Skip to content

Commit

Permalink
completions: improve completions for ls-remote and uninstall
Browse files Browse the repository at this point in the history
  • Loading branch information
jdx committed Dec 13, 2023
1 parent 11ec133 commit 8eeeab5
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 11 deletions.
23 changes: 19 additions & 4 deletions completions/_rtx
Original file line number Diff line number Diff line change
Expand Up @@ -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:' \
Expand Down Expand Up @@ -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' \
Expand All @@ -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
Expand Down
10 changes: 9 additions & 1 deletion completions/rtx.fish
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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
6 changes: 3 additions & 3 deletions src/cli/uninstall.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ToolArg>,
installed_tool: Vec<ToolArg>,

/// Delete all installed versions
#[clap(long, short)]
Expand All @@ -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)?
Expand Down Expand Up @@ -87,7 +87,7 @@ impl Uninstall {
&self,
config: &Config,
) -> Result<Vec<(Arc<dyn Plugin>, 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| {
Expand Down
9 changes: 9 additions & 0 deletions src/shell/completions/fish_complete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
"#}
Expand Down Expand Up @@ -92,6 +100,7 @@ fn render_completer(a: &Arg) -> Option<String> {
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()),
Expand Down
22 changes: 19 additions & 3 deletions src/shell/completions/zsh_complete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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' \
Expand All @@ -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
Expand Down Expand Up @@ -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(),
Expand Down

0 comments on commit 8eeeab5

Please sign in to comment.