-
Notifications
You must be signed in to change notification settings - Fork 179
Description
Is your feature request related to a problem? Please describe.
#112 makes it so that tab-completions can work, but there is no way to generate the shell integrations completions script needed to actually trigger them.
Describe the solution you'd like
I would like mods --shell-completions
or mods completions
to run the default Cobra completions command, or an equivalent command, to allow me to tab-complete the various different flags that mods
will accept.
Describe alternatives you've considered
I've cloned the repo and modified the code to make it possible to generate the completions, but I'm not sure if you're open to this as a feature or not, so I haven't sent a PR. Having generated the zsh completions for myself, my problem is solved, but others may want to use them, too.
Additional context
The change needed to enable the completion script is pretty simple, just adding that fake command always (not just when the __MODS_CMP_ENABLED
env var is set):
diff --git a/main.go b/main.go
index 36607e1..7680f3b 100644
--- a/main.go
+++ b/main.go
@@ -64,7 +64,10 @@ func init() {
return newFlagParseError(err)
})
+ rootCmd.AddCommand(&cobra.Command{Use: "____fake_command_to_enable_completions"})
rootCmd.CompletionOptions.HiddenDefaultCmd = true
+ rootCmd.CompletionOptions.DisableDefaultCmd = false
+ rootCmd.InitDefaultCompletionCmd()
rootCmd.SetHelpCommand(&cobra.Command{Hidden: true})
}
Generating the completion file then works like this:
go run . completion zsh > "${fpath[1]}/_mods"
The only impact on current experience is that you cannot submit a query beginning with the word completion
, which is why i think this would be better solved by moving the command to --shell-completion
or something like that.
Here's what typing mods -<tab>
looks like:
~
• mods -
--api -a -- OpenAI compatible REST API (openai, localai).
--ask-model -M -- Ask which model to use with an interactive prompt.
--continue -c -- Continue from the last response or a given save title.
--continue-last -C -- Continue from the last response.
--delete -d -- Deletes a saved conversation with the given title or ID.
--delete-older-than -- Deletes all saved conversations older than the specified duration. Valid units are: ns, us, µs, μs, ms, s, m, h, d, w, mo, and y.
--dirs -- Print the directories in which mods store its data.
--fanciness -- Your desired level of fanciness.
--format -f -- Ask for the response to be formatted as markdown unless otherwise set.
--help -h -- Show help and exit.
--http-proxy -x -- HTTP proxy to use for API requests.
--list -l -- Lists saved conversations.
--list-roles -- List the roles defined in your configuration file
--max-retries -- Maximum number of times to retry API calls.
--max-tokens -- Maximum number of tokens in response.
--model -m -- Default model (gpt-3.5-turbo, gpt-4, ggml-gpt4all-j...).
--no-cache -- Disables caching of the prompt/response.
--no-limit -- Turn off the client-side limit on the size of the input into the model.
--prompt -P -- Include the prompt from the arguments and stdin, truncate stdin to specified number of lines.
--prompt-args -p -- Include the prompt from the arguments in the response.
--quiet -q -- Quiet mode (hide the spinner while loading and stderr messages for success).
--raw -r -- Render output as raw text when connected to a TTY.
--reset-settings -- Backup your old settings file and reset everything to the defaults.
--role -- System role to use.
--settings -- Open settings in your $EDITOR.
--show -s -- Show a saved conversation with the given title or ID.
--show-last -S -- Show the last saved conversation.
--status-text -- Text to show while generating.
--stop -- Up to 4 sequences where the API will stop generating further tokens.
--temp -- Temperature (randomness) of results, from 0.0 to 2.0.
--title -t -- Saves the current conversation with the given title.
--topp -- TopP, an alternative to temperature that narrows response, from 0.0 to 1.0.
--version -v -- Show version and exit.
--word-wrap -- Wrap formatted output at specific width (default is 80)
--format-as
and here's the _mods
completion script (had to add .txt
so that Github would let me upload it):