diff options
Diffstat (limited to '.config/fish/functions/fish_prompt.fish')
| -rw-r--r-- | .config/fish/functions/fish_prompt.fish | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/.config/fish/functions/fish_prompt.fish b/.config/fish/functions/fish_prompt.fish new file mode 100644 index 0000000..494b07f --- /dev/null +++ b/.config/fish/functions/fish_prompt.fish @@ -0,0 +1,86 @@ +function fish_prompt + set -l cmd_status $status + set -l cmd_duration (math -s0 $CMD_DURATION / 1000) + set CMD_DURATION 0 + set -l is_git (git rev-parse --is-inside-work-tree 2>/dev/null) + + echo + + set_color --bold cyan + if [ "$is_git" = true ] + printf "%s" (git rev-parse --show-toplevel | awk -F/ '{ print $NF }') + set -l git_path (git rev-parse --show-prefix | sed 's#/$##') + [ -n "$git_path" ] && printf '/%s' $git_path + else + printf (prompt_pwd -d0) + end + set_color normal + + if [ "$is_git" = true ] + printf " on " + set_color --bold magenta + printf " "(git branch --show-current) + + function git_status + set -l s (git status --porcelain -b | string split0) + + git rev-parse --verify refs/stash &>/dev/null && printf '$' + echo $s | grep -q '^U[UDA]|^AA|^DD|^[DA]U' && printf "=" + echo $s | grep -q '^[MARCDU ]D|^D[ UM]' && printf "✘" + echo $s | grep -q '^R[ MD]' && printf "»" + echo $s | grep -q '^[ MARC]M' && printf "!" + echo $s | grep -q '^A[ MDAU]|^M[ MD]|^UA' && printf "+" + echo $s | grep -q '^\?\?' && printf "?" + + set -l ahead (echo $s | grep -q '^## [^ ]\+ .*ahead'; echo $status) + set -l behind (echo $s | grep -q '^## [^ ]\+ .*behind'; echo $status) + if [ "$ahead" -eq 0 ] && [ "$behind" -eq 0 ] + printf "⇕" + elif [ "$ahead" -eq 0 ] + printf "⇡" + elif [ "$behind" -eq 0 ] + printf "⇣" + end + end + + set -l stat (git_status) + if [ -n "$stat" ] + set_color --bold red + printf " [%s]" "$stat" + end + + set_color normal + end + + if [ "$cmd_duration" -gt 1 ] + printf " took" + set_color --bold yellow + + set -l secs (math -s1 $cmd_duration % 60) + set -l mins (math -s0 $cmd_duration / 60 % 60) + set -l hours (math -s0 $cmd_duration / 3600) + + [ "$hours" -gt 0 ] && printf " %dh" "$hours" + [ "$mins" -gt 0 ] && printf " %dm" "$mins" + [ "$secs" -gt 0 ] && printf " %ds" "$secs" + set_color normal + end + + echo + + if jobs &>/dev/null + set -l jobs (jobs | wc -l) + set_color --bold blue + printf "✦ " + [ "$jobs" -gt 1 ] && printf "%d " "$jobs" + set_color normal + end + + if [ "$cmd_status" -eq 0 ] + set_color green + else + set_color red + end + printf "❯ " + set_color normal +end |
