Skip to content

Commit

Permalink
suggest args before flags
Browse files Browse the repository at this point in the history
  • Loading branch information
brianstrauch committed Dec 5, 2023
1 parent df84202 commit 280eef2
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions shell.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,15 +205,22 @@ func parseSuggestions(out string) []prompt.Suggest {
}

sort.Slice(suggestions, func(i, j int) bool {
return suggestions[i].Text < suggestions[j].Text
it := suggestions[i].Text
jt := suggestions[j].Text

if isFlag(it) && isFlag(jt) {
return it < jt
}

return isFlag(jt) || !isFlag(it) || it < jt
})

return suggestions
}

func escapeSpecialCharacters(val string) string {
for _, c := range []string{"\\", "\"", "$", "`", "!"} {
val = strings.ReplaceAll(val, c, "\\"+c)
for _, c := range []string{`\`, `"`, "$", "`", "!"} {
val = strings.ReplaceAll(val, c, `\`+c)
}

if strings.ContainsAny(val, " #&*;<>?[]|~") {
Expand Down

0 comments on commit 280eef2

Please sign in to comment.