1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
|
# shellcheck shell=bash
_eza() {
cur=${COMP_WORDS[COMP_CWORD]}
prev=${COMP_WORDS[COMP_CWORD-1]}
case "$prev" in
--help|-v|--version|--smart-group)
return
;;
--colour)
mapfile -t COMPREPLY < <(compgen -W 'always automatic auto never' -- "$cur")
return
;;
--icons)
mapfile -t COMPREPLY < <(compgen -W 'always automatic auto never' -- "$cur")
return
;;
-L|--level)
mapfile -t COMPREPLY < <(compgen -W '{0..9}' -- "$cur")
return
;;
-s|--sort)
mapfile -t COMPREPLY < <(compgen -W 'name filename Name Filename size filesize extension Extension date time modified changed accessed created type inode oldest newest age none --' -- "$cur")
return
;;
-t|--time)
mapfile -t COMPREPLY < <(compgen -W 'modified changed accessed created --' -- "$cur")
return
;;
--time-style)
mapfile -t COMPREPLY < <(compgen -W 'default iso long-iso full-iso relative +FORMAT --' -- "$cur")
return
;;
--color-scale)
mapfile -t COMPREPLY < <(compgen -W 'all age size --' -- "$cur")
return
;;
--color-scale-mode)
mapfile -t COMPREPLY < <(compgen -W 'fixed gradient --' -- "$cur")
return
;;
--absolute)
mapfile -t COMPREPLY < <(compgen -W 'on follow off --' -- "$cur")
return
;;
esac
case "$cur" in
# _parse_help doesn’t pick up short options when they are on the same line than long options
--*)
# colo[u]r isn’t parsed correctly so we filter these options out and add them by hand
parse_help=$(eza --help | grep -oE ' (--[[:alnum:]@-]+)' | tr -d ' ' | grep -v '\--colo' | grep -v '\--list-dirs')
completions=$(echo '--color --colour --color-scale --colour-scale --color-scale-mode --colour-scale-mode' "$parse_help")
mapfile -t COMPREPLY < <(compgen -W "$completions" -- "$cur")
;;
-*)
completions=$(eza --help | grep -oE ' (-[[:alnum:]@])' | tr -d ' ')
mapfile -t COMPREPLY < <(compgen -W "$completions" -- "$cur")
;;
*)
_filedir
;;
esac
} &&
complete -o filenames -o bashdefault -F _eza eza
|