diff options
author | Christian Duerr <contact@christianduerr.com> | 2021-11-19 23:34:40 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-19 23:34:40 +0000 |
commit | c89939b5d14e581e1aeaa940d81843192e0abc79 (patch) | |
tree | 8a78647fbb23b3fde68339ca2a2c9599315c7094 /extra/completions/_alacritty | |
parent | b0da035e9ecabfa13438386a6ce87072b7cc3c98 (diff) |
Switch to clap-generated completions
The current completions required a lot of domain-specific knowledge
about each individual shell and their completion functionality. Much of
which is sparsely documented.
While clap does not generate perfect completions, since parameters like
`-e` are missing completions, it does a reasonable job while requiring
no work on writing these completions.
Since access to `cli.rs` isn't possible from the `build.rs`, these
completions aren't always generated on build. Instead a test verifies
that there has been no changes to these completions and provides a
simple code sample for re-generating them. This should provide a simple
solution with minimal overhead.
Diffstat (limited to 'extra/completions/_alacritty')
-rw-r--r-- | extra/completions/_alacritty | 179 |
1 files changed, 126 insertions, 53 deletions
diff --git a/extra/completions/_alacritty b/extra/completions/_alacritty index 1313128e..32086910 100644 --- a/extra/completions/_alacritty +++ b/extra/completions/_alacritty @@ -1,62 +1,135 @@ #compdef alacritty -# Completions available for the first parameter. -_alacritty_first_param() { - # Main subcommands. - _describe "command" "(msg:'Available socket messages')" +autoload -U is-at-least - # Default options. - _alacritty_main -} - -# Completions available for parameters after the first. -_alacritty_following_param() { - case $words[2] in - msg) - _alacritty_msg;; - *) - _alacritty_main;; - esac -} +_alacritty() { + typeset -A opt_args + typeset -a _arguments_options + local ret=1 -# Completions for the main Alacritty executable. -_alacritty_main() { - # Limit some suggestions to the first option. - local ignore - (( $#words > 2 )) && ignore='!' + if is-at-least 5.2; then + _arguments_options=(-s -S -C) + else + _arguments_options=(-s -C) + fi - _arguments \ - "$ignore(-)"{-h,--help}"[print help information]" \ - "$ignore(-)"{-V,--version}"[print version information]" \ - "--print-events[print all events to stdout]" \ - '(-v)'{-q,-qq}"[reduce the level of verbosity (min is -qq)]" \ - "--ref-test[generate ref test]" \ - "--hold[remain open after child process exits]" \ - '(-q)'{-v,-vv,-vvv}"[increase the level of verbosity (max is -vvv)]" \ - "--class=[define the window class]:class" \ - "--embed=[define the X11 window ID (as a decimal integer) to embed Alacritty within]:windowId" \ - "(-e --command)"{-e,--command}"[execute command (must be last arg)]:program: _command_names -e:*::program arguments: _normal" \ - "--config-file=[specify an alternative config file]:file:_files" \ - "*"{-o=,--option=}"[override config file options]:option" \ - "(-t --title)"{-t=,--title=}"[define the window title]:title" \ - "--working-directory=[start shell in specified directory]:directory:_directories"\ - "--socket=[Path for IPC socket creation]:file:_files" + local context curcontext="$curcontext" state line + _arguments "${_arguments_options[@]}" \ +'-t+[Defines the window title \[default: Alacritty\]]' \ +'--title=[Defines the window title \[default: Alacritty\]]' \ +'--class=[Defines window class/app_id on X11/Wayland \[default: Alacritty\]]' \ +'--embed=[Defines the X11 window ID (as a decimal integer) to embed Alacritty within]' \ +'--working-directory=[Start the shell in the specified working directory]' \ +'--config-file=[Specify alternative configuration file \[default: $XDG_CONFIG_HOME/alacritty/alacritty.yml\]]' \ +'--socket=[Path for IPC socket creation]' \ +'*-e+[Command and args to execute (must be last argument)]' \ +'*--command=[Command and args to execute (must be last argument)]' \ +'*-o+[Override configuration file options \[example: cursor.style=Beam\]]' \ +'*--option=[Override configuration file options \[example: cursor.style=Beam\]]' \ +'--print-events[Print all events to stdout]' \ +'--ref-test[Generates ref test]' \ +'--hold[Remain open after child process exits]' \ +'(-v)*-q[Reduces the level of verbosity (the min level is -qq)]' \ +'(-q)*-v[Increases the level of verbosity (the max level is -vvv)]' \ +'-h[Prints help information]' \ +'--help[Prints help information]' \ +'-V[Prints version information]' \ +'--version[Prints version information]' \ +":: :_alacritty_commands" \ +"*::: :->alacritty" \ +&& ret=0 + case $state in + (alacritty) + words=($line[1] "${words[@]}") + (( CURRENT += 1 )) + curcontext="${curcontext%:*:*}:alacritty-command-$line[1]:" + case $line[1] in + (msg) +_arguments "${_arguments_options[@]}" \ +'-s+[IPC socket connection path override]' \ +'--socket=[IPC socket connection path override]' \ +'-h[Prints help information]' \ +'--help[Prints help information]' \ +'-V[Prints version information]' \ +'--version[Prints version information]' \ +":: :_alacritty__msg_commands" \ +"*::: :->msg" \ +&& ret=0 +case $state in + (msg) + words=($line[1] "${words[@]}") + (( CURRENT += 1 )) + curcontext="${curcontext%:*:*}:alacritty-msg-command-$line[1]:" + case $line[1] in + (create-window) +_arguments "${_arguments_options[@]}" \ +'-h[Prints help information]' \ +'--help[Prints help information]' \ +'-V[Prints version information]' \ +'--version[Prints version information]' \ +&& ret=0 +;; +(help) +_arguments "${_arguments_options[@]}" \ +'-h[Prints help information]' \ +'--help[Prints help information]' \ +'-V[Prints version information]' \ +'--version[Prints version information]' \ +&& ret=0 +;; + esac + ;; +esac +;; +(help) +_arguments "${_arguments_options[@]}" \ +'-h[Prints help information]' \ +'--help[Prints help information]' \ +'-V[Prints version information]' \ +'--version[Prints version information]' \ +&& ret=0 +;; + esac + ;; +esac } -# Completions for the `msg` subcommand. -_alacritty_msg() { - # Limit some suggestions to the first option. - local ignore - (( $#words > 3 )) && ignore='!' - - _arguments \ - "$ignore(-)"{-h,--help}"[print help information]" \ - "$ignore(-)"{-V,--version}"[print version information]" \ - "(-s --socket)"{-s=,--socket=}"[Path for IPC socket creation]:file:_files" \ - "*: :((create-window:'Create a new window in the same Alacritty process'))" +(( $+functions[_alacritty_commands] )) || +_alacritty_commands() { + local commands; commands=( + "msg:Available socket messages" \ +"help:Prints this message or the help of the given subcommand(s)" \ + ) + _describe -t commands 'alacritty commands' commands "$@" +} +(( $+functions[_alacritty__msg__create-window_commands] )) || +_alacritty__msg__create-window_commands() { + local commands; commands=( + + ) + _describe -t commands 'alacritty msg create-window commands' commands "$@" +} +(( $+functions[_alacritty__help_commands] )) || +_alacritty__help_commands() { + local commands; commands=( + + ) + _describe -t commands 'alacritty help commands' commands "$@" +} +(( $+functions[_alacritty__msg__help_commands] )) || +_alacritty__msg__help_commands() { + local commands; commands=( + + ) + _describe -t commands 'alacritty msg help commands' commands "$@" +} +(( $+functions[_alacritty__msg_commands] )) || +_alacritty__msg_commands() { + local commands; commands=( + "create-window:Create a new window in the same Alacritty process" \ +"help:Prints this message or the help of the given subcommand(s)" \ + ) + _describe -t commands 'alacritty msg commands' commands "$@" } -# Handle arguments based on their position. -_arguments \ - "1: :_alacritty_first_param" \ - "*: :_alacritty_following_param" +_alacritty "$@"
\ No newline at end of file |