function fish_prompt --description 'Write out the prompt' # Save our status set -l last_status $status #### line 1 # last command return value printf "%s[" (set_color brblack) if [ $last_status -ne 0 ] printf "%s" (set_color red) else printf "%s" (set_color cyan) end printf "%s%s]" $last_status (set_color brblack) # last command duration set dur_ms (math -s0 $CMD_DURATION \% 1000 / 100) # 10th second set dur_s (math -s0 $CMD_DURATION / 1000 \% 60) set dur_m (math -s0 $CMD_DURATION / 1000 / 60 \% 60) set dur_h (math -s0 $CMD_DURATION / 1000 / 60 / 60) printf " [" if test $dur_h -gt 0 printf "%s%s%sh " (set_color cyan) $dur_h (set_color brblack) end if test $dur_h -gt 0 -o $dur_m -gt 0 printf "%s%s%sm " (set_color cyan) $dur_m (set_color brblack) end printf "%s%s%s.%s%s%ss]" (set_color cyan) $dur_s (set_color brblack) (set_color cyan) $dur_ms (set_color brblack) # user@host # Just calculate this once, to save a few cycles when displaying the prompt if not set -q __fish_prompt_hostname set -g __fish_prompt_hostname (hostname|cut -d . -f 1) end printf " " # user@host printf "%s[%s%s%s@%s%s%s]" (set_color brblack) (set_color cyan) $USER (set_color brblack) (set_color cyan) $__fish_prompt_hostname (set_color brblack) printf " " # time printf "%s[%s%s%s]\n" (set_color brblack) (set_color cyan) (date +%H:%M:%S) (set_color brblack) #### git line if git rev-parse --is-inside-work-tree ^/dev/null >/dev/null printf "%s[git:" (set_color brblack) if not git diff-files --quiet ^/dev/null >/dev/null # changes printf " %s%s" (set_color red) (git diff-files | grep -c .) end if not git diff-index --quiet --cached HEAD -- ^/dev/null >/dev/null # cached changes printf " %s%s" (set_color green) (git diff-index --cached HEAD -- ^/dev/null | grep -c .) end set -l branch (git symbolic-ref --short HEAD ^/dev/null) printf " %s%s" (set_color cyan) (string trim $branch) printf "%s]\n" (set_color brblack) end #### PWD # pwd # this gets too long sometimes set -l pwd_text (prompt_pwd) set -l pwd_space_avail (math (tput cols)-2) set -l pwd_clip (math (string length $pwd_text) - $pwd_space_avail ) if test $pwd_clip -gt 0 set -l pwd_clip (math $pwd_clip + 4) set pwd_text "..."(string sub -s $pwd_clip $pwd_text) end printf "%s[%s%s%s%s]\n" (set_color brblack) (set_color cyan) $pwd_text (set_color brblack) #### prompt line switch $USER case root set p '#' case '*' set p '$' end printf "%s%s%s " (set_color white --bold) $p (set_color normal) end