From 14345095690199a039622fd06f043d89187eb10e Mon Sep 17 00:00:00 2001 From: Sean Patrick Hagen Date: Fri, 10 Jun 2022 15:23:32 -0700 Subject: [PATCH 01/14] Add Go prompt --- functions/fish_prompt.fish | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/functions/fish_prompt.fish b/functions/fish_prompt.fish index 331bc5b..e2b7731 100644 --- a/functions/fish_prompt.fish +++ b/functions/fish_prompt.fish @@ -35,6 +35,7 @@ # set -g theme_display_virtualenv no # set -g theme_display_nix no # set -g theme_display_ruby no +# set -g theme_display_go no # set -g theme_display_user ssh # set -g theme_display_hostname ssh # set -g theme_display_sudo_user yes @@ -803,6 +804,22 @@ function __bobthefish_rvm_info -S -d 'Current Ruby information from RVM' end end +function __bobthefish_prompt_golang -S -d 'Display current Go information' + [ "$theme_display_go" = 'no' ] + and return + + set -l go_version + if type -fq go + set go_version (go version | cut --delimiter=' ' -f 3 | cut --characters='3-6' ) + end + + [ -z "$go_version" ] + and return + + __bobthefish_start_segment $color_virtualgo + echo -ns $go_glyph $go_version ' ' +end + function __bobthefish_prompt_rubies -S -d 'Display current Ruby information' [ "$theme_display_ruby" = 'no' ] and return @@ -1172,6 +1189,7 @@ function fish_prompt -d 'bobthefish, a fish theme optimized for awesome' __bobthefish_prompt_nix __bobthefish_prompt_desk __bobthefish_prompt_rubies + __bobthefish_prompt_golang __bobthefish_prompt_virtualfish __bobthefish_prompt_virtualgo __bobthefish_prompt_node From 9ca1260fc596869b7eff2d2f655cbff37982ffc2 Mon Sep 17 00:00:00 2001 From: Sean Patrick Hagen Date: Fri, 17 Jun 2022 11:24:14 -0700 Subject: [PATCH 02/14] Rework `__bobthefish_prompt_golang` to be more like "rubies" prompt First checks to see if `asdf` is installed. If it is, checks to see if either of the plugins ( `golang` or `go-sdk` ) that install a version of Go have an installed version. If they do, use that version. If `asdf` isn't installed, check the `go.mod` file. If in a folder that has a `go.mod` or a parent folder has a `go.mod`, check that file for the Go version. Lastly, check if there's a `go` executable on the current path. If there isn't set a flag so that the go version will be printed out in red rather than blue. --- functions/fish_prompt.fish | 98 +++++++++++++++++++++++++++++++------- 1 file changed, 82 insertions(+), 16 deletions(-) diff --git a/functions/fish_prompt.fish b/functions/fish_prompt.fish index e2b7731..0a8fda2 100644 --- a/functions/fish_prompt.fish +++ b/functions/fish_prompt.fish @@ -804,22 +804,6 @@ function __bobthefish_rvm_info -S -d 'Current Ruby information from RVM' end end -function __bobthefish_prompt_golang -S -d 'Display current Go information' - [ "$theme_display_go" = 'no' ] - and return - - set -l go_version - if type -fq go - set go_version (go version | cut --delimiter=' ' -f 3 | cut --characters='3-6' ) - end - - [ -z "$go_version" ] - and return - - __bobthefish_start_segment $color_virtualgo - echo -ns $go_glyph $go_version ' ' -end - function __bobthefish_prompt_rubies -S -d 'Display current Ruby information' [ "$theme_display_ruby" = 'no' ] and return @@ -863,6 +847,88 @@ function __bobthefish_prompt_rubies -S -d 'Display current Ruby information' echo -ns $ruby_glyph $ruby_version ' ' end +function __bobthefish_prompt_golang -S -d 'Display current Go information' + [ "$theme_display_go" = 'no' ] + and return + + set -l go_version + if type -fq asdf + set -l asdf_golang_version (asdf current golang 2>/dev/null) + or set -l asdf_golang_version "na" + + set -l asdf_go_sdk_version (asdf current go-sdk 2>/dev/null) + or set -l asdf_go_sdk_version "na" + + set -l _asdf_plugin + set -l asdf_go_version + set -l asdf_provenance + if [ "$asdf_golang_version" != "na" ] + echo "$asdf_golang_version" | read _asdf_plugin asdf_go_version asdf_provenance + else if [ "$asdf_go_sdk_version" != "na" ] + echo "$asdf_go_sdk_version" | read _asdf_plugin asdf_go_version asdf_provenance + end + + [ (string trim -- "$asdf_provenance") = "$HOME/.tool-versions" ] + and return + + set go_version $asdf_go_version + end + + set -l no_go_installed 0 + # no version from asdf, check go.mod file + if [ -z "$go_version" ] + set -l cwd (pwd) + set -l dir (pwd) + set -l gomod_file + set -l gomod_version + set -l _gomod + + set -l found_gomod 0 + + # find the closest go.mod + while not test "$dir" = "/" + set gomod_file "$dir/go.mod" + + if test -f "$gomod_file" + set found_gomod 1 + cat "$gomod_file" | grep "^go\ " | read _gomod gomod_version + break + end + + cd $dir/.. + set dir (pwd) + end + cd $cwd + + if test "$found_gomod" -eq "1" + # found go.mod file, but no version inside + if [ -z (string trim -- "$gomod_version") ] + # is there a version of go we can ask for the version? + if type -fq go + set gomod_version (go version | string match -r 'go version go(\\d+\\.\\d+)' -g) + end + end + end + + set go_version $gomod_version + end + + if ! type -fq go + set no_go_installed 1 + end + + [ -z "$go_version" ] + and return + + __bobthefish_start_segment $color_virtualgo + echo -ns $go_glyph + if test "$no_go_installed" -eq "1" + # we got a version of go from a go.mod file, but no version of go is installed! + __bobthefish_start_segment $color_rvm + end + echo -ns $go_version ' ' +end + function __bobthefish_virtualenv_python_version -S -d 'Get current Python version' switch (python --version 2>&1 | tr '\n' ' ') case 'Python 2*PyPy*' From 4b3197d1b07062eb7c6f10c568619b704cad109e Mon Sep 17 00:00:00 2001 From: Sean Patrick Hagen Date: Fri, 17 Jun 2022 11:41:50 -0700 Subject: [PATCH 03/14] Sort out the logic a bit more --- functions/fish_prompt.fish | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/functions/fish_prompt.fish b/functions/fish_prompt.fish index 0a8fda2..5769ef0 100644 --- a/functions/fish_prompt.fish +++ b/functions/fish_prompt.fish @@ -875,14 +875,14 @@ function __bobthefish_prompt_golang -S -d 'Display current Go information' end set -l no_go_installed 0 + set -l gomod_version "0" + # no version from asdf, check go.mod file if [ -z "$go_version" ] set -l cwd (pwd) set -l dir (pwd) set -l gomod_file - set -l gomod_version set -l _gomod - set -l found_gomod 0 # find the closest go.mod @@ -890,7 +890,6 @@ function __bobthefish_prompt_golang -S -d 'Display current Go information' set gomod_file "$dir/go.mod" if test -f "$gomod_file" - set found_gomod 1 cat "$gomod_file" | grep "^go\ " | read _gomod gomod_version break end @@ -900,30 +899,28 @@ function __bobthefish_prompt_golang -S -d 'Display current Go information' end cd $cwd - if test "$found_gomod" -eq "1" - # found go.mod file, but no version inside - if [ -z (string trim -- "$gomod_version") ] - # is there a version of go we can ask for the version? - if type -fq go - set gomod_version (go version | string match -r 'go version go(\\d+\\.\\d+)' -g) - end - end - end - set go_version $gomod_version end + set -l actual_go_version "0" if ! type -fq go set no_go_installed 1 + else + set actual_go_version (go version | string match -r 'go version go(\\d+\\.\\d+)' -g) end [ -z "$go_version" ] and return + set -l high_enough_version 0 + if printf "%s\n%s" "$gomod_version" "$actual_go_version" | sort --check=silent --version-sort + set high_enough_version 1 + end + __bobthefish_start_segment $color_virtualgo echo -ns $go_glyph - if test "$no_go_installed" -eq "1" - # we got a version of go from a go.mod file, but no version of go is installed! + if test "$high_enough_version" -eq "0" + # the version of go __bobthefish_start_segment $color_rvm end echo -ns $go_version ' ' From 1663a155f8013e5bed0b596e237b9fff23a7060a Mon Sep 17 00:00:00 2001 From: Sean Patrick Hagen Date: Fri, 17 Jun 2022 11:54:52 -0700 Subject: [PATCH 04/14] More logic fixing --- functions/fish_prompt.fish | 46 +++++++++++++++++++------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/functions/fish_prompt.fish b/functions/fish_prompt.fish index 5769ef0..7602b4c 100644 --- a/functions/fish_prompt.fish +++ b/functions/fish_prompt.fish @@ -868,40 +868,40 @@ function __bobthefish_prompt_golang -S -d 'Display current Go information' echo "$asdf_go_sdk_version" | read _asdf_plugin asdf_go_version asdf_provenance end - [ (string trim -- "$asdf_provenance") = "$HOME/.tool-versions" ] - and return - set go_version $asdf_go_version end + + set -l cwd (pwd) + set -l dir (pwd) + set -l found_gomod 0 set -l no_go_installed 0 set -l gomod_version "0" - - # no version from asdf, check go.mod file - if [ -z "$go_version" ] - set -l cwd (pwd) - set -l dir (pwd) - set -l gomod_file - set -l _gomod - set -l found_gomod 0 - - # find the closest go.mod - while not test "$dir" = "/" - set gomod_file "$dir/go.mod" - - if test -f "$gomod_file" - cat "$gomod_file" | grep "^go\ " | read _gomod gomod_version - break - end + set -l gomod_file - cd $dir/.. - set dir (pwd) + # find the closest go.mod + while not test "$dir" = "/" + set gomod_file "$dir/go.mod" + + if test -f "$gomod_file" + set found_gomod 1 + cat "$gomod_file" | grep "^go\ " | read _gomod gomod_version + break end - cd $cwd + cd $dir/.. + set dir (pwd) + end + cd $cwd + + if [ -z "$go_version" ] set go_version $gomod_version end + if test "$found_gomod" -eq "0" + return + end + set -l actual_go_version "0" if ! type -fq go set no_go_installed 1 From 64a6f8ee18fd6202b7a7bbc30a461ee711dc2bd2 Mon Sep 17 00:00:00 2001 From: Sean Patrick Hagen Date: Fri, 17 Jun 2022 12:21:52 -0700 Subject: [PATCH 05/14] More logic cleanup/fixing --- functions/fish_prompt.fish | 60 +++++++++++++++++++++++--------------- 1 file changed, 36 insertions(+), 24 deletions(-) diff --git a/functions/fish_prompt.fish b/functions/fish_prompt.fish index 7602b4c..481b9a5 100644 --- a/functions/fish_prompt.fish +++ b/functions/fish_prompt.fish @@ -36,6 +36,8 @@ # set -g theme_display_nix no # set -g theme_display_ruby no # set -g theme_display_go no +# set -g theme_display_go_show_wrong_version yes +# set -g theme_display_go_actual diff # set -g theme_display_user ssh # set -g theme_display_hostname ssh # set -g theme_display_sudo_user yes @@ -854,14 +856,8 @@ function __bobthefish_prompt_golang -S -d 'Display current Go information' set -l go_version if type -fq asdf set -l asdf_golang_version (asdf current golang 2>/dev/null) - or set -l asdf_golang_version "na" - set -l asdf_go_sdk_version (asdf current go-sdk 2>/dev/null) - or set -l asdf_go_sdk_version "na" - set -l _asdf_plugin - set -l asdf_go_version - set -l asdf_provenance if [ "$asdf_golang_version" != "na" ] echo "$asdf_golang_version" | read _asdf_plugin asdf_go_version asdf_provenance else if [ "$asdf_go_sdk_version" != "na" ] @@ -875,7 +871,6 @@ function __bobthefish_prompt_golang -S -d 'Display current Go information' set -l cwd (pwd) set -l dir (pwd) set -l found_gomod 0 - set -l no_go_installed 0 set -l gomod_version "0" set -l gomod_file @@ -894,36 +889,53 @@ function __bobthefish_prompt_golang -S -d 'Display current Go information' end cd $cwd - if [ -z "$go_version" ] - set go_version $gomod_version - end - + # no go.mod, not in a go project, don't display the prompt if test "$found_gomod" -eq "0" return - end + end - set -l actual_go_version "0" + # check if there's a Go executable + set -l no_go_installed 0 + set -l actual_go_version 0 if ! type -fq go set no_go_installed 1 else set actual_go_version (go version | string match -r 'go version go(\\d+\\.\\d+)' -g) end - [ -z "$go_version" ] - and return - set -l high_enough_version 0 - if printf "%s\n%s" "$gomod_version" "$actual_go_version" | sort --check=silent --version-sort - set high_enough_version 1 - end + if test "$no_go_installed" -eq "0" + if printf "%s\n%s" "$gomod_version" "$actual_go_version" | sort --check=silent --version-sort + set high_enough_version 1 + end + end __bobthefish_start_segment $color_virtualgo echo -ns $go_glyph - if test "$high_enough_version" -eq "0" - # the version of go - __bobthefish_start_segment $color_rvm - end - echo -ns $go_version ' ' + + # do we show the version in red if it's not the right version? + if [ "$theme_display_go_show_wrong_version" = "yes" ] + # yes we do, so check if the version is high enough + if test "$high_enough_version" -eq "0" + # the version of go isn't high enough + __bobthefish_start_segment $color_rvm + end + end + + if [ "$theme_display_go_actual" = "yes" ] + echo -ns "$actual_go_version" + else + echo -ns "$gomod_version" ' ' + if [ "$theme_display_go_actual" = "diff" ] + if [ "$gomod_version" != "$actual_go_version" ] + if [ "$actual_go_version" = "0" ] + echo -ns "(NA)" + else + echo -ns "($actual_go_version)" + end + end + end + end end function __bobthefish_virtualenv_python_version -S -d 'Get current Python version' From 20eb30bf4f1d0d5154107efd03533e0e3c763cae Mon Sep 17 00:00:00 2001 From: Sean Patrick Hagen Date: Fri, 17 Jun 2022 12:26:05 -0700 Subject: [PATCH 06/14] Removing some un-needed code --- functions/fish_prompt.fish | 39 ++++++++++++++------------------------ 1 file changed, 14 insertions(+), 25 deletions(-) diff --git a/functions/fish_prompt.fish b/functions/fish_prompt.fish index 481b9a5..1bfe471 100644 --- a/functions/fish_prompt.fish +++ b/functions/fish_prompt.fish @@ -853,21 +853,6 @@ function __bobthefish_prompt_golang -S -d 'Display current Go information' [ "$theme_display_go" = 'no' ] and return - set -l go_version - if type -fq asdf - set -l asdf_golang_version (asdf current golang 2>/dev/null) - set -l asdf_go_sdk_version (asdf current go-sdk 2>/dev/null) - - if [ "$asdf_golang_version" != "na" ] - echo "$asdf_golang_version" | read _asdf_plugin asdf_go_version asdf_provenance - else if [ "$asdf_go_sdk_version" != "na" ] - echo "$asdf_go_sdk_version" | read _asdf_plugin asdf_go_version asdf_provenance - end - - set go_version $asdf_go_version - end - - set -l cwd (pwd) set -l dir (pwd) set -l found_gomod 0 @@ -895,18 +880,18 @@ function __bobthefish_prompt_golang -S -d 'Display current Go information' end # check if there's a Go executable - set -l no_go_installed 0 - set -l actual_go_version 0 - if ! type -fq go - set no_go_installed 1 + set -l no_go_installed "0" + set -l actual_go_version "0" + if type -fq go + set actual_go_version (go version | string match -r 'go version go(\\d+\\.\\d+)' -g) else - set actual_go_version (go version | string match -r 'go version go(\\d+\\.\\d+)' -g) + set no_go_installed "1" end - set -l high_enough_version 0 - if test "$no_go_installed" -eq "0" + set -l high_enough_version "0" + if [ "$no_go_installed" = "0" ] if printf "%s\n%s" "$gomod_version" "$actual_go_version" | sort --check=silent --version-sort - set high_enough_version 1 + set high_enough_version "1" end end @@ -916,14 +901,18 @@ function __bobthefish_prompt_golang -S -d 'Display current Go information' # do we show the version in red if it's not the right version? if [ "$theme_display_go_show_wrong_version" = "yes" ] # yes we do, so check if the version is high enough - if test "$high_enough_version" -eq "0" + if [ "$high_enough_version" = "0" ] # the version of go isn't high enough __bobthefish_start_segment $color_rvm end end if [ "$theme_display_go_actual" = "yes" ] - echo -ns "$actual_go_version" + if [ "$actual_go_version" = "0" ] + echo -ns "(NA)" + else + echo -ns "($actual_go_version)" + end else echo -ns "$gomod_version" ' ' if [ "$theme_display_go_actual" = "diff" ] From 69e58a2f6883b82b5fdd53b0b5f649be30f3bceb Mon Sep 17 00:00:00 2001 From: Sean Patrick Hagen Date: Fri, 17 Jun 2022 12:40:13 -0700 Subject: [PATCH 07/14] Better greping --- functions/fish_prompt.fish | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/functions/fish_prompt.fish b/functions/fish_prompt.fish index 1bfe471..75e3911 100644 --- a/functions/fish_prompt.fish +++ b/functions/fish_prompt.fish @@ -865,7 +865,7 @@ function __bobthefish_prompt_golang -S -d 'Display current Go information' if test -f "$gomod_file" set found_gomod 1 - cat "$gomod_file" | grep "^go\ " | read _gomod gomod_version + grep "^go\ " "$gomod_file" | read __ gomod_version break end From 27f900076e1eb435541f538e7ac65dec4a97049e Mon Sep 17 00:00:00 2001 From: Sean Patrick Hagen Date: Fri, 17 Jun 2022 12:40:18 -0700 Subject: [PATCH 08/14] Some prompt cleanup --- functions/fish_prompt.fish | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/functions/fish_prompt.fish b/functions/fish_prompt.fish index 75e3911..d8aa618 100644 --- a/functions/fish_prompt.fish +++ b/functions/fish_prompt.fish @@ -909,9 +909,9 @@ function __bobthefish_prompt_golang -S -d 'Display current Go information' if [ "$theme_display_go_actual" = "yes" ] if [ "$actual_go_version" = "0" ] - echo -ns "(NA)" + echo -ns "NA" else - echo -ns "($actual_go_version)" + echo -ns "$actual_go_version" end else echo -ns "$gomod_version" ' ' From fffbde266fb65e9cc8718d1550193fcb6217538e Mon Sep 17 00:00:00 2001 From: Sean Patrick Hagen Date: Fri, 17 Jun 2022 12:41:49 -0700 Subject: [PATCH 09/14] Better "find directory", copied from hg code --- functions/fish_prompt.fish | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/functions/fish_prompt.fish b/functions/fish_prompt.fish index d8aa618..61d7ee5 100644 --- a/functions/fish_prompt.fish +++ b/functions/fish_prompt.fish @@ -853,26 +853,21 @@ function __bobthefish_prompt_golang -S -d 'Display current Go information' [ "$theme_display_go" = 'no' ] and return - set -l cwd (pwd) - set -l dir (pwd) + + set -l dir $real_pwd set -l found_gomod 0 set -l gomod_version "0" set -l gomod_file # find the closest go.mod - while not test "$dir" = "/" - set gomod_file "$dir/go.mod" - - if test -f "$gomod_file" - set found_gomod 1 + while not [ -z "$d" ] + if [ -e $d/go.mod ] grep "^go\ " "$gomod_file" | read __ gomod_version - break end - cd $dir/.. - set dir (pwd) + [ "$d" = "/" ] + and return end - cd $cwd # no go.mod, not in a go project, don't display the prompt if test "$found_gomod" -eq "0" From 92a2e467344712c8207250203b8b3eb66d5e9677 Mon Sep 17 00:00:00 2001 From: Sean Patrick Hagen Date: Fri, 17 Jun 2022 12:48:58 -0700 Subject: [PATCH 10/14] Update loop for finding go.mod Also had to move `set -l real_pwd (__bobthefish_pwd)` above the prompts so that `$real_pwd` is available inside the prompt function --- functions/fish_prompt.fish | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/functions/fish_prompt.fish b/functions/fish_prompt.fish index 61d7ee5..36138ff 100644 --- a/functions/fish_prompt.fish +++ b/functions/fish_prompt.fish @@ -852,17 +852,14 @@ end function __bobthefish_prompt_golang -S -d 'Display current Go information' [ "$theme_display_go" = 'no' ] and return - - - set -l dir $real_pwd - set -l found_gomod 0 - set -l gomod_version "0" - set -l gomod_file # find the closest go.mod + set -l gomod_version "0" + set -l d $real_pwd while not [ -z "$d" ] if [ -e $d/go.mod ] - grep "^go\ " "$gomod_file" | read __ gomod_version + grep "^go\ " "$d/go.mod" | read __ gomod_version + break end [ "$d" = "/" ] @@ -870,7 +867,7 @@ function __bobthefish_prompt_golang -S -d 'Display current Go information' end # no go.mod, not in a go project, don't display the prompt - if test "$found_gomod" -eq "0" + if [ "$gomod_version" = "0" ] return end @@ -1229,6 +1226,8 @@ function fish_prompt -d 'bobthefish, a fish theme optimized for awesome' # Start each line with a blank slate set -l __bobthefish_current_bg + + set -l real_pwd (__bobthefish_pwd) # Status flags and input mode __bobthefish_prompt_status $last_status @@ -1253,7 +1252,6 @@ function fish_prompt -d 'bobthefish, a fish theme optimized for awesome' __bobthefish_prompt_virtualgo __bobthefish_prompt_node - set -l real_pwd (__bobthefish_pwd) # VCS set -l git_root_dir (__bobthefish_git_project_dir $real_pwd) From bb9c3f194609e6120c99ca0515a54f3b254f19d9 Mon Sep 17 00:00:00 2001 From: Sean Patrick Hagen Date: Fri, 17 Jun 2022 12:58:52 -0700 Subject: [PATCH 11/14] Ensure we go up a directory each iteration Whoops --- functions/fish_prompt.fish | 2 ++ 1 file changed, 2 insertions(+) diff --git a/functions/fish_prompt.fish b/functions/fish_prompt.fish index 36138ff..4b5eb9f 100644 --- a/functions/fish_prompt.fish +++ b/functions/fish_prompt.fish @@ -864,6 +864,8 @@ function __bobthefish_prompt_golang -S -d 'Display current Go information' [ "$d" = "/" ] and return + + set d (__bobthefish_dirname $d) end # no go.mod, not in a go project, don't display the prompt From d25d03ab4a37fa4be54a272b4443956620b15330 Mon Sep 17 00:00:00 2001 From: Sean Patrick Hagen Date: Fri, 17 Jun 2022 13:01:51 -0700 Subject: [PATCH 12/14] Better color setting for prompt --- functions/fish_prompt.fish | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/functions/fish_prompt.fish b/functions/fish_prompt.fish index 4b5eb9f..04f2a07 100644 --- a/functions/fish_prompt.fish +++ b/functions/fish_prompt.fish @@ -887,19 +887,21 @@ function __bobthefish_prompt_golang -S -d 'Display current Go information' if printf "%s\n%s" "$gomod_version" "$actual_go_version" | sort --check=silent --version-sort set high_enough_version "1" end - end + end - __bobthefish_start_segment $color_virtualgo - echo -ns $go_glyph - # do we show the version in red if it's not the right version? if [ "$theme_display_go_show_wrong_version" = "yes" ] # yes we do, so check if the version is high enough if [ "$high_enough_version" = "0" ] # the version of go isn't high enough __bobthefish_start_segment $color_rvm + else + __bobthefish_start_segment $color_virtualgo end + else + __bobthefish_start_segment $color_virtualgo end + echo -ns $go_glyph if [ "$theme_display_go_actual" = "yes" ] if [ "$actual_go_version" = "0" ] From 4828218af53bd0706d7edf11eadd4bb357b5728c Mon Sep 17 00:00:00 2001 From: Sean Patrick Hagen Date: Sat, 18 Jun 2022 14:08:52 -0700 Subject: [PATCH 13/14] Simplifying the prompt --- functions/fish_prompt.fish | 59 +++++++++++++------------------------- 1 file changed, 20 insertions(+), 39 deletions(-) diff --git a/functions/fish_prompt.fish b/functions/fish_prompt.fish index 04f2a07..9c17c01 100644 --- a/functions/fish_prompt.fish +++ b/functions/fish_prompt.fish @@ -36,8 +36,6 @@ # set -g theme_display_nix no # set -g theme_display_ruby no # set -g theme_display_go no -# set -g theme_display_go_show_wrong_version yes -# set -g theme_display_go_actual diff # set -g theme_display_user ssh # set -g theme_display_hostname ssh # set -g theme_display_sudo_user yes @@ -849,7 +847,8 @@ function __bobthefish_prompt_rubies -S -d 'Display current Ruby information' echo -ns $ruby_glyph $ruby_version ' ' end -function __bobthefish_prompt_golang -S -d 'Display current Go information' +function __bobthefish_prompt_golang -S -a real_pwd -d 'Display current Go information' + # setting is 'no', don't display the prompt [ "$theme_display_go" = 'no' ] and return @@ -876,49 +875,31 @@ function __bobthefish_prompt_golang -S -d 'Display current Go information' # check if there's a Go executable set -l no_go_installed "0" set -l actual_go_version "0" - if type -fq go - set actual_go_version (go version | string match -r 'go version go(\\d+\\.\\d+)' -g) - else - set no_go_installed "1" - end - set -l high_enough_version "0" - if [ "$no_go_installed" = "0" ] + if type -fq go + set actual_go_version (go version | string match -r 'go version go(\\d+\\.\\d+)' -g) if printf "%s\n%s" "$gomod_version" "$actual_go_version" | sort --check=silent --version-sort set high_enough_version "1" end - end - - # do we show the version in red if it's not the right version? - if [ "$theme_display_go_show_wrong_version" = "yes" ] - # yes we do, so check if the version is high enough - if [ "$high_enough_version" = "0" ] - # the version of go isn't high enough - __bobthefish_start_segment $color_rvm - else - __bobthefish_start_segment $color_virtualgo - end else + set no_go_installed "1" + end + + if [ "$high_enough_version" = "1" ] __bobthefish_start_segment $color_virtualgo + else + __bobthefish_start_segment $color_rvm end - echo -ns $go_glyph - if [ "$theme_display_go_actual" = "yes" ] - if [ "$actual_go_version" = "0" ] - echo -ns "NA" - else - echo -ns "$actual_go_version" - end - else - echo -ns "$gomod_version" ' ' - if [ "$theme_display_go_actual" = "diff" ] - if [ "$gomod_version" != "$actual_go_version" ] - if [ "$actual_go_version" = "0" ] - echo -ns "(NA)" - else - echo -ns "($actual_go_version)" - end - end + echo -ns $go_glyph + echo -ns "$gomod_version " + + # showing the prompt -- but plain ( for 'yes' ) or verbose? + if [ "$theme_display_go" = "verbose" ] + if [ "$actual_go_version" != "0" ] + # show the prompt with the required version AND the currently available + # version; same color rules as above + echo -ns " ($actual_go_version)" end end end @@ -1251,7 +1232,7 @@ function fish_prompt -d 'bobthefish, a fish theme optimized for awesome' __bobthefish_prompt_nix __bobthefish_prompt_desk __bobthefish_prompt_rubies - __bobthefish_prompt_golang + __bobthefish_prompt_golang $real_pwd __bobthefish_prompt_virtualfish __bobthefish_prompt_virtualgo __bobthefish_prompt_node From 9ff7cd3f3c1445830895ca3b02a741a0e8692a5e Mon Sep 17 00:00:00 2001 From: Sean Patrick Hagen Date: Wed, 12 Oct 2022 14:05:37 -0700 Subject: [PATCH 14/14] Remove backslash to remove grep warning New in grep 3.8 apparently is this warning: `grep: warning: stray \ before white space`. Explanation: https://github.com/koalaman/shellcheck/issues/2573 --- functions/fish_prompt.fish | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/functions/fish_prompt.fish b/functions/fish_prompt.fish index 9c17c01..7e1161a 100644 --- a/functions/fish_prompt.fish +++ b/functions/fish_prompt.fish @@ -857,7 +857,7 @@ function __bobthefish_prompt_golang -S -a real_pwd -d 'Display current Go inform set -l d $real_pwd while not [ -z "$d" ] if [ -e $d/go.mod ] - grep "^go\ " "$d/go.mod" | read __ gomod_version + grep "^go " "$d/go.mod" | read __ gomod_version break end