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

completions should complete plugins + versions #97

Closed
5 tasks done
jdx opened this issue Feb 4, 2023 · 11 comments · Fixed by #1084
Closed
5 tasks done

completions should complete plugins + versions #97

jdx opened this issue Feb 4, 2023 · 11 comments · Fixed by #1084
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@jdx
Copy link
Owner

jdx commented Feb 4, 2023

the completions right now only help complete things like command names and option names.
Ideally you should be able to complete with something like this:

rtx install nodejs@18<tab><tab>
rtx install nodejs@<tab><tab>
rtx install nod<tab><tab>

This probably is non-trivial, but it would certainly be nice.

EDIT: this is working now, but some improvements can be made (I would welcome some help!)

2023-12-07 14 07 07

  • zsh
  • fish
  • zsh+fish rtx uninstall should only show installed versions (perhaps other commands as well)
  • fish's output can be improved, right now rtx install <tab><tab> starts off showing ancient bun versions. (see my comment about this below)
  • rtx settings set <tab><tab>
@jdx jdx added the help wanted Extra attention is needed label Feb 4, 2023
@Stanislav-Lapata
Copy link

Thanks for your great work

I think you can add this lines to fish completions
It adds completion for plugins and versions.

function __fish_rtx_list_all -a plugin
    rtx ls-remote $plugin 2>/dev/null
end

function __fish_rtx_arg_at -a number
    set -l cmd (commandline -opc)
    echo $cmd[$number]
end
set -l plugin_commands current global install latest local ls ls-remote prune uninstall # etc.
complete -c rtx -n "__fish_seen_subcommand_from $plugin_commands" -f -a '(rtx plugins)'
complete -c rtx -n '__fish_seen_subcommand_from (rtx plugins)' -f -a '(__fish_rtx_list_all (__fish_rtx_arg_at 3))'

image
image

It has few bugs but I don't know how I should fix them because I have never written completions
image
image

@jdx
Copy link
Owner Author

jdx commented Jun 1, 2023

looks promising, if I can find some time to have a deeper look I can check more. I like how simple this is for fish!

@jdx
Copy link
Owner Author

jdx commented Dec 5, 2023

ok I got this working for zsh. I'll do it for fish too but not the other shells (these are a massive pain to write)

@fgimian
Copy link

fgimian commented Dec 5, 2023

ok I got this working for zsh. I'll do it for fish too but not the other shells (these are a massive pain to write)

I think Bash is really the most common shell so it would be awesome if that could be supported in time too. 😄

@MrGreenTea
Copy link

ok I got this working for zsh. I'll do it for fish too but not the other shells (these are a massive pain to write)

I think Bash is really the most common shell so it would be awesome if that could be supported in time too. 😄

You are free to open a PR for this and implement it. Maybe @jdx will merge it with a disclaimer that they won't support it 😄

@AlecRust
Copy link
Contributor

AlecRust commented Dec 5, 2023

Zsh is the default on macOS and the most common shell by this point.

https://www.warp.dev/state-of-the-cli-2023#shell-preferences-and-personalizations

@MrGreenTea
Copy link

MrGreenTea commented Dec 5, 2023

Zsh is the default on macOS and the most common shell by this point.

https://www.warp.dev/state-of-the-cli-2023#shell-preferences-and-personalizations

Well that's from a terminal that's only available for MacOS and therefore not representative. I assume most servers will have bash preinstalled for example.

@jdx jdx linked a pull request Dec 6, 2023 that will close this issue
@jdx jdx closed this as completed in #1084 Dec 6, 2023
@jdx jdx unpinned this issue Dec 6, 2023
@Stanislav-Lapata
Copy link

@jdx
command rtx uninstall <plugin>@<tab><tab> returns all versions
I think it should return only installed versions

My shell is fish

@jdx jdx reopened this Dec 7, 2023
@jdx jdx pinned this issue Dec 7, 2023
@jdx
Copy link
Owner Author

jdx commented Dec 8, 2023

fish is a bit ugly unfortunately because I can't figure out how to separate the plugin from the version like with zsh
CleanShot_2023-12-07_at_14 05 472x

I think this can be improved by changing it to be non-alphabetically ordered and showing results without versions first

@Stanislav-Lapata
Copy link

@jdx Thanks for your excellent project
I think cache is unneeded here because after uninstalling I see deleted versions
https://github.com/jdx/rtx/blob/v2023.12.26/src/shell/completions/fish_complete.rs#L41-L43

❯ rtx ls --installed | awk '{print $1 "@" $2}'
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
...

❯ rtx uninstall [email protected]
rtx [email protected] uninstalled

❯ rtx ls --installed | awk '{print $1 "@" $2}'
[email protected]
[email protected]
[email protected]
[email protected]
...

but

❯ rtx uninstall elixir@<tab><tab>[email protected]  (Tool(s) to remove)  
…[email protected]  (Tool(s) to remove)  
…[email protected]  (Tool(s) to remove)  
…[email protected]  (Tool(s) to remove)

Last version is uninstalled

@jdx
Copy link
Owner Author

jdx commented Dec 31, 2023

@Stanislav-Lapata it should show installed versions now.

I'm also working on bash for some unrelated reasons.

@jdx jdx unpinned this issue Jan 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants