From a6c0510cc2d99165a3ee355946cd553575759c98 Mon Sep 17 00:00:00 2001 From: Greg Fitzgerald Date: Wed, 23 Sep 2015 18:29:13 -0400 Subject: [PATCH] Add Go version to prompt, only displayed when in a go source tree --- README.md | 9 +++++++++ bullet-train.zsh-theme | 29 +++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/README.md b/README.md index 2c5a3f3..6c7c05c 100644 --- a/README.md +++ b/README.md @@ -164,6 +164,15 @@ or don't want to see. All options must be overridden in your **.zshrc** file. |`BULLETTRAIN_RUBY_FG`|`white`|Foreground color |`BULLETTRAIN_RUBY_PREFIX`|`"♦"`|Prefix of the segment +### Go + +|Variable|Default|Meaning +|--------|-------|-------| +|`BULLETTRAIN_GO_SHOW`|`false`|Show/hide that segment +|`BULLETTRAIN_GO_BG`|`green`|Background color +|`BULLETTRAIN_GO_FG`|`white`|Foreground color +|`BULLETTRAIN_GO_PREFIX`|`""`|Prefix of the segment + ### Dir |Variable|Default|Meaning diff --git a/bullet-train.zsh-theme b/bullet-train.zsh-theme index 0114fc0..8a138af 100644 --- a/bullet-train.zsh-theme +++ b/bullet-train.zsh-theme @@ -96,6 +96,20 @@ if [ ! -n "${BULLETTRAIN_RUBY_PREFIX+1}" ]; then BULLETTRAIN_RUBY_PREFIX=♦️ fi +# Go +if [ ! -n "${BULLETTRAIN_GO_SHOW+1}" ]; then + BULLETTRAIN_GO_SHOW=true +fi +if [ ! -n "${BULLETTRAIN_GO_BG+1}" ]; then + BULLETTRAIN_GO_BG=cyan +fi +if [ ! -n "${BULLETTRAIN_GO_FG+1}" ]; then + BULLETTRAIN_GO_FG=white +fi +if [ ! -n "${BULLETTRAIN_GO_PREFIX+1}" ]; then + BULLETTRAIN_GO_PREFIX= +fi + # DIR if [ ! -n "${BULLETTRAIN_DIR_SHOW+1}" ]; then BULLETTRAIN_DIR_SHOW=true @@ -358,6 +372,20 @@ prompt_ruby() { fi } +# Go +prompt_go() { + if [[ $BULLETTRAIN_GO_SHOW == false ]]; then + return + fi + + setopt extended_glob + if [[ (-f *.go(#qN) || -d Godeps) ]]; then + if command -v go > /dev/null 2>&1; then + prompt_segment $BULLETTRAIN_GO_BG $BULLETTRAIN_GO_FG $BULLETTRAIN_GO_PREFIX"$(go version | grep -oE 'go[[:digit:]].[[:digit:]]')" + fi + fi +} + # Virtualenv: current working virtualenv prompt_virtualenv() { if [[ $BULLETTRAIN_VIRTUALENV_SHOW == false ]]; then @@ -460,6 +488,7 @@ build_prompt() { prompt_ruby prompt_virtualenv prompt_nvm + prompt_go prompt_context prompt_dir prompt_git