{ programs.fish = { enable = true; shellInit = "set -g fish_greeting"; # https://github.com/arbourd/prompt promptInit = '' function fish_prompt -d "Prints left prompt" set -l last_status $status set -l glyph "\$" set -l glyph_color (set_color normal) set -l pwd (prompt_pwd) set -l pwd_color (set_color blue) if test (id -u "$USER") -eq 0 set glyph "#" end if test "$last_status" -ne 0 set pwd_color (set_color red) end if command git rev-parse --git-dir > /dev/null 2>/dev/null if ! command git diff --cached --no-ext-diff --quiet --exit-code 2>/dev/null set glyph_color (set_color green) else if command git rev-parse --verify --quiet refs/stash > /dev/null 2>/dev/null set glyph_color (set_color yellow) end end printf "$pwd_color$pwd $glyph_color$glyph " end function fish_right_prompt -d "Prints right prompt" function __git_branch_name command git symbolic-ref --short HEAD 2>/dev/null \ || command git describe --tags --exact-match HEAD 2>/dev/null \ || command git rev-parse --short HEAD 2>/dev/null end function __git_changed ! command git diff-index --quiet HEAD 2>/dev/null \ || count (command git ls-files --others --exclude-standard) >/dev/null end function __git_modified_files count (command git status --porcelain --ignore-submodules 2>/dev/null) end function __git_symbol command git rev-list --count --left-right @{upstream}...@ 2>/dev/null | read behind ahead switch "$behind $ahead" case " " "0 0" case "0 *" printf " ↑" case "* 0" printf " ↓" case "*" printf " ⥄" end end if set branch_name (__git_branch_name) set -l git_symbol (__git_symbol) set -l git_color set -l git_modified_files (__git_modified_files) set -l git_changed_files if __git_changed set git_color (set_color red) else set git_color (set_color cyan) end if test "$git_modified_files" -gt 0 set git_changed_files (set_color yellow)"$git_modified_files changed " end printf "$git_changed_files$git_color$branch_name$git_symbol" end end ''; }; }