From 7e203d12fc07ecf6546818a13288619e12c93941 Mon Sep 17 00:00:00 2001 From: Jorge Bucaran Date: Sat, 2 Jul 2022 00:36:46 -0300 Subject: [PATCH 1/3] Introduce addons --- conf.d/hydro.fish | 9 +++++++-- functions/fish_prompt.fish | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/conf.d/hydro.fish b/conf.d/hydro.fish index 4c272cc..223d857 100644 --- a/conf.d/hydro.fish +++ b/conf.d/hydro.fish @@ -1,8 +1,9 @@ status is-interactive || exit set --global _hydro_git _hydro_git_$fish_pid +set --global _hydro_addons _hydro_items_$fish_pid -function $_hydro_git --on-variable $_hydro_git +function $_hydro_git --on-variable $_hydro_git --on-variable $_hydro_addons commandline --function repaint end @@ -65,7 +66,11 @@ function _hydro_prompt --on-event fish_prompt set --query _hydro_skip_git_prompt && set $_hydro_git && return + set --local addons _hydro_addon_{$hydro_prompt_addons}\; + fish --private --command " + set --universal $_hydro_addons ($addons) \"\" + set branch ( command git symbolic-ref --short HEAD 2>/dev/null || command git describe --tags --exact-match HEAD 2>/dev/null || @@ -102,7 +107,7 @@ function _hydro_prompt --on-event fish_prompt end function _hydro_fish_exit --on-event fish_exit - set --erase $_hydro_git + set --erase $_hydro_git $_hydro_addons end function _hydro_uninstall --on-event hydro_uninstall diff --git a/functions/fish_prompt.fish b/functions/fish_prompt.fish index c8cf475..5b9aa5c 100644 --- a/functions/fish_prompt.fish +++ b/functions/fish_prompt.fish @@ -1,3 +1,3 @@ function fish_prompt --description Hydro - echo -e "$_hydro_color_pwd$_hydro_pwd$hydro_color_normal $_hydro_color_git$$_hydro_git$hydro_color_normal$_hydro_color_duration$_hydro_cmd_duration$hydro_color_normal$_hydro_status$hydro_color_normal " + echo -e "$_hydro_color_pwd$_hydro_pwd$hydro_color_normal $_hydro_color_git$$_hydro_git$hydro_color_normal$_hydro_color_duration$_hydro_cmd_duration$hydro_color_normal$$_hydro_addons$_hydro_status$hydro_color_normal " end From 5bfcc85d6aaee379f2081f722fdeb2c5852005da Mon Sep 17 00:00:00 2001 From: Jorge Bucaran Date: Sat, 2 Jul 2022 02:00:59 -0300 Subject: [PATCH 2/3] Addons should work outside a git path too --- conf.d/hydro.fish | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/conf.d/hydro.fish b/conf.d/hydro.fish index 223d857..df85a19 100644 --- a/conf.d/hydro.fish +++ b/conf.d/hydro.fish @@ -8,18 +8,15 @@ function $_hydro_git --on-variable $_hydro_git --on-variable $_hydro_addons end function _hydro_pwd --on-variable PWD --on-variable hydro_ignored_git_paths --on-variable fish_prompt_pwd_dir_length - set --local git_root (command git --no-optional-locks rev-parse --show-toplevel 2>/dev/null) - set --local git_base (string replace --all --regex -- "^.*/" "" "$git_root") + set --global _hydro_git_root (command git --no-optional-locks rev-parse --show-toplevel 2>/dev/null) + set --local git_base (string replace --all --regex -- "^.*/" "" "$_hydro_git_root") set --local path_sep / + + set --query _hydro_git_root[1] && + contains -- $_hydro_git_root $hydro_ignored_git_paths && set _hydro_git_root test "$fish_prompt_pwd_dir_length" = 0 && set path_sep - if set --query git_root[1] && ! contains -- $git_root $hydro_ignored_git_paths - set --erase _hydro_skip_git_prompt - else - set --global _hydro_skip_git_prompt - end - set --global _hydro_pwd ( string replace --ignore-case -- ~ \~ $PWD | string replace -- "/$git_base/" /:/ | @@ -62,15 +59,15 @@ function _hydro_prompt --on-event fish_prompt set --query _hydro_status || set --global _hydro_status "$_hydro_newline$_hydro_color_prompt$hydro_symbol_prompt" set --query _hydro_pwd || _hydro_pwd - command kill $_hydro_last_pid 2>/dev/null - - set --query _hydro_skip_git_prompt && set $_hydro_git && return - set --local addons _hydro_addon_{$hydro_prompt_addons}\; + command kill $_hydro_last_pid 2>/dev/null + fish --private --command " set --universal $_hydro_addons ($addons) \"\" + test -z \"$_hydro_git_root\" && set $_hydro_git && exit + set branch ( command git symbolic-ref --short HEAD 2>/dev/null || command git describe --tags --exact-match HEAD 2>/dev/null || From 0492e680f44e687d5c6400e21542004f5401a416 Mon Sep 17 00:00:00 2001 From: Jorge Bucaran Date: Sat, 2 Jul 2022 02:01:59 -0300 Subject: [PATCH 3/3] Remove internal hydro_color_normal variable --- conf.d/hydro.fish | 2 -- functions/fish_prompt.fish | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/conf.d/hydro.fish b/conf.d/hydro.fish index df85a19..275a373 100644 --- a/conf.d/hydro.fish +++ b/conf.d/hydro.fish @@ -114,8 +114,6 @@ function _hydro_uninstall --on-event hydro_uninstall functions --erase (functions --all | string match --entire --regex "^_?hydro_") end -set --global hydro_color_normal (set_color normal) - for color in hydro_color_{pwd,git,error,prompt,duration} function $color --on-variable $color --inherit-variable color set --query $color && set --global _$color (set_color $$color) diff --git a/functions/fish_prompt.fish b/functions/fish_prompt.fish index 5b9aa5c..fec1499 100644 --- a/functions/fish_prompt.fish +++ b/functions/fish_prompt.fish @@ -1,3 +1,3 @@ function fish_prompt --description Hydro - echo -e "$_hydro_color_pwd$_hydro_pwd$hydro_color_normal $_hydro_color_git$$_hydro_git$hydro_color_normal$_hydro_color_duration$_hydro_cmd_duration$hydro_color_normal$$_hydro_addons$_hydro_status$hydro_color_normal " + echo -e "$_hydro_color_pwd$_hydro_pwd\x1b[0m $_hydro_color_git$$_hydro_git\x1b[0m$_hydro_color_duration$_hydro_cmd_duration\x1b[0m$$_hydro_addons$_hydro_status\x1b[0m " end