From 8d10cc948887e3cff29923d758999afa6edf87fb Mon Sep 17 00:00:00 2001 From: Grant Stephens Date: Mon, 7 Sep 2026 15:49:06 +0100 Subject: [PATCH] feat(go): Create go_prompt_info to add Go version to theme prompts (#8924) * Create go_prompt_info to add go version to prompts * golang: move go_prompt_info to plugin, guard and quote output Addresses review feedback: the prompt helper only belongs to Go developers, so it moves out of lib/ (sourced for every shell) into plugins/golang/golang.plugin.zsh. Adds a $+commands[go] guard so users without Go installed don't spawn a process or see a stderr error on every prompt render, quotes the version output the same way the rvm/nvm helpers do so a % can't be read as a prompt escape, and adds the dummy go_prompt_info stub to lib/prompt_info_functions.zsh for themes that call it when the plugin isn't loaded. Co-Authored-By: Claude Sonnet 5 Claude-Session: https://claude.ai/code/session_0193G8TyNqmNnv6v9HsVafGa --------- Co-authored-by: Claude Sonnet 5 --- lib/prompt_info_functions.zsh | 1 + plugins/golang/README.md | 15 +++++++++++++++ plugins/golang/golang.plugin.zsh | 9 +++++++++ 3 files changed, 25 insertions(+) diff --git a/lib/prompt_info_functions.zsh b/lib/prompt_info_functions.zsh index 722ae58c0..9b8e2de9d 100644 --- a/lib/prompt_info_functions.zsh +++ b/lib/prompt_info_functions.zsh @@ -21,6 +21,7 @@ function chruby_prompt_info \ azure_prompt_info \ tf_prompt_info \ conda_prompt_info \ + go_prompt_info \ { return 1 } diff --git a/plugins/golang/README.md b/plugins/golang/README.md index 80f8cf3b5..610952d6d 100644 --- a/plugins/golang/README.md +++ b/plugins/golang/README.md @@ -39,3 +39,18 @@ plugins=(... golang) | gov | `go vet` | Vet examines Go source code and reports suspicious constructs | | gove | `go version` | Prints Go version | | gow | `go work` | Work provides access to operations on workspaces | + +## Prompt + +This plugin provides the `go_prompt_info` function to add the installed Go +version to your prompt. + +For example: +``` +PROMPT="%~$ " +RPROMPT='$(go_prompt_info)' +``` +changes your prompt to: +``` +~/go/project$ ▋ 1.22.3 +``` diff --git a/plugins/golang/golang.plugin.zsh b/plugins/golang/golang.plugin.zsh index dc4d91845..48908b5d9 100644 --- a/plugins/golang/golang.plugin.zsh +++ b/plugins/golang/golang.plugin.zsh @@ -36,3 +36,12 @@ alias gotofx='go tool fix' alias gov='go vet' alias gove='go version' alias gow='go work' + +## prompt +function go_prompt_info() { + (( $+commands[go] )) || return + local go_prompt + go_prompt=$(go version | awk '{ print substr($3, 3) }') + [[ -z "${go_prompt}" ]] && return + echo "${ZSH_THEME_GO_PROMPT_PREFIX}${go_prompt:gs/%/%%}${ZSH_THEME_GO_PROMPT_SUFFIX}" +}