diff --git a/README.md b/README.md index 0f997f743..a1fcab8f0 100644 --- a/README.md +++ b/README.md @@ -160,10 +160,10 @@ v20.0.0 - [`rtx prune [OPTIONS] [PLUGIN]...`](#rtx-prune-options-plugin) - [`rtx reshim`](#rtx-reshim) - [`rtx self-update [OPTIONS] [VERSION]`](#rtx-self-update-options-version) - - [`rtx settings get `](#rtx-settings-get-key) + - [`rtx settings get `](#rtx-settings-get-setting) - [`rtx settings ls`](#rtx-settings-ls) - - [`rtx settings set `](#rtx-settings-set-key-value) - - [`rtx settings unset `](#rtx-settings-unset-key) + - [`rtx settings set `](#rtx-settings-set-setting-value) + - [`rtx settings unset `](#rtx-settings-unset-setting) - [`rtx shell [OPTIONS] [TOOL@VERSION]...`](#rtx-shell-options-toolversion) - [`rtx sync node <--brew|--nvm|--nodenv>`](#rtx-sync-node---brew--nvm--nodenv) - [`rtx sync python --pyenv`](#rtx-sync-python---pyenv) @@ -2456,7 +2456,7 @@ Options: Skip confirmation prompt ``` -### `rtx settings get ` +### `rtx settings get ` ```text Show a current setting @@ -2466,10 +2466,10 @@ This is the contents of a single entry in ~/.config/rtx/config.toml Note that aliases are also stored in this file but managed separately with `rtx aliases get` -Usage: settings get +Usage: settings get Arguments: - + The setting to show Examples: @@ -2494,17 +2494,17 @@ Examples: legacy_version_file = false ``` -### `rtx settings set ` +### `rtx settings set ` ```text Add/update a setting This modifies the contents of ~/.config/rtx/config.toml -Usage: settings set +Usage: settings set Arguments: - + The setting to set @@ -2514,17 +2514,17 @@ Examples: $ rtx settings set legacy_version_file true ``` -### `rtx settings unset ` +### `rtx settings unset ` ```text Clears a setting This modifies the contents of ~/.config/rtx/config.toml -Usage: settings unset +Usage: settings unset Arguments: - + The setting to remove Examples: diff --git a/completions/_rtx b/completions/_rtx index 0b79f829f..e10ef3693 100644 --- a/completions/_rtx +++ b/completions/_rtx @@ -602,7 +602,7 @@ return ret (( $+functions[__rtx_settings_get_cmd] )) || __rtx_settings_get_cmd() { _arguments -s -S \ - ':key:' \ + ':setting:__rtx_settings' \ '(-j --jobs)'{-j,--jobs}'=[Number of plugins and runtimes to install in parallel]:jobs:' \ '(-q --quiet)'{-q,--quiet}'[Suppress output]' \ '(-r --raw)'{-r,--raw}'[Directly pipe stdin/stdout/stderr to user.]' \ @@ -621,7 +621,7 @@ __rtx_settings_ls_cmd() { (( $+functions[__rtx_settings_set_cmd] )) || __rtx_settings_set_cmd() { _arguments -s -S \ - ':key:' \ + ':setting:__rtx_settings' \ ':value:' \ '(-j --jobs)'{-j,--jobs}'=[Number of plugins and runtimes to install in parallel]:jobs:' \ '(-q --quiet)'{-q,--quiet}'[Suppress output]' \ @@ -632,7 +632,7 @@ __rtx_settings_set_cmd() { (( $+functions[__rtx_settings_unset_cmd] )) || __rtx_settings_unset_cmd() { _arguments -s -S \ - ':key:' \ + ':setting:__rtx_settings' \ '(-j --jobs)'{-j,--jobs}'=[Number of plugins and runtimes to install in parallel]:jobs:' \ '(-q --quiet)'{-q,--quiet}'[Suppress output]' \ '(-r --raw)'{-r,--raw}'[Directly pipe stdin/stdout/stderr to user.]' \ @@ -911,6 +911,11 @@ __rtx_aliases() { local -a aliases; aliases=($(rtx aliases ls ${words[CURRENT-1]} | awk '{print $2}')) _describe -t aliases 'alias' aliases "$@" } +(( $+functions[__rtx_settings] )) || +__rtx_settings() { + local -a settings; settings=($(rtx settings ls | awk '{print $1}')) + _describe -t settings 'setting' settings "$@" +} (( $+functions[__rtx_prefixes] )) || __rtx_prefixes() { if [[ CURRENT -gt 2 ]]; then diff --git a/completions/rtx.bash b/completions/rtx.bash index 964e1d0d4..94e321304 100644 --- a/completions/rtx.bash +++ b/completions/rtx.bash @@ -3023,7 +3023,7 @@ _rtx() { return 0 ;; rtx__settings__get) - opts="-j -q -r -v -y -h --jobs --debug --log-level --trace --quiet --raw --verbose --yes --help " + opts="-j -q -r -v -y -h --jobs --debug --log-level --trace --quiet --raw --verbose --yes --help " if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) return 0 @@ -3159,7 +3159,7 @@ _rtx() { return 0 ;; rtx__settings__set) - opts="-j -q -r -v -y -h --jobs --debug --log-level --trace --quiet --raw --verbose --yes --help " + opts="-j -q -r -v -y -h --jobs --debug --log-level --trace --quiet --raw --verbose --yes --help " if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) return 0 @@ -3185,7 +3185,7 @@ _rtx() { return 0 ;; rtx__settings__unset) - opts="-j -q -r -v -y -h --jobs --debug --log-level --trace --quiet --raw --verbose --yes --help " + opts="-j -q -r -v -y -h --jobs --debug --log-level --trace --quiet --raw --verbose --yes --help " if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) return 0 diff --git a/completions/rtx.fish b/completions/rtx.fish index f00d50013..bd0221f60 100644 --- a/completions/rtx.fish +++ b/completions/rtx.fish @@ -54,19 +54,19 @@ complete -xc rtx -n "$fssf alias; and not $fssf $others" -a set -d 'Add/update a complete -xc rtx -n "$fssf alias; and not $fssf $others" -a unset -d 'Clears an alias for a plugin' # alias get -complete -kxc rtx -n "$fssf alias; and $fssf get" -d 'The alias to show' +complete -kxc rtx -n "$fssf alias; and $fssf get" -a "(__rtx_aliases)" -d 'The alias to show' complete -kxc rtx -n "$fssf alias; and $fssf get" -a "(__rtx_plugins)" -d 'The plugin to show the alias for' # alias ls complete -kxc rtx -n "$fssf alias; and $fssf ls" -a "(__rtx_plugins)" -d 'Show aliases for ' # alias set -complete -kxc rtx -n "$fssf alias; and $fssf set" -d 'The alias to set' +complete -kxc rtx -n "$fssf alias; and $fssf set" -a "(__rtx_aliases)" -d 'The alias to set' complete -kxc rtx -n "$fssf alias; and $fssf set" -a "(__rtx_plugins)" -d 'The plugin to set the alias for' complete -kxc rtx -n "$fssf alias; and $fssf set" -d 'The value to set the alias to' # alias unset -complete -kxc rtx -n "$fssf alias; and $fssf unset" -d 'The alias to remove' +complete -kxc rtx -n "$fssf alias; and $fssf unset" -a "(__rtx_aliases)" -d 'The alias to remove' complete -kxc rtx -n "$fssf alias; and $fssf unset" -a "(__rtx_plugins)" -d 'The plugin to remove the alias from' @@ -212,16 +212,16 @@ complete -xc rtx -n "$fssf settings; and not $fssf $others" -a set -d 'Add/updat complete -xc rtx -n "$fssf settings; and not $fssf $others" -a unset -d 'Clears a setting' # settings get -complete -kxc rtx -n "$fssf settings; and $fssf get" -d 'The setting to show' +complete -kxc rtx -n "$fssf settings; and $fssf get" -a "(__rtx_settings)" -d 'The setting to show' # settings ls # settings set -complete -kxc rtx -n "$fssf settings; and $fssf set" -d 'The setting to set' +complete -kxc rtx -n "$fssf settings; and $fssf set" -a "(__rtx_settings)" -d 'The setting to set' complete -kxc rtx -n "$fssf settings; and $fssf set" -d 'The value to set' # settings unset -complete -kxc rtx -n "$fssf settings; and $fssf unset" -d 'The setting to remove' +complete -kxc rtx -n "$fssf settings; and $fssf unset" -a "(__rtx_settings)" -d 'The setting to remove' # shell @@ -309,5 +309,21 @@ function __rtx_installed_tool_versions echo $tv end end +function __rtx_aliases + if test -z "$__rtx_aliases_cache" + set -g __rtx_aliases_cache (rtx alias ls | awk '{print $2}') + end + for a in $__rtx_aliases_cache + echo $a + end +end +function __rtx_settings + if test -z "$__rtx_settings_cache" + set -g __rtx_settings_cache (rtx settings ls | awk '{print $1}') + end + for s in $__rtx_settings_cache + echo $s + end +end # vim: noet ci pi sts=0 sw=4 ts=4 diff --git a/src/cli/settings/get.rs b/src/cli/settings/get.rs index 2547c4b73..c28d57c92 100644 --- a/src/cli/settings/get.rs +++ b/src/cli/settings/get.rs @@ -12,14 +12,14 @@ use crate::config::Config; #[clap(after_long_help = AFTER_LONG_HELP, verbatim_doc_comment)] pub struct SettingsGet { /// The setting to show - pub key: String, + pub setting: String, } impl SettingsGet { pub fn run(self, config: Config) -> Result<()> { - match config.settings.to_index_map().get(&self.key) { + match config.settings.to_index_map().get(&self.setting) { Some(value) => Ok(rtxprintln!("{}", value)), - None => Err(eyre!("Unknown setting: {}", self.key)), + None => Err(eyre!("Unknown setting: {}", self.setting)), } } } diff --git a/src/cli/settings/set.rs b/src/cli/settings/set.rs index e78089bc9..160e436a2 100644 --- a/src/cli/settings/set.rs +++ b/src/cli/settings/set.rs @@ -11,14 +11,14 @@ use crate::config::Config; pub struct SettingsSet { /// The setting to set #[clap()] - pub key: String, + pub setting: String, /// The value to set pub value: String, } impl SettingsSet { pub fn run(self, mut config: Config) -> Result<()> { - let value: toml_edit::Value = match self.key.as_str() { + let value: toml_edit::Value = match self.setting.as_str() { "experimental" => parse_bool(&self.value)?, "always_keep_download" => parse_bool(&self.value)?, "always_keep_install" => parse_bool(&self.value)?, @@ -30,10 +30,10 @@ impl SettingsSet { "shorthands_file" => self.value.into(), "disable_default_shorthands" => parse_bool(&self.value)?, "raw" => parse_bool(&self.value)?, - _ => return Err(eyre!("Unknown setting: {}", self.key)), + _ => return Err(eyre!("Unknown setting: {}", self.setting)), }; - config.global_config.update_setting(&self.key, value); + config.global_config.update_setting(&self.setting, value); config.global_config.save() } } diff --git a/src/cli/settings/unset.rs b/src/cli/settings/unset.rs index f71b756ed..d7e609194 100644 --- a/src/cli/settings/unset.rs +++ b/src/cli/settings/unset.rs @@ -10,12 +10,12 @@ use crate::config::Config; #[clap(visible_aliases = ["rm", "remove", "delete", "del"], after_long_help = AFTER_LONG_HELP, verbatim_doc_comment)] pub struct SettingsUnset { /// The setting to remove - pub key: String, + pub setting: String, } impl SettingsUnset { pub fn run(self, mut config: Config) -> Result<()> { - config.global_config.remove_setting(&self.key); + config.global_config.remove_setting(&self.setting); config.global_config.save() } } diff --git a/src/shell/completions/fish_complete.rs b/src/shell/completions/fish_complete.rs index 3de9bf94c..d3681fb69 100644 --- a/src/shell/completions/fish_complete.rs +++ b/src/shell/completions/fish_complete.rs @@ -45,6 +45,22 @@ function __rtx_installed_tool_versions echo $tv end end +function __rtx_aliases + if test -z "$__rtx_aliases_cache" + set -g __rtx_aliases_cache (rtx alias ls | awk '{{print $2}}') + end + for a in $__rtx_aliases_cache + echo $a + end +end +function __rtx_settings + if test -z "$__rtx_settings_cache" + set -g __rtx_settings_cache (rtx settings ls | awk '{{print $1}}') + end + for s in $__rtx_settings_cache + echo $s + end +end # vim: noet ci pi sts=0 sw=4 ts=4 "#} @@ -103,7 +119,8 @@ fn render_completer(a: &Arg) -> Option { "installed_tool" => Some("(__rtx_installed_tool_versions)".to_string()), "plugin" => Some("(__rtx_plugins)".to_string()), "new_plugin" => Some("(__rtx_all_plugins)".to_string()), - //"alias" => Some("(__rtx_aliases)".to_string()), + "alias" => Some("(__rtx_aliases)".to_string()), + "setting" => Some("(__rtx_settings)".to_string()), //"prefix" => Some("(__rtx_prefixes)".to_string()), _ => None, }, diff --git a/src/shell/completions/zsh_complete.rs b/src/shell/completions/zsh_complete.rs index 1ba43cb45..eef6b79a9 100644 --- a/src/shell/completions/zsh_complete.rs +++ b/src/shell/completions/zsh_complete.rs @@ -60,6 +60,11 @@ pub fn render(cmd: &Command) -> String { local -a aliases; aliases=($(rtx aliases ls ${{words[CURRENT-1]}} | awk '{{print $2}}')) _describe -t aliases 'alias' aliases "$@" }} + (( $+functions[__rtx_settings] )) || + __rtx_settings() {{ + local -a settings; settings=($(rtx settings ls | awk '{{print $1}}')) + _describe -t settings 'setting' settings "$@" + }} (( $+functions[__rtx_prefixes] )) || __rtx_prefixes() {{ if [[ CURRENT -gt 2 ]]; then @@ -228,6 +233,7 @@ fn render_completion(arg: &Arg) -> String { "plugin" => "__rtx_plugins".to_string(), "new_plugin" => "__rtx_all_plugins".to_string(), "alias" => "__rtx_aliases".to_string(), + "setting" => "__rtx_settings".to_string(), "prefix" => "__rtx_prefixes".to_string(), _ => String::new(), },