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.bash | |
parent | b0da035e9ecabfa13438386a6ce87072b7cc3c98 (diff) | |
download | alacritty-c89939b5d14e581e1aeaa940d81843192e0abc79.tar.gz alacritty-c89939b5d14e581e1aeaa940d81843192e0abc79.zip |
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.bash')
-rw-r--r-- | extra/completions/alacritty.bash | 201 |
1 files changed, 154 insertions, 47 deletions
diff --git a/extra/completions/alacritty.bash b/extra/completions/alacritty.bash index 464afe6e..0a9b286e 100644 --- a/extra/completions/alacritty.bash +++ b/extra/completions/alacritty.bash @@ -1,55 +1,162 @@ -#/usr/bin/env bash - -# Load completion function -complete -F _alacritty alacritty - -# Completion function -_alacritty() -{ - local cur prev prevprev opts +_alacritty() { + local i cur prev opts cmds COMPREPLY=() cur="${COMP_WORDS[COMP_CWORD]}" prev="${COMP_WORDS[COMP_CWORD-1]}" - prevprev="${COMP_WORDS[COMP_CWORD-2]}" - opts="-h --help -V --version --print-events -q -qq -v -vv -vvv --ref-test --hold -e --command --config-file -o --option -t --title --embed --class --working-directory --socket msg" + cmd="" + opts="" - # If `--command` or `-e` is used, stop completing - for i in "${!COMP_WORDS[@]}"; do - if [[ "${COMP_WORDS[i]}" == "--command" ]] \ - || [[ "${COMP_WORDS[i]}" == "-e" ]] \ - && [[ "${#COMP_WORDS[@]}" -gt "$(($i + 2))" ]] - then - return 0 - fi + for i in ${COMP_WORDS[@]} + do + case "${i}" in + alacritty) + cmd="alacritty" + ;; + + create-window) + cmd+="__create__window" + ;; + help) + cmd+="__help" + ;; + msg) + cmd+="__msg" + ;; + *) + ;; + esac done - # Match the previous word - case "${prev}" in - --command | -e) - # Complete all commands in $PATH - COMPREPLY=( $(compgen -c -- "${cur}") ) - return 0;; - --config-file | --socket) - # File completion - local IFS=$'\n' - compopt -o filenames - COMPREPLY=( $(compgen -f -- "${cur}") ) - return 0;; - --class | --title | -t) - # Don't complete here - return 0;; - --working-directory) - # Directory completion - local IFS=$'\n' - compopt -o filenames - COMPREPLY=( $(compgen -d -- "${cur}") ) - return 0;; - msg) - COMPREPLY=( $(compgen -W "-h --help -V --version -s --socket" -- "${cur}") ) - return 0;; + case "${cmd}" in + alacritty) + opts=" -q -v -h -V -t -e -o --print-events --ref-test --hold --help --version --title --class --embed --working-directory --config-file --socket --command --option msg help" + if [[ ${cur} == -* || ${COMP_CWORD} -eq 1 ]] ; then + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + fi + case "${prev}" in + + --title) + COMPREPLY=($(compgen -f "${cur}")) + return 0 + ;; + -t) + COMPREPLY=($(compgen -f "${cur}")) + return 0 + ;; + --class) + COMPREPLY=($(compgen -f "${cur}")) + return 0 + ;; + --embed) + COMPREPLY=($(compgen -f "${cur}")) + return 0 + ;; + --working-directory) + COMPREPLY=($(compgen -f "${cur}")) + return 0 + ;; + --config-file) + COMPREPLY=($(compgen -f "${cur}")) + return 0 + ;; + --socket) + COMPREPLY=($(compgen -f "${cur}")) + return 0 + ;; + --command) + COMPREPLY=($(compgen -f "${cur}")) + return 0 + ;; + -e) + COMPREPLY=($(compgen -f "${cur}")) + return 0 + ;; + --option) + COMPREPLY=($(compgen -f "${cur}")) + return 0 + ;; + -o) + COMPREPLY=($(compgen -f "${cur}")) + return 0 + ;; + *) + COMPREPLY=() + ;; + esac + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + ;; + + alacritty__help) + opts=" -h -V --help --version " + if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + fi + case "${prev}" in + + *) + COMPREPLY=() + ;; + esac + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + ;; + alacritty__msg) + opts=" -h -V -s --help --version --socket create-window help" + if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + fi + case "${prev}" in + + --socket) + COMPREPLY=($(compgen -f "${cur}")) + return 0 + ;; + -s) + COMPREPLY=($(compgen -f "${cur}")) + return 0 + ;; + *) + COMPREPLY=() + ;; + esac + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + ;; + alacritty__msg__create__window) + opts=" -h -V --help --version " + if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + fi + case "${prev}" in + + *) + COMPREPLY=() + ;; + esac + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + ;; + alacritty__msg__help) + opts=" -h -V --help --version " + if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + fi + case "${prev}" in + + *) + COMPREPLY=() + ;; + esac + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + ;; esac - - # Show all flags if there was no previous word - COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) - return 0 } + +complete -F _alacritty -o bashdefault -o default alacritty |