Skip to content

Commit

Permalink
Merge pull request #179 from rsteube/inshellisense-style
Browse files Browse the repository at this point in the history
inshellisense: added style
  • Loading branch information
rsteube committed Jan 25, 2024
2 parents 14b9ccb + 94534a1 commit f979cf9
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions pkg/actions/bridge/inshellisense.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/rsteube/carapace"
shlex "github.com/rsteube/carapace-shlex"
"github.com/rsteube/carapace/pkg/style"
)

// ActionInshellisense bridges https://github.com/microsoft/inshellisense
Expand All @@ -31,6 +32,7 @@ func ActionInshellisense(command ...string) carapace.Action {
Name string
AllNames []string `json:"allNames"`
Description string
Icon string
}
}

Expand All @@ -39,6 +41,8 @@ func ActionInshellisense(command ...string) carapace.Action {
}

vals := make([]string, 0)
flags := make([]string, 0)
files := make([]string, 0)
for _, s := range r.Suggestions {
for _, name := range s.AllNames {
if !strings.HasPrefix(c.Value, "-") && strings.HasPrefix(name, "-") {
Expand All @@ -47,11 +51,22 @@ func ActionInshellisense(command ...string) carapace.Action {

if strings.HasPrefix(name, c.Value) ||
(strings.HasPrefix(c.Value, "-") && strings.Contains(c.Value, "=")) {
vals = append(vals, name, s.Description)
switch s.Icon {
case "📀":
files = append(files, name, s.Description)
case "🔗":
flags = append(flags, name, s.Description)
default:
vals = append(vals, name, s.Description)
}
}
}
}
a := carapace.ActionValuesDescribed(vals...)
a := carapace.Batch(
carapace.ActionValuesDescribed(vals...),
carapace.ActionValuesDescribed(flags...).Tag("flags"),
carapace.ActionValuesDescribed(files...).StyleF(style.ForPathExt).Tag("files"),
).ToA()
if strings.HasPrefix(c.Value, "-") && strings.Contains(c.Value, "=") {
a = a.Prefix(strings.SplitAfterN(c.Value, "=", 2)[0])
}
Expand Down

0 comments on commit f979cf9

Please sign in to comment.