|
| 1 | +# Source this file to activate auto completion for zsh using the bash |
| 2 | +# compatibility helper. Make sure to run `compinit` before, which should be |
| 3 | +# given usually. |
| 4 | +# |
| 5 | +# % source /path/to/zsh_complete.sh |
| 6 | +# |
| 7 | +# Typically that would be called somewhere in your .zshrc. |
| 8 | +# |
| 9 | +# Note, the overwrite of _bash_complete() is to export COMP_LINE and COMP_POINT |
| 10 | +# That is only required for zsh <= edab1d3dbe61da7efe5f1ac0e40444b2ec9b9570 |
| 11 | +# |
| 12 | +# https://github.com/zsh-users/zsh/commit/edab1d3dbe61da7efe5f1ac0e40444b2ec9b9570 |
| 13 | +# |
| 14 | +# zsh releases prior to that version do not export the required env variables! |
| 15 | + |
| 16 | +autoload -Uz bashcompinit |
| 17 | +bashcompinit -i |
| 18 | + |
| 19 | +_bash_complete() { |
| 20 | + local ret=1 |
| 21 | + local -a suf matches |
| 22 | + local -x COMP_POINT COMP_CWORD |
| 23 | + local -a COMP_WORDS COMPREPLY BASH_VERSINFO |
| 24 | + local -x COMP_LINE="$words" |
| 25 | + local -A savejobstates savejobtexts |
| 26 | + |
| 27 | + (( COMP_POINT = 1 + ${#${(j. .)words[1,CURRENT]}} + $#QIPREFIX + $#IPREFIX + $#PREFIX )) |
| 28 | + (( COMP_CWORD = CURRENT - 1)) |
| 29 | + COMP_WORDS=( $words ) |
| 30 | + BASH_VERSINFO=( 2 05b 0 1 release ) |
| 31 | + |
| 32 | + savejobstates=( ${(kv)jobstates} ) |
| 33 | + savejobtexts=( ${(kv)jobtexts} ) |
| 34 | + |
| 35 | + [[ ${argv[${argv[(I)nospace]:-0}-1]} = -o ]] && suf=( -S '' ) |
| 36 | + |
| 37 | + matches=( ${(f)"$(compgen $@ -- ${words[CURRENT]})"} ) |
| 38 | + |
| 39 | + if [[ -n $matches ]]; then |
| 40 | + if [[ ${argv[${argv[(I)filenames]:-0}-1]} = -o ]]; then |
| 41 | + compset -P '*/' && matches=( ${matches##*/} ) |
| 42 | + compset -S '/*' && matches=( ${matches%%/*} ) |
| 43 | + compadd -Q -f "${suf[@]}" -a matches && ret=0 |
| 44 | + else |
| 45 | + compadd -Q "${suf[@]}" -a matches && ret=0 |
| 46 | + fi |
| 47 | + fi |
| 48 | + |
| 49 | + if (( ret )); then |
| 50 | + if [[ ${argv[${argv[(I)default]:-0}-1]} = -o ]]; then |
| 51 | + _default "${suf[@]}" && ret=0 |
| 52 | + elif [[ ${argv[${argv[(I)dirnames]:-0}-1]} = -o ]]; then |
| 53 | + _directories "${suf[@]}" && ret=0 |
| 54 | + fi |
| 55 | + fi |
| 56 | + |
| 57 | + return ret |
| 58 | +} |
| 59 | + |
| 60 | +complete -C aws_completer aws |
0 commit comments