Skip to content

Add completions subcommand#1240

Merged
haixuanTao merged 2 commits intodora-rs:mainfrom
drindr:cli-autocompletion
Nov 30, 2025
Merged

Add completions subcommand#1240
haixuanTao merged 2 commits intodora-rs:mainfrom
drindr:cli-autocompletion

Conversation

@drindr
Copy link
Copy Markdown
Contributor

@drindr drindr commented Nov 25, 2025

With this command, it can generate auto-completion script for specific shell, like bash and fish.

Use eval "$(dora completions <SHELL>)" to apply the autocompletion script.

This PR is proposed in #1228.

With this command, it can generate auto-completion
script for specific shell, like bash and fish.

Use `eval "$(dora completions <SHELL>)"` to apply
the autocompletion script

Signed-off-by: drindr <dreamchancn@qq.com>
@drindr drindr force-pushed the cli-autocompletion branch from 86e9257 to d3c4da9 Compare November 25, 2025 10:54
@haixuanTao
Copy link
Copy Markdown
Collaborator

That's great!

Could you write down the process to persist those bash modifications within a readme or within the helper of this function?

Would it also be possible to auto-detect which shell is currently used like https://stackoverflow.com/questions/9910966/how-to-get-shell-to-self-detect-using-zsh-or-bash to remove the requirement to manually input it?

@drindr drindr force-pushed the cli-autocompletion branch 2 times, most recently from 2869181 to 4c8cbc3 Compare November 26, 2025 14:40
@drindr
Copy link
Copy Markdown
Contributor Author

drindr commented Nov 26, 2025

I have added more help information which can be seen with dora completions --help
And it will try to autodetect the shell type if the shell type is not given manually now.

@haixuanTao
Copy link
Copy Markdown
Collaborator

I don't think the helper work:

(base) ~/D/w/d/e/rust-dataflow ❯❯❯     echo "eval \$(dora completions bash)" >> .bashrc                                                                              (base)  ✘ 130 cli-autocompletion ✭ ◼
zsh: no such file or directory: .bashrc

Also, you didn't mention about auto detection of shell.

Could you also remove the s of completions as there is at most one auto-completion.

@drindr
Copy link
Copy Markdown
Contributor Author

drindr commented Nov 27, 2025

I don't think the helper work:

(base) ~/D/w/d/e/rust-dataflow ❯❯❯     echo "eval \$(dora completions bash)" >> .bashrc                                                                              (base)  ✘ 130 cli-autocompletion ✭ ◼
zsh: no such file or directory: .bashrc

Also, you didn't mention about auto detection of shell.

Sry, it is my fault.
For Zsh, I think it should be echo 'eval "$(dora completion)"' >> ~/.zshrc
The SHELL parameter is wrapped by [ and ] in the help info, which means it is optional.
When the shell is not given, it will try to figure out which shell you are using.

Do you mean write down all the available shell as example in the help info?
Or even implement the config writing process with pipe into the completion command itself automatically?

Could you also remove the s of completions as there is at most one auto-completion.

Fine.

@drindr drindr force-pushed the cli-autocompletion branch from 4c8cbc3 to 583c877 Compare November 27, 2025 06:42
@drindr
Copy link
Copy Markdown
Contributor Author

drindr commented Nov 27, 2025

Updated.

Signed-off-by: drindr <dreamchancn@qq.com>
@drindr drindr force-pushed the cli-autocompletion branch from 583c877 to 51ef62d Compare November 27, 2025 11:18
@drindr
Copy link
Copy Markdown
Contributor Author

drindr commented Nov 28, 2025

Tested on bash, fish and zsh, and the help info has updated as below:

Usage: dora completion [SHELL]

Arguments:
  [SHELL]  The shell to generate the script for [possible values: bash, elvish, fish, powershell, zsh]

Options:
  -h, --help  Print help


USAGE:
  eval $(dora completion)              # Auto-detect shell
  eval $(dora completion <SHELL>)      # Specify shell explicitly

PERSIST COMPLETION:

  Bash:
    echo 'eval "$(dora completion bash)"' >> ~/.bashrc
    # Then restart shell

  Zsh:
    echo 'eval "$(dora completion zsh)"' >> ~/.zshrc
    # Then restart shell

    # If you get 'command not found: compdef', add this before the eval line:
    autoload -Uz compinit
    compinit

  Fish:
    # Add to ~/.config/fish/config.fish
    if status is-interactive
        eval "$(dora completion fish)"
    end
    # Then restart shell

@haixuanTao
Copy link
Copy Markdown
Collaborator

Great! Thanks!

@haixuanTao haixuanTao merged commit 2143f93 into dora-rs:main Nov 30, 2025
50 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants