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

Completion support for Nushell #1857

Open
wants to merge 18 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 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
49 changes: 46 additions & 3 deletions completions.go
Original file line number Diff line number Diff line change
Expand Up @@ -798,14 +798,57 @@ to your powershell profile.
return cmd.Root().GenPowerShellCompletion(out)
}
return cmd.Root().GenPowerShellCompletionWithDesc(out)

},
}
if haveNoDescFlag {
powershell.Flags().BoolVar(&noDesc, compCmdNoDescFlagName, compCmdNoDescFlagDefault, compCmdNoDescFlagDesc)
}

completionCmd.AddCommand(bash, zsh, fish, powershell)
nushell := &Command{
Use: "nushell",
Short: fmt.Sprintf(shortDesc, "nushell"),
Long: fmt.Sprintf(`Generate the autocompletion script for nushell.

To configure the Nushell cobra external configurator for the first time:
ayax79 marked this conversation as resolved.
Show resolved Hide resolved

ayax79 marked this conversation as resolved.
Show resolved Hide resolved
# 1. Copy the output of the command below:
> %[1]s completion nushell

# 2. Edit the nushell config file:
> config nu

# 3. Paste above the "let-env config" line.

# 4. Change the config block's external_completer line to be
external_completer: $cobra_completer

# 5. You will need to start a new shell or for this setup to take effect.
ayax79 marked this conversation as resolved.
Show resolved Hide resolved

If you have already setup the cobra external configurator:

# 1. Edit the nushell config file:
> config nu

# 2. Modify the cobra_apps varible to contain this application:
ayax79 marked this conversation as resolved.
Show resolved Hide resolved
> let cobra_apps = [ "othercobraapp", "%[1]s" ]

# 3. You will need to start a new shell or for this setup to take effect.
ayax79 marked this conversation as resolved.
Show resolved Hide resolved

`, c.Root().Name()),
Args: NoArgs,
ValidArgsFunction: NoFileCompletions,
RunE: func(cmd *Command, args []string) error {
if noDesc {
return cmd.Root().GenPowerShellCompletion(out)
ayax79 marked this conversation as resolved.
Show resolved Hide resolved
}
return cmd.Root().GenPowerShellCompletionWithDesc(out)
},
}
if haveNoDescFlag {
nushell.Flags().BoolVar(&noDesc, compCmdNoDescFlagName, compCmdNoDescFlagDefault, compCmdNoDescFlagDesc)
}

completionCmd.AddCommand(bash, zsh, fish, powershell, nushell)
}

func findFlag(cmd *Command, name string) *pflag.Flag {
Expand Down Expand Up @@ -838,7 +881,7 @@ func CompDebug(msg string, printToStdErr bool) {
// variable BASH_COMP_DEBUG_FILE to the path of some file to be used.
if path := os.Getenv("BASH_COMP_DEBUG_FILE"); path != "" {
f, err := os.OpenFile(path,
os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0o644)
ayax79 marked this conversation as resolved.
Show resolved Hide resolved
if err == nil {
defer f.Close()
WriteStringAndCheck(f, msg)
Expand Down
Loading