🐟 My personal dotfiles

Re-organize prompt code

Signed-off-by: David Celis <me@davidcel.is>

+81 -43
+49
config/fish/functions/__fish_prompt_git.fish
··· 1 + function __fish_prompt_git 2 + set -g __git_branch_name (command git symbolic-ref --short -q HEAD ^/dev/null) 3 + 4 + if not set -q -g __git_functions_defined 5 + set -g __git_functions_defined 6 + 7 + function _git_dirty 8 + echo (command git status -s --ignore-submodules=dirty) 9 + end 10 + 11 + function _git_ahead 12 + echo (command git log --format=oneline origin/$__git_branch_name..$__git_branch_name ^/dev/null) 13 + end 14 + 15 + function _git_behind 16 + echo (command git log --format=oneline $__git_branch_name..origin/$__git_branch_name ^/dev/null) 17 + end 18 + end 19 + 20 + set -l cyan (set_color -o cyan) 21 + set -l yellow (set_color -o yellow) 22 + set -l purple (set_color -o purple) 23 + set -l blue (set_color -o blue) 24 + set -l normal (set_color normal) 25 + 26 + set -l cwd $cyan(prompt_pwd) 27 + 28 + if [ $__git_branch_name ] 29 + set -l git_branch $purple$__git_branch_name 30 + set git_info "$blue $git_branch" 31 + 32 + if [ (_git_dirty) ] 33 + set -l dirty $yellow! 34 + set git_info $git_info$dirty 35 + end 36 + 37 + if [ (_git_ahead) ] 38 + set -l ahead $blue↑ 39 + set git_info $git_info$ahead 40 + end 41 + 42 + if [ (_git_behind) ] 43 + set -l behind $blue↓ 44 + set git_info $git_info$behind 45 + end 46 + end 47 + 48 + echo $git_info 49 + end
+3
config/fish/functions/__fish_prompt_pwd.fish
··· 1 + function __fish_prompt_pwd 2 + echo $PWD | sed -e "s|^$DEVELOPER|~Developer|" -e "s|^$HOME/*|~|" -e 's-.*/\([^/]*/[^/]*\)-\1-' 3 + end
+15
config/fish/functions/__fish_prompt_timing.fish
··· 1 + function __fish_prompt_timing 2 + if test "$CMD_DURATION" -gt '100' 3 + set_color $fish_color_error 4 + 5 + if test "$CMD_DURATION" -lt '60000' 6 + printf '%.1fs ' (awk "BEGIN { print $CMD_DURATION / 1000 }") 7 + else if test "$CMD_DURATION" -lt '3600000' 8 + printf '%.1fm ' (awk "BEGIN { print $CMD_DURATION / 60000 }") 9 + else 10 + printf '%.1fh ' (awk "BEGIN { print $CMD_DURATION / 3600000 }") 11 + end 12 + 13 + set_color normal 14 + end 15 + end
+14 -40
config/fish/functions/fish_prompt.fish
··· 1 1 function fish_prompt 2 - set -g __git_branch_name (command git symbolic-ref --short -q HEAD ^/dev/null) 2 + set -l last_status $status 3 3 4 - if not set -q -g __git_functions_defined 5 - set -g __git_functions_defined 4 + # Command timing 5 + echo -n -s (__fish_prompt_timing) 6 6 7 - function _git_dirty 8 - echo (command git status -s --ignore-submodules=dirty) 9 - end 7 + # PWD 8 + set_color cyan 9 + echo -n (__fish_prompt_pwd) 10 + set_color normal 10 11 11 - function _git_ahead 12 - echo (command git log --format=oneline origin/$__git_branch_name..$__git_branch_name ^/dev/null) 13 - end 12 + # Git 13 + printf '%s ' (__fish_prompt_git ' %s') 14 + set_color normal 14 15 15 - function _git_behind 16 - echo (command git log --format=oneline $__git_branch_name..origin/$__git_branch_name ^/dev/null) 17 - end 16 + if not test $last_status -eq 0 17 + set_color $fish_color_error 18 18 end 19 19 20 - set -l cyan (set_color -o cyan) 21 - set -l yellow (set_color -o yellow) 22 - set -l purple (set_color -o purple) 23 - set -l blue (set_color -o blue) 24 - set -l normal (set_color normal) 25 - 26 - set -l cwd $cyan(prompt_pwd) 27 - 28 - if [ $__git_branch_name ] 29 - set -l git_branch $purple$__git_branch_name 30 - set git_info "$blue $git_branch" 20 + echo -n -s '% ' 31 21 32 - if [ (_git_dirty) ] 33 - set -l dirty $yellow! 34 - set git_info $git_info$dirty 35 - end 36 - 37 - if [ (_git_ahead) ] 38 - set -l ahead $blue↑ 39 - set git_info $git_info$ahead 40 - end 41 - 42 - if [ (_git_behind) ] 43 - set -l behind $blue↓ 44 - set git_info $git_info$behind 45 - end 46 - end 47 - 48 - echo -n -s $cwd $git_info $normal ' % ' 22 + set_color normal 49 23 end
-3
config/fish/functions/prompt_pwd.fish
··· 1 - function prompt_pwd --description 'Print the current working directory, shortend to fit the prompt' 2 - echo $PWD | sed -e "s|^$DEVELOPER|~Developer|" -e "s|^$HOME/*|~|" -e 's-.*/\([^/]*/[^/]*\)-\1-' 3 - end