diff options
author | Roger Gonzalez <rogergonzalez21@gmail.com> | 2019-12-29 14:58:33 -0300 |
---|---|---|
committer | Roger Gonzalez <rogergonzalez21@gmail.com> | 2019-12-29 14:58:33 -0300 |
commit | efb336a23b65a9a2d56889396b13c1757bdaf354 (patch) | |
tree | 234e40115f79a84c8a755df6fb932cc6797e36e1 /.config/fisher/github.com/matchai/spacefish/functions/__sf_section_golang.fish |
Initial commit
Diffstat (limited to '.config/fisher/github.com/matchai/spacefish/functions/__sf_section_golang.fish')
-rw-r--r-- | .config/fisher/github.com/matchai/spacefish/functions/__sf_section_golang.fish | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/.config/fisher/github.com/matchai/spacefish/functions/__sf_section_golang.fish b/.config/fisher/github.com/matchai/spacefish/functions/__sf_section_golang.fish new file mode 100644 index 00000000..81211ee4 --- /dev/null +++ b/.config/fisher/github.com/matchai/spacefish/functions/__sf_section_golang.fish @@ -0,0 +1,55 @@ +# +# Go +# +# Go is an open source programming language that makes it easy +# to build efficient software. +# Link: https://golang.org/ + +function __sf_section_golang -d "Display the current go version if you're inside GOPATH" + # ------------------------------------------------------------------------------ + # Configuration + # ------------------------------------------------------------------------------ + + __sf_util_set_default SPACEFISH_GOLANG_SHOW true + __sf_util_set_default SPACEFISH_GOLANG_PREFIX $SPACEFISH_PROMPT_DEFAULT_PREFIX + __sf_util_set_default SPACEFISH_GOLANG_SUFFIX $SPACEFISH_PROMPT_DEFAULT_SUFFIX + __sf_util_set_default SPACEFISH_GOLANG_SYMBOL "🐹 " + __sf_util_set_default SPACEFISH_GOLANG_COLOR cyan + + # ------------------------------------------------------------------------------ + # Section + # ------------------------------------------------------------------------------ + + # Show the current version of Golang + [ $SPACEFISH_GOLANG_SHOW = false ]; and return + + # Ensure the go command is available + type -q go; or return + + if not test -f go.mod \ + -o -d Godeps \ + -o -f glide.yaml \ + -o (count *.go) -gt 0 \ + -o -f Gopkg.yml \ + -o -f Gopkg.lock \ + -o ([ (count $GOPATH) -gt 0 ]; and string match $GOPATH $PWD) + return + end + + set -l go_version (go version | string split ' ') + + # Go version is either the commit hash and date (devel +5efe9a8f11 Web Jan 9 07:21:16 2019 +0000) + # at the time of the build or a release tag (go1.11.4) + # https://github.com/matchai/spacefish/issues/137 + if test (string match 'devel*' $go_version[3]) + set go_version $go_version[3]":"(string sub -s 2 $go_version[4]) + else + set go_version "v"(string sub -s 3 $go_version[3]) + end + + __sf_lib_section \ + $SPACEFISH_GOLANG_COLOR \ + $SPACEFISH_GOLANG_PREFIX \ + "$SPACEFISH_GOLANG_SYMBOL""$go_version" \ + $SPACEFISH_GOLANG_SUFFIX +end |