DEV Community

Cover image for Some Fish Aliases for a More Productive Programming
Maroun Maroun
Maroun Maroun

Posted on

Some Fish Aliases for a More Productive Programming

I believe that the shell prompt shouldn't be too much cluttered. Here's how mine looks:


It contains the PWD, followed by the current Git branch and the K8s context I'm using. This is achieved by the following ~/.config/fish/

function custom_prompt
    set_color normal
    set -l git_branch (git branch 2>/dev/null | sed -n '/\* /s///p')
    set -l kube_context (kubectl config current-context | cut -d. -f1)
    set_color 2eb82e
    set_color cyan
    echo -n (prompt_pwd)
    set_color normal
    echo -n ' ['
    set_color 0087ff
    echo -n "$git_branch"
    if [ ! -z "$git_branch" ]
      set_color normal
      echo -n "/"
    set_color 00b386
    echo -n "$kube_context"
    set_color normal
    echo -n ']'
    set_color cyan
    echo -n '$ '

Addiotianly, sometimes I want to hide the prompt in order to get more space in my terminal. For that, I have the following aliases:

function fish_prompt --description "Custom fish prompt"

function show --description "Show fish prompt"
    function fish_prompt

function hide --description "Hide fish prompt"
    function fish_prompt
        echo -n '> '

which gives me the following:


Additionally, here are some of my favorite aliases for K8s and Docker:

# switch between K8s contexes
abbr -a -g kubedev kubectl config use-context <dev-context>
abbr -a -g kubestaging kubectl config use-context <staging-context>

# edit deployments
abbr -a -g edit-deployment kubectl edit deployment <deployment>

# exec to your common pod
function exec-pod
    set pod_id (kubectl get pods -l app=<app> -o custom-columns="")
    kubectl exec -it $pod_id bash

# display the current deployed image
function current_image
    set image (kubectl get deployment <deployment> -o=jsonpath='{$.spec.template.spec.containers[:1].image}')
    printf "$image\n"

# docker stuff
abbr -a -g drm docker rm
abbr -a -g dri docker images
abbr -a -g dexec docker exec -it
abbr -a -g dstopall docker stop (docker ps -q)
abbr -a -g dps docker ps
abbr -a -g rmidang docker rmi -f (docker images -f "dangling=true" -q)

I have the same aliases also for Bash, if someone is interested I'll happily share them.

I'd appreciate it if you share your useful aliases too!

Top comments (0)