From 8eeeab50faefe7a590a69feb0205d234e3dedec4 Mon Sep 17 00:00:00 2001 From: Jeff Dickey <216188+jdx@users.noreply.github.com> Date: Wed, 13 Dec 2023 15:34:30 -0600 Subject: [PATCH] completions: improve completions for ls-remote and uninstall --- completions/_rtx | 23 +++++++++++++++++++---- completions/rtx.fish | 10 +++++++++- src/cli/uninstall.rs | 6 +++--- src/shell/completions/fish_complete.rs | 9 +++++++++ src/shell/completions/zsh_complete.rs | 22 +++++++++++++++++++--- 5 files changed, 59 insertions(+), 11 deletions(-) diff --git a/completions/_rtx b/completions/_rtx index 9cddd3dd38..0b79f829f4 100644 --- a/completions/_rtx +++ b/completions/_rtx @@ -709,7 +709,7 @@ __rtx_trust_cmd() { (( $+functions[__rtx_uninstall_cmd] )) || __rtx_uninstall_cmd() { _arguments -s -S \ - '*::tool:__rtx_tool_versions' \ + '*::installed_tool:__rtx_installed_tool_versions' \ '(-a --all)'{-a,--all}'[Delete all installed versions]' \ '(-n --dry-run)'{-n,--dry-run}'[Do not actually delete anything]' \ '(-j --jobs)'{-j,--jobs}'=[Number of plugins and runtimes to install in parallel]:jobs:' \ @@ -876,7 +876,20 @@ __rtx_tool_versions() { if compset -P '*@'; then local -a tool_versions; tool_versions=($(rtx ls-remote ${words[CURRENT]})) _wanted tool_version expl 'version of tool' \ - compadd -a tool_versions + compadd -a tool_versions -o nosort + else + local -a plugins; plugins=($(rtx plugins --core --user)) + _wanted plugin expl 'plugin name' \ + compadd -S '@' -a plugins + fi +} +(( $+functions[__rtx_installed_tool_versions] )) || +__rtx_installed_tool_versions() { + if compset -P '*@'; then + local plugin; plugin=${words[CURRENT]%%@*} + local -a installed_tool_versions; installed_tool_versions=($(rtx ls --installed $plugin | awk '{print $2}')) + _wanted installed_tool_version expl 'version of tool' \ + compadd -a installed_tool_versions -o nosort else local -a plugins; plugins=($(rtx plugins --core --user)) _wanted plugin expl 'plugin name' \ @@ -900,8 +913,10 @@ __rtx_aliases() { } (( $+functions[__rtx_prefixes] )) || __rtx_prefixes() { - local -a prefixes; prefixes=($(rtx ls-remote ${words[CURRENT-1]})) - _describe -t prefixes 'prefix' prefixes "$@" + if [[ CURRENT -gt 2 ]]; then + local -a prefixes; prefixes=($(rtx ls-remote ${words[CURRENT-1]})) + _describe -t prefixes 'prefix' prefixes "$@" + fi } if [ "$funcstack[1]" = "_rtx" ]; then diff --git a/completions/rtx.fish b/completions/rtx.fish index a840a74e96..e8edcaf0c6 100644 --- a/completions/rtx.fish +++ b/completions/rtx.fish @@ -249,7 +249,7 @@ complete -xc rtx -n "$fssf trust" -l untrust -d 'No longer trust this config' # uninstall complete -xc rtx -n "$fssf uninstall" -s a -l all -d 'Delete all installed versions' complete -xc rtx -n "$fssf uninstall" -s n -l dry-run -d 'Do not actually delete anything' -complete -xc rtx -n "$fssf uninstall" -a "(__rtx_tool_versions)" -d 'Tool(s) to remove' +complete -xc rtx -n "$fssf uninstall" -a "(__rtx_installed_tool_versions)" -d 'Tool(s) to remove' # upgrade complete -xc rtx -n "$fssf upgrade" -s n -l dry-run -d 'Just print what would be done, don'\''t actually do it' @@ -301,5 +301,13 @@ function __rtx_tool_versions echo $tv end end +function __rtx_installed_tool_versions + if test -z "$__rtx_installed_tool_versions_cache" + set -g __rtx_installed_tool_versions_cache (rtx ls --installed | awk '{print $1 "@" $2}') + end + for tv in $__rtx_installed_tool_versions_cache + echo $tv + end +end # vim: noet ci pi sts=0 sw=4 ts=4 diff --git a/src/cli/uninstall.rs b/src/cli/uninstall.rs index f4861fca59..b23ce6ff7e 100644 --- a/src/cli/uninstall.rs +++ b/src/cli/uninstall.rs @@ -18,7 +18,7 @@ use crate::{runtime_symlinks, shims}; pub struct Uninstall { /// Tool(s) to remove #[clap(value_name = "TOOL@VERSION", value_parser = ToolArgParser, required_unless_present = "all")] - tool: Vec, + installed_tool: Vec, /// Delete all installed versions #[clap(long, short)] @@ -31,7 +31,7 @@ pub struct Uninstall { impl Uninstall { pub fn run(self, config: Config) -> Result<()> { - let tool_versions = if self.tool.is_empty() && self.all { + let tool_versions = if self.installed_tool.is_empty() && self.all { self.get_all_tool_versions(&config)? } else { self.get_requested_tool_versions(&config)? @@ -87,7 +87,7 @@ impl Uninstall { &self, config: &Config, ) -> Result, ToolVersion)>> { - let runtimes = ToolArg::double_tool_condition(&self.tool); + let runtimes = ToolArg::double_tool_condition(&self.installed_tool); let tool_versions = runtimes .into_par_iter() .map(|a| { diff --git a/src/shell/completions/fish_complete.rs b/src/shell/completions/fish_complete.rs index f9a06f2a80..28cc7c9ff3 100644 --- a/src/shell/completions/fish_complete.rs +++ b/src/shell/completions/fish_complete.rs @@ -37,6 +37,14 @@ function __rtx_tool_versions echo $tv end end +function __rtx_installed_tool_versions + if test -z "$__rtx_installed_tool_versions_cache" + set -g __rtx_installed_tool_versions_cache (rtx ls --installed | awk '{{print $1 "@" $2}}') + end + for tv in $__rtx_installed_tool_versions_cache + echo $tv + end +end # vim: noet ci pi sts=0 sw=4 ts=4 "#} @@ -92,6 +100,7 @@ fn render_completer(a: &Arg) -> Option { ValueHint::AnyPath => Some("(__fish_complete_path)".to_string()), _ => match a.get_id().as_str() { "tool" => Some("(__rtx_tool_versions)".to_string()), + "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()), diff --git a/src/shell/completions/zsh_complete.rs b/src/shell/completions/zsh_complete.rs index 38c0100a05..1ba43cb459 100644 --- a/src/shell/completions/zsh_complete.rs +++ b/src/shell/completions/zsh_complete.rs @@ -25,7 +25,20 @@ pub fn render(cmd: &Command) -> String { if compset -P '*@'; then local -a tool_versions; tool_versions=($(rtx ls-remote ${{words[CURRENT]}})) _wanted tool_version expl 'version of tool' \ - compadd -a tool_versions + compadd -a tool_versions -o nosort + else + local -a plugins; plugins=($(rtx plugins --core --user)) + _wanted plugin expl 'plugin name' \ + compadd -S '@' -a plugins + fi + }} + (( $+functions[__rtx_installed_tool_versions] )) || + __rtx_installed_tool_versions() {{ + if compset -P '*@'; then + local plugin; plugin=${{words[CURRENT]%%@*}} + local -a installed_tool_versions; installed_tool_versions=($(rtx ls --installed $plugin | awk '{{print $2}}')) + _wanted installed_tool_version expl 'version of tool' \ + compadd -a installed_tool_versions -o nosort else local -a plugins; plugins=($(rtx plugins --core --user)) _wanted plugin expl 'plugin name' \ @@ -49,8 +62,10 @@ pub fn render(cmd: &Command) -> String { }} (( $+functions[__rtx_prefixes] )) || __rtx_prefixes() {{ - local -a prefixes; prefixes=($(rtx ls-remote ${{words[CURRENT-1]}})) - _describe -t prefixes 'prefix' prefixes "$@" + if [[ CURRENT -gt 2 ]]; then + local -a prefixes; prefixes=($(rtx ls-remote ${{words[CURRENT-1]}})) + _describe -t prefixes 'prefix' prefixes "$@" + fi }} if [ "$funcstack[1]" = "_rtx" ]; then @@ -209,6 +224,7 @@ fn render_completion(arg: &Arg) -> String { ValueHint::Other => "( )".to_string(), _ => match arg.get_id().as_str() { "tool" => "__rtx_tool_versions".to_string(), + "installed_tool" => "__rtx_installed_tool_versions".to_string(), "plugin" => "__rtx_plugins".to_string(), "new_plugin" => "__rtx_all_plugins".to_string(), "alias" => "__rtx_aliases".to_string(),