Skip to content

Commit

Permalink
condition: fix path
Browse files Browse the repository at this point in the history
  • Loading branch information
rsteube committed Jan 7, 2024
1 parent 4d496b0 commit 36e595d
Showing 1 changed file with 7 additions and 14 deletions.
21 changes: 7 additions & 14 deletions pkg/condition/condition.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,12 @@ func File(s string) func(c carapace.Context) bool {
}
}

// CompletingPath returns true when Context.Value is assumed a path.
// Either
// - it has a path prefix
// - it contains a filepath delimiter and the first segment is a valid directory
// - it is a valid file or directory
// CompletingPath returns true when `Context.Value` has a path prefix.
func CompletingPath(c carapace.Context) bool {
if util.HasPathPrefix(c.Value) {
return true
}
if s := c.Value; strings.ContainsAny(s, "/\\") {
s = strings.SplitN(s, "/", 2)[0]
s = strings.SplitN(s, "\\", 2)[0]
return File(s)(c)
}
return File(c.Value)(c)
return util.HasPathPrefix(c.Value)
}

// CompletingPathS is like CompletingPathS but also checks path separator `/`
func CompletingPathS(c carapace.Context) bool {
return CompletingPath(c) || strings.Contains(c.Value, "/") // TODO support windows backslash at some point?
}

0 comments on commit 36e595d

Please sign in to comment.