Skip to content

Commit

Permalink
patch args
Browse files Browse the repository at this point in the history
  • Loading branch information
rsteube committed Dec 29, 2024
1 parent 8048164 commit a722be6
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
9 changes: 9 additions & 0 deletions complete.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/carapace-sh/carapace/internal/config"
"github.com/carapace-sh/carapace/internal/shell/bash"
"github.com/carapace-sh/carapace/internal/shell/cmd_clink"
"github.com/carapace-sh/carapace/internal/shell/nushell"
"github.com/carapace-sh/carapace/pkg/ps"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -37,6 +38,14 @@ func complete(cmd *cobra.Command, args []string) (string, error) {
}
return ActionMessage(err.Error()).Invoke(context).value(args[0], args[len(args)-1]), nil
}
case "cmd":
var err error
args, err = cmd_clink.Patch(args)
LOG.Printf("patching args to %#v", args)
if err != nil {
context := NewContext(args...)
return ActionMessage(err.Error()).Invoke(context).value(args[0], args[len(args)-1]), nil
}
}

action, context := traverse(cmd, args[2:])
Expand Down
26 changes: 26 additions & 0 deletions internal/shell/cmd_clink/patch.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package cmd_clink

import (
"os"

shlex "github.com/carapace-sh/carapace-shlex"
)

func Patch(args []string) ([]string, error) {
compline, ok := os.LookupEnv("CARAPACE_COMPLINE")
if !ok {
return args, nil
}
os.Unsetenv("CARAPACE_COMPLINE")

if compline == "" {
return args, nil
}

tokens, err := shlex.Split(compline)
if err != nil {
return nil, err
}
args = append(args[:1], tokens.CurrentPipeline().FilterRedirects().Words().Strings()...)
return args, nil
}
2 changes: 2 additions & 0 deletions pkg/ps/ps.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ func DetermineShell() string {
return "bash-ble"
}
return "bash"
case "cmd":
return "cmd"
case "elvish":
return "elvish"
case "fish":
Expand Down

0 comments on commit a722be6

Please sign in to comment.