Skip to content

Commit

Permalink
fixes justjanne#123, add -pwd option to support cygwin
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyle Wolfe committed Mar 14, 2019
1 parent 6c4f49b commit e7b74c6
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ type segment struct {

type args struct {
CwdMode *string
Pwd *string
CwdMaxDepth *int
CwdMaxDirSize *int
ColorizeHostname *bool
Expand Down Expand Up @@ -81,14 +82,7 @@ func pathExists(path string) bool {
}
}

func getValidCwd() string {
cwd, exists := os.LookupEnv("PWD")
if !exists {
warn("Your current directory is invalid.")
print("> ")
os.Exit(1)
}

func getValidCwd(cwd string) string {
parts := strings.Split(cwd, string(os.PathSeparator))
up := cwd

Expand Down Expand Up @@ -142,12 +136,17 @@ func commentsWithDefaults(lines ...string) string {
}

func main() {
pwd, _ := os.LookupEnv("PWD")
args := args{
CwdMode: flag.String(
"cwd-mode",
"fancy",
commentsWithDefaults("How to display the current directory",
"(valid choices: fancy, plain, dironly)")),
Pwd: flag.String(
"pwd",
pwd,
comments("Override $PWD is needed for certain emulated environments such as cygwin")),
CwdMaxDepth: flag.Int(
"cwd-max-depth",
5,
Expand Down Expand Up @@ -272,7 +271,7 @@ func main() {
priorities[priority] = len(priorityList) - idx
}

p := newPowerline(args, getValidCwd(), priorities, alignLeft)
p := newPowerline(args, getValidCwd(*args.Pwd), priorities, alignLeft)
if p.supportsRightModules() && p.hasRightModules() && !*args.Eval {
fmt.Fprintln(os.Stderr, "Flag '-modules-right' requires '-eval' mode.")
os.Exit(1)
Expand Down

0 comments on commit e7b74c6

Please sign in to comment.