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

Commit

Permalink
Enhacement: Go Version segment uses Go colours and only the version n…
Browse files Browse the repository at this point in the history
…umber 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!
  • Loading branch information
denisse-dev committed Apr 5, 2019
1 parent 9429fe6 commit 8c2d08a
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 5 deletions.
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.

0 comments on commit 8c2d08a

Please sign in to comment.