Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixes #123, add -pwd option to support cygwin #124

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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