A Nicer Custom FISH Shell Prompt

Over the past couple years Fish has really become my favorite go to shell. At the end of the day I think most people fall into either the bash, fish, or zsh shell camps. The truth is that while many of the zsh fans argue that any interesting feature eventually makes it into the shell, the honest truth is that all that extensibility actually works against it. Most definitely bash is fine for most things, but fish is clearly superior when it comes to just having an “out-of-the-box” experience. This especially includes the advanced type of completion it offers. Yes you can get anything you want in zsh, just keep it updated and modify it, but that just gets out of hand at times.

As for fish, it suffers from this problem as well when you “want to go off the reservation”. However, thankfully, that’s largely unnecessary for the basic “goodies”. However, one thing I do like is how you can basically “trade” functionality (which even aliases fall into this category). The prompt for the shell is no different and so you can just copypasta this into a file and drop into your ~/.config/fish/functions/ directory.

fish_prompt.fish

function fish_prompt --description 'Write out the prompt'
    if test -z $WINDOW
        printf '[%s%s@%s%s%s] %s%s%s> ' (set_color 17D) (whoami) (set_color 6af) (hostname|cut -d . -f 1) (set_color normal) (set_color c6f) (prompt_pwd) (set_color normal)
    else
        printf '%s%s@%s%s%s(%s)%s%s%s> ' (set_color yellow) (whoami) (set_color purple) (hostname|cut -d . -f 1) (set_color white) (echo $WINDOW) (set_color $fish_color_cwd) (prompt_pwd) (set_color normal)
    end
end

This provides you with a nice little color change to the prompt. You can of course modify this to suit your needs, and what I really like is that changes are automatically recognized, without the need to read in the runcom/resource configuration file (ala bash’s . .bashrc¬†method)

If you happen to come up with any interesting prompts yourself or interesting color combinations, be sure to leave/comment them below, I’d love to see what people have come up with.

 

Leave a Reply