February 21, 2024
by Matt Raines

Pretty prompts in Fish and Vim

Example Vim editor status line and shell prompt, including pretty colours and icons for version control status.

Every time I’ve gone away to a conference recently, and PHP UK 2024 was no exception to the rule, I’ve come home jealous of all the pretty Powerline-style prompts the presenters seem to have on their Macs. It’s always on their Macs.

So I decided this was the time to do something about it and bring the development team the joy of version control integration and pretty status icons in their shell prompts and text editor statuslines.

We use the Fish shell not the more usual Bash so I installed and configured Oh My Fish with the bobthefish theme, and Powerline for the Vim integration. Although after a brief “holy war” discussion on text editors it appears I might be the only one who uses Vim. Here’s how I did it:

Install Oh My Fish and the theme.

curl https://raw.githubusercontent.com/oh-my-fish/oh-my-fish/master/bin/install | fish
omf install bobthefish

We spent a little while faffing around trying to install Powerline fonts on Windows (on Ubuntu it’s just apt install fonts-powerline but everyone else insists on having a Start menu) before deciding to just download a nice Nerd Font and configure all our terminals to use it. You get nicer icons this way anyway. Jet Brains Mono was my favourite. It’s important to extract the fonts from the Zip and install them with “More Options” and “Install for all users” otherwise it only works intermittently.

Configure some options for a prettier prompt. eg add a .config/fish/conf.d/bobthe.fish

set -g theme_date_format "+%a %-d %b %H:%M"   # shorter date format
set -g theme_display_cmd_duration yes         # how long the last command took
set -g theme_display_git_default_branch yes   # show "main" branch
set -g theme_display_jobs_verbose yes         # number of background jobs
set -g theme_display_user yes                 # always show username
set -g theme_nerd_fonts yes                   # for pretty icons
set -g theme_use_abbreviated_branch_name yes  # otherwise the prompt is long

# Only display hostname if we're on a remote server
# (ie it has a domain portion of its hostname)
set domain (hostname -d)
if test -n "$domain"
  set -g theme_display_hostname yes
  set -g theme_title_display_user yes
else
  set -g theme_display_hostname no
  set -g theme_title_display_user no
end

Install Powerline.

sudo apt install powerline

Add it to your vimrc.

python3 from powerline.vim import setup as powerline_setup
python3 powerline_setup()
python3 del powerline_setup