diff --git a/config/fish/functions/__fish_prompt_git.fish b/config/fish/functions/__fish_prompt_git.fish new file mode 100644 index 0000000..52ae486 --- /dev/null +++ b/config/fish/functions/__fish_prompt_git.fish @@ -0,0 +1,49 @@ +function __fish_prompt_git + set -g __git_branch_name (command git symbolic-ref --short -q HEAD ^/dev/null) + + if not set -q -g __git_functions_defined + set -g __git_functions_defined + + function _git_dirty + echo (command git status -s --ignore-submodules=dirty) + end + + function _git_ahead + echo (command git log --format=oneline origin/$__git_branch_name..$__git_branch_name ^/dev/null) + end + + function _git_behind + echo (command git log --format=oneline $__git_branch_name..origin/$__git_branch_name ^/dev/null) + end + end + + set -l cyan (set_color -o cyan) + set -l yellow (set_color -o yellow) + set -l purple (set_color -o purple) + set -l blue (set_color -o blue) + set -l normal (set_color normal) + + set -l cwd $cyan(prompt_pwd) + + if [ $__git_branch_name ] + set -l git_branch $purple$__git_branch_name + set git_info "$blue $git_branch" + + if [ (_git_dirty) ] + set -l dirty $yellow! + set git_info $git_info$dirty + end + + if [ (_git_ahead) ] + set -l ahead $blue↑ + set git_info $git_info$ahead + end + + if [ (_git_behind) ] + set -l behind $blue↓ + set git_info $git_info$behind + end + end + + echo $git_info +end diff --git a/config/fish/functions/prompt_pwd.fish b/config/fish/functions/__fish_prompt_pwd.fish similarity index 50% rename from config/fish/functions/prompt_pwd.fish rename to config/fish/functions/__fish_prompt_pwd.fish index 0522be3..e4de693 100644 --- a/config/fish/functions/prompt_pwd.fish +++ b/config/fish/functions/__fish_prompt_pwd.fish @@ -1,3 +1,3 @@ -function prompt_pwd --description 'Print the current working directory, shortend to fit the prompt' +function __fish_prompt_pwd echo $PWD | sed -e "s|^$DEVELOPER|~Developer|" -e "s|^$HOME/*|~|" -e 's-.*/\([^/]*/[^/]*\)-\1-' end diff --git a/config/fish/functions/__fish_prompt_timing.fish b/config/fish/functions/__fish_prompt_timing.fish new file mode 100644 index 0000000..d047996 --- /dev/null +++ b/config/fish/functions/__fish_prompt_timing.fish @@ -0,0 +1,15 @@ +function __fish_prompt_timing + if test "$CMD_DURATION" -gt '100' + set_color $fish_color_error + + if test "$CMD_DURATION" -lt '60000' + printf '%.1fs ' (awk "BEGIN { print $CMD_DURATION / 1000 }") + else if test "$CMD_DURATION" -lt '3600000' + printf '%.1fm ' (awk "BEGIN { print $CMD_DURATION / 60000 }") + else + printf '%.1fh ' (awk "BEGIN { print $CMD_DURATION / 3600000 }") + end + + set_color normal + end +end diff --git a/config/fish/functions/fish_prompt.fish b/config/fish/functions/fish_prompt.fish index 2083380..1387304 100644 --- a/config/fish/functions/fish_prompt.fish +++ b/config/fish/functions/fish_prompt.fish @@ -1,49 +1,23 @@ function fish_prompt - set -g __git_branch_name (command git symbolic-ref --short -q HEAD ^/dev/null) + set -l last_status $status - if not set -q -g __git_functions_defined - set -g __git_functions_defined + # Command timing + echo -n -s (__fish_prompt_timing) - function _git_dirty - echo (command git status -s --ignore-submodules=dirty) - end + # PWD + set_color cyan + echo -n (__fish_prompt_pwd) + set_color normal - function _git_ahead - echo (command git log --format=oneline origin/$__git_branch_name..$__git_branch_name ^/dev/null) - end + # Git + printf '%s ' (__fish_prompt_git ' %s') + set_color normal - function _git_behind - echo (command git log --format=oneline $__git_branch_name..origin/$__git_branch_name ^/dev/null) - end + if not test $last_status -eq 0 + set_color $fish_color_error end - set -l cyan (set_color -o cyan) - set -l yellow (set_color -o yellow) - set -l purple (set_color -o purple) - set -l blue (set_color -o blue) - set -l normal (set_color normal) + echo -n -s '% ' - set -l cwd $cyan(prompt_pwd) - - if [ $__git_branch_name ] - set -l git_branch $purple$__git_branch_name - set git_info "$blue $git_branch" - - if [ (_git_dirty) ] - set -l dirty $yellow! - set git_info $git_info$dirty - end - - if [ (_git_ahead) ] - set -l ahead $blue↑ - set git_info $git_info$ahead - end - - if [ (_git_behind) ] - set -l behind $blue↓ - set git_info $git_info$behind - end - end - - echo -n -s $cwd $git_info $normal ' % ' + set_color normal end