From 59e14d646ff7e2d417c084a5f1e18921cff9c1bf Mon Sep 17 00:00:00 2001 From: Daniel Flanagan Date: Mon, 17 Oct 2022 10:08:38 -0500 Subject: [PATCH] Add git status to fish prompt --- common/bash/rc | 1 + common/fish/prompt.fish | 45 +++++++++++++++++-- .../arch/provision.d/20-install-packages.bash | 1 + 3 files changed, 44 insertions(+), 3 deletions(-) diff --git a/common/bash/rc b/common/bash/rc index 58215a5..34f4e2c 100644 --- a/common/bash/rc +++ b/common/bash/rc @@ -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" diff --git a/common/fish/prompt.fish b/common/fish/prompt.fish index 00b860e..1739aee 100644 --- a/common/fish/prompt.fish +++ b/common/fish/prompt.fish @@ -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 diff --git a/os/linux/arch/provision.d/20-install-packages.bash b/os/linux/arch/provision.d/20-install-packages.bash index 9725330..3f033cd 100755 --- a/os/linux/arch/provision.d/20-install-packages.bash +++ b/os/linux/arch/provision.d/20-install-packages.bash @@ -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` \