Skip to content

Commit

Permalink
Merge pull request #75 from burl/master
Browse files Browse the repository at this point in the history
added node module/segment that displays version from package.json in …
  • Loading branch information
justjanne authored Apr 11, 2018
2 parents 2530cca + ef23772 commit 40c9e92
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 2 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ Usage of powerline-go:
(default "patched")
-modules string
The list of modules to load, separated by ','
(valid choices: aws, cwd, docker, dotenv, exit, git, gitlite, hg, host, jobs, perlbrew, perms, root, shell-var, ssh, time, user, venv)
(valid choices: aws, cwd, docker, dotenv, exit, git, gitlite, hg, host, jobs, perlbrew, perms, root, shell-var, ssh, time, user, venv, node)
(default "venv,user,host,ssh,cwd,perms,git,hg,jobs,exit,root")
-newline
Show the prompt on a new line
Expand All @@ -167,7 +167,7 @@ Usage of powerline-go:
Use '~' for your home dir. You may need to escape this character to avoid shell substitution.
-priority string
Segments sorted by priority, if not enough space exists, the least priorized segments are removed first. Separate with ','
(valid choices: aws, cwd, cwd-path, docker, exit, git-branch, git-status, hg, host, jobs, perlbrew, perms, root, ssh, time, user, venv)
(valid choices: aws, cwd, cwd-path, docker, exit, git-branch, git-status, hg, host, jobs, perlbrew, perms, root, ssh, time, user, venv, node)
(default "root,cwd,user,host,ssh,perms,git-branch,git-status,hg,jobs,exit,cwd-path")
-shell string
Set this to your shell type
Expand Down
3 changes: 3 additions & 0 deletions defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,9 @@ var themes = map[string]Theme{
ShellVarFg: 52,
ShellVarBg: 11,

NodeFg: 15,
NodeBg: 40,

HostnameColorizedFgMap: map[uint8]uint8{
0: 250,
1: 250,
Expand Down
1 change: 1 addition & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ var modules = map[string](func(*powerline)){
"ssh": segmentSsh,
"termtitle": segmentTermTitle,
"time": segmentTime,
"node": segmentNode,
"user": segmentUser,
"venv": segmentVirtualEnv,
"vgo": segmentVirtualGo,
Expand Down
29 changes: 29 additions & 0 deletions segment-node.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package main

import (
"encoding/json"
"io/ioutil"
"os"
)

const pkgfile = "./package.json"

type packageJSON struct {
Version string `json:"version"`
}

func segmentNode(p *powerline) {
stat, err := os.Stat(pkgfile)
if err == nil && !stat.IsDir() {
pkg := packageJSON{"!"}
raw, err := ioutil.ReadFile(pkgfile)
if err == nil {
json.Unmarshal(raw, &pkg)
}
p.appendSegment("node-version", segment{
content: pkg.Version + " \u2B22",
foreground: p.theme.NodeFg,
background: p.theme.NodeBg,
})
}
}
3 changes: 3 additions & 0 deletions themes.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,7 @@ type Theme struct {

ShellVarFg uint8
ShellVarBg uint8

NodeFg uint8
NodeBg uint8
}
2 changes: 2 additions & 0 deletions themes/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@
"TimeBg": 236,
"ShellVarFg": 52,
"ShellVarBg": 11,
"NodeFg": 15,
"NodeBg": 40,
"HostnameColorizedFgMap": {
"0": 250,
"1": 250,
Expand Down

0 comments on commit 40c9e92

Please sign in to comment.