Encouraged by a tweet, intrigued by the homepage, and this blog, I started playing around with the ﬁsh shell.
Reading through the tutorial and documentation, I often felt that the right choices were done, even though sometimes a little brave (e. g. with changing
I have been using zsh for a while now after being a bash user for a long time and work on macOS, Linux, and FreeBSD and I fancy a nice prompt, in particular including repository status, number of background jobs, last commands error code, etc.
I gave ﬁsh a shot and came up with the conﬁguration in the following listing, which is small, simple to set up and feels like a somewhat clean conﬁguration. The reason for that might be that the git prompt is a ﬁrst class citizen in ﬁsh and that ﬁsh’s scripting language seems well designed.
# Fish git prompt set __fish_git_prompt_showdirtystate 'yes' set __fish_git_prompt_showstashstate 'yes' set __fish_git_prompt_showuntrackedfiles 'yes' set __fish_git_prompt_showupstream 'yes' set __fish_git_prompt_color -b grey set __fish_git_prompt_color_branch -b grey yellow set __fish_git_prompt_color_upstream_ahead -b grey green set __fish_git_prompt_color_upstream_behind -b grey red set __fish_git_prompt_show_informative_status 'yes' # Status Chars set __fish_git_prompt_char_upstream_prefix ':' set __fish_git_prompt_char_upstream_ahead 'A' set __fish_git_prompt_char_upstream_behind 'B' set __fish_git_prompt_char_stateseparator '.' set __fish_git_prompt_char_dirtystate 'm' set __fish_git_prompt_char_invalidstate 'x' set __fish_git_prompt_char_stagedstate 'M' set __fish_git_prompt_char_untrackedfiles '?' set __fish_git_prompt_char_cleanstate '' set __fish_git_prompt_char_stashstate '^' set __fish_git_prompt_describe_style 'branch' function fish_prompt set -l last_status $status if not test $last_status -eq 0 set_color -b $fish_color_error white printf ' %s ' (echo $last_status) set_color normal end set -l jobcount (jobs | wc -l) printf '[%d]' $jobcount printf '%s ' (__fish_git_prompt) printf '%s ' (date "+%y-%m-%d %H:%M:%S") set_color green printf '%s\n' (hostname) set_color $fish_color_cwd printf '%s\n> ' (prompt_pwd) set_color normal end
The ﬁrst two paragraphs are conﬁguration settings of the git prompt, while the ‘actual work’ is done in the function
It contains the last command’s return code with red background (if non-zero), the number of jobs in the background, a detailed git status prompt, the date and time when the prompt was printed, the hostname and in the next line the working directory.
Very compact, very nice. Cheers,