Skip to content
This repository has been archived by the owner on Apr 24, 2020. It is now read-only.

Enhacement: Go Version segment uses Go colours and only the version number is shown. #1242

Open
wants to merge 1 commit into
base: next
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion segments/go_version/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,18 @@ where you want to show this segment.

## Configuration

This segment shows the version of Go installed.

It figures out the version being used by taking the output of the `go version` command.

* If `go` is not in $PATH, nothing will be shown.
* By default, if the current Go version is only shown while inside your GOPATH. See the configuration variable, below, to modify this behavior.

| Variable | Default Value | Description |
|----------|---------------|-------------|
|`P9K_GO_VERSION_PROMPT_ALWAYS_SHOW` |`false`|Set to true if you wish to show the go_version segment even if you're not inside your GOPATH. |


### Color Customization

You can change the foreground and background color of this segment by setting
Expand All @@ -21,4 +33,4 @@ P9K_GO_VERSION_BACKGROUND='blue'
### Customize Icon

The main Icon can be changed by setting `P9K_GO_VERSION_ICON="my_icon"`. To change the
icon color only, set `P9K_GO_VERSION_ICON_COLOR="red"`.
icon color only, set `P9K_GO_VERSION_ICON_COLOR="red"`.
10 changes: 7 additions & 3 deletions segments/go_version/go_version.p9k
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@
# Parameters:
# segment_name context background foreground Generic Flat/Awesome-Patched Awesome-FontConfig Awesome-Mapped-FontConfig NerdFont
#  
p9k::register_segment "GO_VERSION" '' 'green' 'grey93' 'Go' '' '' '\u'${CODEPOINT_OF_DEVICONS_GIT_PULL_REQUEST} $'\uE626'
p9k::register_segment "GO_VERSION" '' 'cyan' 'black' 'Go' '' '' '\u'${CODEPOINT_OF_DEVICONS_GIT_PULL_REQUEST} $'\uE626'

################################################################
# Register segment default values
p9k::set_default P9K_GO_VERSION_PROMPT_ALWAYS_SHOW false
}

################################################################
Expand All @@ -27,10 +31,10 @@
prompt_go_version() {
local go_version
local go_path
go_version=$(go version 2>/dev/null | sed -E "s/.*(go[0-9.]*).*/\1/")
go_version=$(go version 2>/dev/null | sed -E 's/.*(go[0-9.]*).*/\1/; s/go//g')
go_path=$(go env GOPATH 2>/dev/null)

if [[ -n "$go_version" && "${PWD##$go_path}" != "$PWD" ]]; then
if [[ -n "$go_version" && "${PWD##$go_path}" != "$PWD" || "${P9K_GO_VERSION_PROMPT_ALWAYS_SHOW}" == "true" ]]; then
p9k::prepare_segment "$0" "" $1 "$2" $3 "$go_version"
fi
}
2 changes: 1 addition & 1 deletion segments/go_version/go_version.spec
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ function testGo() {

PWD="$HOME/go/src/github.com/bhilburn/powerlevel9k"

assertEquals "%K{002} %F{255}Go %F{255}go1.5.3 %k%F{002}%f " "$(__p9k_build_left_prompt)"
assertEquals "%K{006} %F{000}Go %F{000}1.5.3 %k%F{006}%f " "$(__p9k_build_left_prompt)"

unset P9K_GO_ICON
unset PWD
Expand Down
Binary file modified segments/go_version/segment.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 5 additions & 5 deletions segments/go_version/segment.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.