Add git status to fish prompt

This commit is contained in:
Daniel Flanagan 2022-10-17 10:08:38 -05:00
parent 20a6c72d8b
commit 59e14d646f
Signed by: lytedev
GPG key ID: 5B2020A0F9921EF4
3 changed files with 44 additions and 3 deletions

View file

@ -8,3 +8,4 @@ command -v fish >/dev/null 2>&1 && grep fish /etc/shells >/dev/null 2>&1 && {
echo " You can also try fish temporarily by running 'fish'. No 'chsh' commitment required." echo " You can also try fish temporarily by running 'fish'. No 'chsh' commitment required."
echo " If you're in bash intentionally for some reason, then ignore this message." echo " If you're in bash intentionally for some reason, then ignore this message."
} }
. "$HOME/.cargo/env"

View file

@ -16,28 +16,42 @@ function preprocess_pwd
awk '{n=split($0,p,"/");for(i=1;i<=n;i++){if(i==n){printf "/%s",p[i]}else{printf "/%.'$MAX_PATH_PIECE_CHARS[1]'s",p[i]}}}' awk '{n=split($0,p,"/");for(i=1;i<=n;i++){if(i==n){printf "/%s",p[i]}else{printf "/%.'$MAX_PATH_PIECE_CHARS[1]'s",p[i]}}}'
end end
function fish_prompt function _maybe_sudo_prefix
set last_cmd_status $status
if set -q SUDO_USER if set -q SUDO_USER
set_color -b yellow black set_color -b yellow black
printf " SUDO " printf " SUDO "
set_color -b normal normal set_color -b normal normal
printf " " printf " "
end end
if test $last_cmd_status -eq 0 end
function _user_and_host
if test $argv[1] -eq 0
set_color -b normal blue set_color -b normal blue
else else
set_color -b normal red set_color -b normal red
end end
printf "$USER@$hostname" printf "$USER@$hostname"
end
function _cur_work_dir
set_color -b normal magenta set_color -b normal magenta
printf " %s" (preprocess_pwd) printf " %s" (preprocess_pwd)
end
function _last_cmd_duration
set_color -b normal green set_color -b normal green
set -q CMD_DURATION && printf " %dms" $CMD_DURATION set -q CMD_DURATION && printf " %dms" $CMD_DURATION
end
function _maybe_jobs_summary
if jobs -q if jobs -q
set_color -b normal cyan set_color -b normal cyan
printf " &%d" (jobs -p | wc -l) printf " &%d" (jobs -p | wc -l)
end end
end
function _user_prompt
printf "\n" printf "\n"
set_color brblack set_color brblack
if test (id -u) -eq 0 if test (id -u) -eq 0
@ -48,6 +62,31 @@ function fish_prompt
set_color -b normal normal set_color -b normal normal
end end
function _maybe_git_summary
set_color -b normal yellow
set cur_sha (git rev-parse --short HEAD 2>/dev/null)
if test $status = 0
set num_changes (git status --porcelain | wc -l)
if test $num_changes = 0
set num_changes "✔"
else
set num_changes "+$num_changes"
end
printf " %s %s %s" (git branch --show-current) $cur_sha $num_changes
end
end
function fish_prompt
set last_cmd_status $status
_maybe_sudo_prefix
_user_and_host $last_cmd_status
_cur_work_dir
_last_cmd_duration
_maybe_jobs_summary
_maybe_git_summary
_user_prompt
end
function fish_mode_prompt; end function fish_mode_prompt; end
function fish_right_prompt function fish_right_prompt

View file

@ -17,6 +17,7 @@ paru -Sy --needed --noconfirm \
aria2 `# Downloads Manager` \ aria2 `# Downloads Manager` \
dmenu `# Application Launcher` \ dmenu `# Application Launcher` \
ripgrep `# Code Search Utilities` \ ripgrep `# Code Search Utilities` \
git-delta `# Better Diff Viewer` \
fd `# File Search` \ fd `# File Search` \
exa `# Better ls` \ exa `# Better ls` \
sd `# Easy Find/Replace` \ sd `# Easy Find/Replace` \