Skip to content

Commit

Permalink
Cleanup code, fix help, improve readme
Browse files Browse the repository at this point in the history
  • Loading branch information
justjanne committed Jan 27, 2019
1 parent 62757e5 commit d72109a
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 52 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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

2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ sudo: false
language: go

go:
- 1.9
- 1.10
before_script:
- go get

Expand Down
41 changes: 20 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
26 changes: 15 additions & 11 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ import (
"os"
"strings"

runewidth "github.com/mattn/go-runewidth"
"github.com/mattn/go-runewidth"
)

type alignment int

const (
MinUnsignedInteger uint = 0
MaxUnsignedInteger = ^MinUnsignedInteger
MaxInteger int = int(MaxUnsignedInteger >> 1)
MaxInteger = int(MaxUnsignedInteger >> 1)
MinInteger = ^MaxInteger

alignLeft alignment = iota
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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, ",")
Expand All @@ -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)
}

Expand Down
File renamed without changes.
12 changes: 2 additions & 10 deletions segment-cwd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
}
Expand All @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion segment-nix-shell.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
14 changes: 8 additions & 6 deletions segment-node.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})
}
}
2 changes: 1 addition & 1 deletion themes/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
"LoadFg": 15,
"LoadBg": 22,
"LoadHighBg": 161,
"LoadAvgValue": 5,
"LoadAvgValue": 5,
"LoadThresholdBad": 1.0,
"NixShellFg": 0,
"NixShellBg": 69,
Expand Down

0 comments on commit d72109a

Please sign in to comment.