2021-06-03 16:57:05 +02:00
|
|
|
# shellcheck disable=SC2207
|
|
|
|
|
2021-06-14 16:26:57 +02:00
|
|
|
# Requires https://github.com/scop/bash-completion
|
|
|
|
|
2022-02-24 07:57:23 +01:00
|
|
|
# Macs have bash3 for which the bash-completion package doesn't include
|
|
|
|
# _init_completion. This is a minimal version of that function.
|
|
|
|
__bat_init_completion()
|
|
|
|
{
|
|
|
|
COMPREPLY=()
|
|
|
|
_get_comp_words_by_ref "$@" cur prev words cword
|
|
|
|
}
|
|
|
|
|
2021-06-03 16:57:05 +02:00
|
|
|
_bat() {
|
2022-02-24 07:57:23 +01:00
|
|
|
local cur prev words cword split=false
|
|
|
|
if declare -F _init_completion >/dev/null 2>&1; then
|
|
|
|
_init_completion -s || return 0
|
|
|
|
else
|
|
|
|
__bat_init_completion -n "=" || return 0
|
|
|
|
_split_longopt && split=true
|
|
|
|
fi
|
2021-06-14 16:26:57 +02:00
|
|
|
|
|
|
|
if [[ ${words[1]-} == cache ]]; then
|
|
|
|
case $prev in
|
2021-06-03 16:57:05 +02:00
|
|
|
--source | --target)
|
2021-06-14 16:26:57 +02:00
|
|
|
_filedir -d
|
2021-06-03 16:57:05 +02:00
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
COMPREPLY=($(compgen -W "
|
|
|
|
--build --clear --source --target --blank --help
|
2021-06-14 16:26:57 +02:00
|
|
|
" -- "$cur"))
|
2021-06-03 16:57:05 +02:00
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
|
2021-06-14 16:26:57 +02:00
|
|
|
case $prev in
|
2021-06-03 16:57:05 +02:00
|
|
|
-l | --language)
|
|
|
|
local IFS=$'\n'
|
|
|
|
COMPREPLY=($(compgen -W "$(
|
|
|
|
"$1" --list-languages | while IFS=: read -r lang _; do
|
|
|
|
printf "%s\n" "$lang"
|
|
|
|
done
|
2021-06-14 16:26:57 +02:00
|
|
|
)" -- "$cur"))
|
2021-06-03 16:57:05 +02:00
|
|
|
compopt -o filenames # for escaping
|
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
-H | --highlight-line | --diff-context | --tabs | --terminal-width | \
|
|
|
|
-m | --map-syntax | --style | --line-range | -h | --help | -V | \
|
2021-07-01 22:10:44 +02:00
|
|
|
--version | --diagnostic | --config-file | --config-dir | \
|
|
|
|
--cache-dir | --generate-config-file)
|
|
|
|
# argument required but no completion available, or option
|
2021-06-03 16:57:05 +02:00
|
|
|
# causes an exit
|
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
--file-name)
|
2021-06-14 16:26:57 +02:00
|
|
|
_filedir
|
2021-06-03 16:57:05 +02:00
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
--wrap)
|
2021-06-14 16:26:57 +02:00
|
|
|
COMPREPLY=($(compgen -W "auto never character" -- "$cur"))
|
2021-06-03 16:57:05 +02:00
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
--color | --decorations | --paging)
|
2021-06-14 16:26:57 +02:00
|
|
|
COMPREPLY=($(compgen -W "auto never always" -- "$cur"))
|
2021-06-03 16:57:05 +02:00
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
--italic-text)
|
2021-06-14 16:26:57 +02:00
|
|
|
COMPREPLY=($(compgen -W "always never" -- "$cur"))
|
2021-06-03 16:57:05 +02:00
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
--pager)
|
2021-06-14 16:26:57 +02:00
|
|
|
COMPREPLY=($(compgen -c -- "$cur"))
|
2021-06-03 16:57:05 +02:00
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
--theme)
|
|
|
|
local IFS=$'\n'
|
2021-06-14 16:26:57 +02:00
|
|
|
COMPREPLY=($(compgen -W "$("$1" --list-themes)" -- "$cur"))
|
2021-06-14 16:20:54 +02:00
|
|
|
compopt -o filenames # for escaping
|
2021-06-03 16:57:05 +02:00
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2021-06-14 16:26:57 +02:00
|
|
|
$split && return 0
|
|
|
|
|
|
|
|
if [[ $cur == -* ]]; then
|
2021-06-03 16:57:05 +02:00
|
|
|
COMPREPLY=($(compgen -W "
|
|
|
|
--show-all --plain --language --highlight-line
|
|
|
|
--file-name --diff --diff-context --tabs --wrap
|
|
|
|
--terminal-width --number --color --italic-text
|
|
|
|
--decorations --paging --pager --map-syntax --theme
|
|
|
|
--list-themes --style --line-range --list-languages
|
2021-07-01 22:10:44 +02:00
|
|
|
--help --version --force-colorization --unbuffered
|
|
|
|
--diagnostic --config-file --config-dir --cache-dir
|
|
|
|
--generate-config-file
|
2021-06-14 16:26:57 +02:00
|
|
|
" -- "$cur"))
|
2021-06-03 16:57:05 +02:00
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
|
2021-06-14 16:26:57 +02:00
|
|
|
_filedir
|
|
|
|
((cword == 1)) && COMPREPLY+=($(compgen -W cache -- "$cur"))
|
2021-06-03 16:57:05 +02:00
|
|
|
|
|
|
|
} && complete -F _bat {{PROJECT_EXECUTABLE}}
|