Skip to content

Conversation

@Blacksmoke16
Copy link
Member

@Blacksmoke16 Blacksmoke16 commented Jul 23, 2023

Implements command tab completion by leveraging the shell's built in completion features. Currently only bash is supported, but fish and zsh can/will be added in another PR. Command and option names are supported out of the box. Option/argument values can be defined by using the new suggested_values option when adding arguments/options which accepts either an Enumerable(String) or a block that should return an Array(String) if additional filtering is desired. The #complete method may also be overridden for more complex usages.

This functionality does require sourcing/placing a generated file in a location where you shell is able to read it. E.g. sourced within ~/.bashrc or placed within /etc/bash_completion.d/. This is a one-time setup, so not too big of a deal.

This can be done via the completion command that is bundled in with all console applications. E.g. ./console completion > completion.sh. Run ./console help completion formore information.

The name of the binary used to generate the script is important. In this case, completion.sh would handle auto completion for a binary called console, but not one called something else.

The completion script also is required to run with real binaries, not via like crystal run src/console.cr -- completion.

  • Support tab completion
  • Add helper assert_command_is_successful to the *Tester types

Resolves #293

@Blacksmoke16 Blacksmoke16 added component:console kind:feature Brand new functionality labels Jul 23, 2023
@Blacksmoke16 Blacksmoke16 merged commit a3788e8 into master Jul 25, 2023
@Blacksmoke16 Blacksmoke16 deleted the console-autocompletion branch July 25, 2023 03:42
@paulocoghi
Copy link

Wow! Incredible!

@Blacksmoke16
Copy link
Member Author

@paulocoghi Is still some work to do (mainly adding the other shells and augmenting existing commands), but feel free to try it out and let me know if you have any issues/suggestions.

@paulocoghi
Copy link

I will try it and let you know!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component:console kind:feature Brand new functionality

Development

Successfully merging this pull request may close these issues.

Tab completion on Athena Console

3 participants