Afficher la branche git dans le prompt du shell fish
Par Alexis Lefebvre le lundi 14 novembre 2016, 19:37 - Lien permanent
Par défaut, le shell fish n'affiche pas la branche git actuelle :
Il faut placer le code suivant dans le fichier ~/.config/fish/config.fish :
set fish_git_dirty_color red
set fish_git_not_dirty_color green
function parse_git_branch
set -l branch (git branch 2> /dev/null | grep -e '\* ' | sed 's/^..\(.*\)/\1/')
set -l git_diff (git diff)
if test -n "$git_diff"
echo (set_color $fish_git_dirty_color)$branch(set_color normal)
else
echo (set_color $fish_git_not_dirty_color)$branch(set_color normal)
end
end
function fish_prompt
set -l git_dir (git rev-parse --git-dir 2> /dev/null)
if test -n "$git_dir"
printf '%s@%s %s%s%s (%s)> ' (whoami) (hostname|cut -d . -f 1) (set_color $fish_color_cwd) (prompt_pwd) (set_color normal) (parse_git_branch)
else
printf '%s@%s %s%s%s> ' (whoami) (hostname|cut -d . -f 1) (set_color $fish_color_cwd) (prompt_pwd) (set_color normal)
end
end
La branche s'affiche alors en vert ou en rouge si des changements n'ont pas été sauvegardés :

