diff --git a/.editorconfig b/.editorconfig index ae72bae0..47fac873 100644 --- a/.editorconfig +++ b/.editorconfig @@ -3,5 +3,5 @@ # In Go files we indent with tabs but still # set indent_size to control the GitHub web viewer. [*.go] -indent_size=4 +indent_size = 4 diff --git a/.travis.yml b/.travis.yml index 4fcc8145..0b721cff 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,7 +2,7 @@ sudo: false language: go go: -- 1.9 + - 1.10 before_script: - go get diff --git a/README.md b/README.md index ff9acfce..139c6d2d 100644 --- a/README.md +++ b/README.md @@ -152,14 +152,14 @@ Usage of powerline-go: Colorize the hostname based on a hash of itself -cwd-max-depth int Maximum number of directories to show in path - (default 5) + (default 5) -cwd-max-dir-size int Maximum number of letters displayed for each directory in the path - (default -1) + (default -1) -cwd-mode string How to display the current directory - (valid choices: fancy, plain, dironly) - (default "fancy") + (valid choices: fancy, plain, dironly) + (default "fancy") -duration string The elapsed clock-time of the previous command -east-asian-width @@ -170,49 +170,48 @@ Usage of powerline-go: Output prompt in 'eval' format. -ignore-repos string A list of git repos to ignore. Separate with ','. - Repos are identified by their root directory. + Repos are identified by their root directory. -max-width int Maximum width of the shell that the prompt may use, in percent. Setting this to 0 disables the shrinking subsystem. - -mode string The characters used to make separators between segments. - (valid choices: patched, compatible, flat) - (default "patched") + (valid choices: patched, compatible, flat) + (default "patched") -modules string The list of modules to load, separated by ',' - (valid choices: aws, cwd, docker, dotenv, duration, exit, git, gitlite, hg, host, jobs, kube, load, newline, perlbrew, perms, root, shell-var, ssh, termtitle, terraform-workspace, time, node, user, venv, vgo, nix-shell) - (default "nix-shell,venv,user,host,ssh,cwd,perms,git,hg,jobs,exit,root,vgo") + (valid choices: aws, cwd, docker, dotenv, duration, exit, git, gitlite, hg, host, jobs, kube, load, newline, nix-shell, node, perlbrew, perms, root, shell-var, ssh, svn, termtitle, terraform-workspace, time, user, venv, vgo) + (default "nix-shell,venv,user,host,ssh,cwd,perms,git,hg,jobs,exit,root,vgo") -modules-right string The list of modules to load anchored to the right, for shells that support it, separated by ',' - (valid choices: aws, cwd, docker, dotenv, duration, exit, git, gitlite, hg, host, jobs, kube, load, newline, perlbrew, perms, root, shell-var, ssh, termtitle, terraform-workspace, time, node, user, venv, vgo, nix-shell) + (valid choices: aws, cwd, docker, dotenv, duration, exit, git, gitlite, hg, host, jobs, kube, load, newline, nix-shell, node, perlbrew, perms, root, shell-var, ssh, svn, termtitle, terraform-workspace, time, user, venv, vgo) -newline Show the prompt on a new line -numeric-exit-codes Shows numeric exit codes for errors. -path-aliases string One or more aliases from a path to a short name. Separate with ','. - An alias maps a path like foo/bar/baz to a short name like FBB. - Specify these as key/value pairs like foo/bar/baz=FBB. - Use '~' for your home dir. You may need to escape this character to avoid shell substitution. + An alias maps a path like foo/bar/baz to a short name like FBB. + Specify these as key/value pairs like foo/bar/baz=FBB. + 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, docker, dotenv, duration, exit, git, gitlite, hg, host, jobs, kube, load, newline, perlbrew, perms, root, shell-var, ssh, termtitle, terraform-workspace, time, node, user, venv, vgo, nix-shell) - (default "root,cwd,user,host,ssh,perms,git-branch,git-status,hg,jobs,exit,cwd-path") + (valid choices: aws, cwd, docker, dotenv, duration, exit, git, gitlite, hg, host, jobs, kube, load, newline, nix-shell, node, perlbrew, perms, root, shell-var, ssh, svn, termtitle, terraform-workspace, time, user, venv, vgo) + (default "root,cwd,user,host,ssh,perms,git-branch,git-status,hg,jobs,exit,cwd-path") -shell string Set this to your shell type - (valid choices: bare, bash, zsh) - (default "bash") + (valid choices: bare, bash, zsh) + (default "bash") -shell-var string A shell variable to add to the segments. -shorten-gke-names Shortens names for GKE Kube clusters. -theme string Set this to the theme you want to use - (valid choices: default, low-contrast) - (default "default") + (valid choices: default, low-contrast) + (default "default") -truncate-segment-width int Minimum width of a segment, segments longer than this will be shortened if space is limited. Setting this to 0 disables it. - (default 16) + (default 16) ``` ### Path Aliases diff --git a/main.go b/main.go index 3860812c..a671e07e 100644 --- a/main.go +++ b/main.go @@ -8,7 +8,7 @@ import ( "os" "strings" - runewidth "github.com/mattn/go-runewidth" + "github.com/mattn/go-runewidth" ) type alignment int @@ -16,7 +16,7 @@ type alignment int const ( MinUnsignedInteger uint = 0 MaxUnsignedInteger = ^MinUnsignedInteger - MaxInteger int = int(MaxUnsignedInteger >> 1) + MaxInteger = int(MaxUnsignedInteger >> 1) MinInteger = ^MaxInteger alignLeft alignment = iota @@ -96,7 +96,7 @@ func getValidCwd() string { return cwd } -var modules = map[string](func(*powerline)){ +var modules = map[string]func(*powerline){ "aws": segmentAWS, "cwd": segmentCwd, "docker": segmentDocker, @@ -128,11 +128,11 @@ var modules = map[string](func(*powerline)){ } func comments(lines ...string) string { - return " " + strings.Join(lines, "\n"+" \t ") + return " " + strings.Join(lines, "\n"+" ") } func commentsWithDefaults(lines ...string) string { - return comments(lines...) + "\n" + " \t" + return comments(lines...) + "\n" } func main() { @@ -191,11 +191,11 @@ func main() { "priority", "root,cwd,user,host,ssh,perms,git-branch,git-status,hg,jobs,exit,cwd-path", commentsWithDefaults("Segments sorted by priority, if not enough space exists, the least priorized segments are removed first. Separate with ','", - "(valid choices: aws, cwd, docker, dotenv, duration, exit, git, gitlite, hg, host, jobs, kube, load, newline, perlbrew, perms, root, shell-var, ssh, termtitle, terraform-workspace, time, node, user, venv, vgo, nix-shell)")), + "(valid choices: aws, cwd, docker, dotenv, duration, exit, git, gitlite, hg, host, jobs, kube, load, newline, nix-shell, node, perlbrew, perms, root, shell-var, ssh, svn, termtitle, terraform-workspace, time, user, venv, vgo)")), MaxWidthPercentage: flag.Int( "max-width", 0, - commentsWithDefaults("Maximum width of the shell that the prompt may use, in percent. Setting this to 0 disables the shrinking subsystem.")), + comments("Maximum width of the shell that the prompt may use, in percent. Setting this to 0 disables the shrinking subsystem.")), TruncateSegmentWidth: flag.Int( "truncate-segment-width", 16, @@ -243,10 +243,14 @@ func main() { file, err := ioutil.ReadFile(*args.Theme) if err == nil { - json.Unmarshal(file, &jsonTheme) + err = json.Unmarshal(file, &jsonTheme) + if err == nil { + themes[*args.Theme] = jsonTheme + } else { + println("Error reading theme") + println(err.Error()) + } } - - themes[*args.Theme] = jsonTheme } priorities := map[string]int{} priorityList := strings.Split(*args.Priority, ",") @@ -256,7 +260,7 @@ func main() { p := newPowerline(args, getValidCwd(), priorities, alignLeft) if p.supportsRightModules() && p.hasRightModules() && !*args.Eval { - fmt.Fprint(os.Stderr, "Flag '-modules-right' requires '-eval' mode.") + fmt.Fprintln(os.Stderr, "Flag '-modules-right' requires '-eval' mode.") os.Exit(1) } diff --git a/aws.go b/segment-aws.go similarity index 100% rename from aws.go rename to segment-aws.go diff --git a/segment-cwd.go b/segment-cwd.go index b79568c3..96dcf0dd 100644 --- a/segment-cwd.go +++ b/segment-cwd.go @@ -57,7 +57,7 @@ Aliases: Segments: // We want to see if that array of strings exists in pathSegments. - for i, _ := range pathSegments { + for i := range pathSegments { // This is the upper index that we would look at. So if i is 0, // then we'd look at pathSegments[0,1,2], then [1,2,3], etc.. If i // is 2, we'd look at pathSegments[2,3,4] and so on. @@ -72,7 +72,7 @@ Aliases: // Then we loop over the indices in path and compare the // elements. If any element doesn't match we can move on to the // next index in pathSegments. - for j, _ := range path { + for j := range path { if path[j] != pathSegments[i+j].path { continue Segments } @@ -97,14 +97,6 @@ Aliases: return pathSegments } -func toString(ps []pathSegment) string { - b := make([]string, 0) - for _, s := range ps { - b = append(b, s.path) - } - return strings.Join(b, " > ") -} - func cwdToPathSegments(p *powerline, cwd string) []pathSegment { pathSegments := make([]pathSegment, 0) diff --git a/segment-nix-shell.go b/segment-nix-shell.go index 858cf506..2d2ea14e 100644 --- a/segment-nix-shell.go +++ b/segment-nix-shell.go @@ -6,7 +6,7 @@ import ( func segmentNixShell(p *powerline) { var nixShell string - nixShell, _ = os.LookupEnv("IN_NIX_SHELL") + nixShell, _ = os.LookupEnv("IN_NIX_SHELL") if nixShell == "" { return } else { diff --git a/segment-node.go b/segment-node.go index c8575c93..da2a0b6a 100644 --- a/segment-node.go +++ b/segment-node.go @@ -18,12 +18,14 @@ func segmentNode(p *powerline) { pkg := packageJSON{"!"} raw, err := ioutil.ReadFile(pkgfile) if err == nil { - json.Unmarshal(raw, &pkg) + err = json.Unmarshal(raw, &pkg) + if err == nil { + p.appendSegment("node-version", segment{ + content: pkg.Version + " \u2B22", + foreground: p.theme.NodeFg, + background: p.theme.NodeBg, + }) + } } - p.appendSegment("node-version", segment{ - content: pkg.Version + " \u2B22", - foreground: p.theme.NodeFg, - background: p.theme.NodeBg, - }) } } diff --git a/themes/default.json b/themes/default.json index 02ee6938..17215737 100644 --- a/themes/default.json +++ b/themes/default.json @@ -59,7 +59,7 @@ "LoadFg": 15, "LoadBg": 22, "LoadHighBg": 161, - "LoadAvgValue": 5, + "LoadAvgValue": 5, "LoadThresholdBad": 1.0, "NixShellFg": 0, "NixShellBg": 69,