diff --git a/README.md b/README.md index 0e4e9297..0ee150bf 100644 --- a/README.md +++ b/README.md @@ -142,6 +142,9 @@ Usage of powerline-go: Use East Asian Ambiguous Widths -error int Exit code of previously executed command + -max-width int + Maximum width of the shell that the prompt may use, in percent. + (default 50) -mode string The characters used to make separators between segments. (valid choices: patched, compatible, flat) @@ -152,6 +155,10 @@ Usage of powerline-go: (default "venv,user,host,ssh,cwd,perms,git,hg,jobs,exit,root") -newline Show the prompt on a new line + -priority string + Segments sorted by priority, if not enough space exists, the least priorized segments are removed first. Separate with ',' + (valid choices: cwd, docker, exit, git-branch, git-status, hg, host, jobs, perms, root, ssh, time, user, venv) + (default "root,cwd,user,host,ssh,perms,git-branch,git-status,hg,jobs,exit") -shell string Set this to your shell type (valid choices: bare, bash, zsh) diff --git a/main.go b/main.go index b57f1929..133cf610 100644 --- a/main.go +++ b/main.go @@ -17,18 +17,19 @@ type segment struct { } type args struct { - CwdMode *string - CwdMaxDepth *int - CwdMaxDirSize *int - ColorizeHostname *bool - EastAsianWidth *bool - PromptOnNewLine *bool - Mode *string - Theme *string - Shell *string - Modules *string - Priority *string - PrevError *int + CwdMode *string + CwdMaxDepth *int + CwdMaxDirSize *int + ColorizeHostname *bool + EastAsianWidth *bool + PromptOnNewLine *bool + Mode *string + Theme *string + Shell *string + Modules *string + Priority *string + MaxWidthPercentage *int + PrevError *int } func warn(msg string) { @@ -119,6 +120,10 @@ func main() { "Segments sorted by priority, if not enough space exists, the least priorized segments are removed first. Separate with ','\n"+ " (valid choices: cwd, docker, exit, git-branch, git-status, hg, host, jobs, perms, root, ssh, time, user, venv)\n"+ " "), + MaxWidthPercentage: flag.Int("max-width", + 50, + "Maximum width of the shell that the prompt may use, in percent.\n"+ + " "), PrevError: flag.Int("error", 0, "Exit code of previously executed command"), } diff --git a/powerline.go b/powerline.go index 5f56f660..e3ed2e22 100644 --- a/powerline.go +++ b/powerline.go @@ -74,6 +74,8 @@ func (p *powerline) draw() string { shellMaxLength64, _ := strconv.ParseInt(shellMaxLengthStr, 0, 64) shellMaxLength := int(shellMaxLength64) + shellMaxLength = shellMaxLength * *p.args.MaxWidthPercentage / 100 + shellActualLength := 0 if shellMaxLength > 0 { for _, segment := range p.Segments {