Add git status to fish prompt
This commit is contained in:
parent
20a6c72d8b
commit
59e14d646f
|
@ -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 " If you're in bash intentionally for some reason, then ignore this message."
|
||||
}
|
||||
. "$HOME/.cargo/env"
|
||||
|
|
|
@ -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]}}}'
|
||||
end
|
||||
|
||||
function fish_prompt
|
||||
set last_cmd_status $status
|
||||
function _maybe_sudo_prefix
|
||||
if set -q SUDO_USER
|
||||
set_color -b yellow black
|
||||
printf " SUDO "
|
||||
set_color -b normal normal
|
||||
printf " "
|
||||
end
|
||||
if test $last_cmd_status -eq 0
|
||||
end
|
||||
|
||||
function _user_and_host
|
||||
if test $argv[1] -eq 0
|
||||
set_color -b normal blue
|
||||
else
|
||||
set_color -b normal red
|
||||
end
|
||||
printf "$USER@$hostname"
|
||||
end
|
||||
|
||||
function _cur_work_dir
|
||||
set_color -b normal magenta
|
||||
printf " %s" (preprocess_pwd)
|
||||
end
|
||||
|
||||
function _last_cmd_duration
|
||||
set_color -b normal green
|
||||
set -q CMD_DURATION && printf " %dms" $CMD_DURATION
|
||||
end
|
||||
|
||||
function _maybe_jobs_summary
|
||||
if jobs -q
|
||||
set_color -b normal cyan
|
||||
printf " &%d" (jobs -p | wc -l)
|
||||
end
|
||||
end
|
||||
|
||||
function _user_prompt
|
||||
printf "\n"
|
||||
set_color brblack
|
||||
if test (id -u) -eq 0
|
||||
|
@ -48,6 +62,31 @@ function fish_prompt
|
|||
set_color -b normal normal
|
||||
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_right_prompt
|
||||
|
|
|
@ -17,6 +17,7 @@ paru -Sy --needed --noconfirm \
|
|||
aria2 `# Downloads Manager` \
|
||||
dmenu `# Application Launcher` \
|
||||
ripgrep `# Code Search Utilities` \
|
||||
git-delta `# Better Diff Viewer` \
|
||||
fd `# File Search` \
|
||||
exa `# Better ls` \
|
||||
sd `# Easy Find/Replace` \
|
||||
|
|
Reference in a new issue