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

Commit 8c2d08a

Browse files
committed
Enhacement: Go Version segment uses Go colours and only the version number is
shown. 1. Why is this change neccesary? Because the go_version segment had a green background when other segments (like rbenv) have a colour that matches the language. The Go version had the string "go" before the semantic versioning being redundant to have the Gopher icon and the String. The segment was only visible when inside the GOPATH, and some users (like me) may be interested in the segment being shown persistently. 2. How does it address the issue? The background colour was changed from green to cyan and the foreground colour from white to black in order to match Go colours. Only the version of Go is shown in the segment. A variable was added to see the segment persistently if the user wishes to. 3. What side effects does this change have? None!
1 parent 9429fe6 commit 8c2d08a

File tree

4 files changed

+21
-5
lines changed

4 files changed

+21
-5
lines changed

segments/go_version/README.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,18 @@ where you want to show this segment.
1010

1111
## Configuration
1212

13+
This segment shows the version of Go installed.
14+
15+
It figures out the version being used by taking the output of the `go version` command.
16+
17+
* If `go` is not in $PATH, nothing will be shown.
18+
* By default, if the current Go version is only shown while inside your GOPATH. See the configuration variable, below, to modify this behavior.
19+
20+
| Variable | Default Value | Description |
21+
|----------|---------------|-------------|
22+
|`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. |
23+
24+
1325
### Color Customization
1426

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

2335
The main Icon can be changed by setting `P9K_GO_VERSION_ICON="my_icon"`. To change the
24-
icon color only, set `P9K_GO_VERSION_ICON_COLOR="red"`.
36+
icon color only, set `P9K_GO_VERSION_ICON_COLOR="red"`.

segments/go_version/go_version.p9k

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@
1212
# Parameters:
1313
# segment_name context background foreground Generic Flat/Awesome-Patched Awesome-FontConfig Awesome-Mapped-FontConfig NerdFont
1414
#  
15-
p9k::register_segment "GO_VERSION" '' 'green' 'grey93' 'Go' '' '' '\u'${CODEPOINT_OF_DEVICONS_GIT_PULL_REQUEST} $'\uE626'
15+
p9k::register_segment "GO_VERSION" '' 'cyan' 'black' 'Go' '' '' '\u'${CODEPOINT_OF_DEVICONS_GIT_PULL_REQUEST} $'\uE626'
16+
17+
################################################################
18+
# Register segment default values
19+
p9k::set_default P9K_GO_VERSION_PROMPT_ALWAYS_SHOW false
1620
}
1721

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

33-
if [[ -n "$go_version" && "${PWD##$go_path}" != "$PWD" ]]; then
37+
if [[ -n "$go_version" && "${PWD##$go_path}" != "$PWD" || "${P9K_GO_VERSION_PROMPT_ALWAYS_SHOW}" == "true" ]]; then
3438
p9k::prepare_segment "$0" "" $1 "$2" $3 "$go_version"
3539
fi
3640
}

segments/go_version/go_version.spec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ function testGo() {
4444

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

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

4949
unset P9K_GO_ICON
5050
unset PWD

segments/go_version/segment.png

2.06 KB
Loading

0 commit comments

Comments
 (0)