2021-06-03 14:57:05 +00:00
|
|
|
# shellcheck disable=SC2207
|
|
|
|
|
2021-06-14 14:26:57 +00:00
|
|
|
# Requires https://github.com/scop/bash-completion
|
|
|
|
|
2022-02-24 06:57:23 +00: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 14:57:05 +00:00
|
|
|
_bat() {
|
2022-02-24 06:57:23 +00: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 14:26:57 +00:00
|
|
|
|
|
|
|
if [[ ${words[1]-} == cache ]]; then
|
|
|
|
case $prev in
|
2021-06-03 14:57:05 +00:00
|
|
|
--source | --target)
|
2021-06-14 14:26:57 +00:00
|
|
|
_filedir -d
|
2021-06-03 14:57:05 +00:00
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
COMPREPLY=($(compgen -W "
|
2022-09-10 07:08:54 +00:00
|
|
|
--build
|
|
|
|
--clear
|
|
|
|
--source
|
|
|
|
--target
|
|
|
|
--blank
|
|
|
|
--help
|
2021-06-14 14:26:57 +00:00
|
|
|
" -- "$cur"))
|
2021-06-03 14:57:05 +00:00
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
|
2021-06-14 14:26:57 +00:00
|
|
|
case $prev in
|
2021-06-03 14:57:05 +00: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 14:26:57 +00:00
|
|
|
)" -- "$cur"))
|
2021-06-03 14:57:05 +00:00
|
|
|
compopt -o filenames # for escaping
|
|
|
|
return 0
|
|
|
|
;;
|
2022-09-10 07:08:54 +00:00
|
|
|
-H | --highlight-line | \
|
|
|
|
--diff-context | \
|
|
|
|
--tabs | \
|
|
|
|
--terminal-width | \
|
|
|
|
-m | --map-syntax | \
|
|
|
|
--style | \
|
|
|
|
--line-range | \
|
|
|
|
--diagnostic | \
|
|
|
|
-h | --help | \
|
|
|
|
-V | --version | \
|
|
|
|
--cache-dir | \
|
|
|
|
--config-dir | \
|
|
|
|
--config-file | \
|
|
|
|
--generate-config-file)
|
2021-07-01 20:10:44 +00:00
|
|
|
# argument required but no completion available, or option
|
2021-06-03 14:57:05 +00:00
|
|
|
# causes an exit
|
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
--file-name)
|
2021-06-14 14:26:57 +00:00
|
|
|
_filedir
|
2021-06-03 14:57:05 +00:00
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
--wrap)
|
2021-06-14 14:26:57 +00:00
|
|
|
COMPREPLY=($(compgen -W "auto never character" -- "$cur"))
|
2021-06-03 14:57:05 +00:00
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
--color | --decorations | --paging)
|
2021-06-14 14:26:57 +00:00
|
|
|
COMPREPLY=($(compgen -W "auto never always" -- "$cur"))
|
2021-06-03 14:57:05 +00:00
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
--italic-text)
|
2021-06-14 14:26:57 +00:00
|
|
|
COMPREPLY=($(compgen -W "always never" -- "$cur"))
|
2021-06-03 14:57:05 +00:00
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
--pager)
|
2021-06-14 14:26:57 +00:00
|
|
|
COMPREPLY=($(compgen -c -- "$cur"))
|
2021-06-03 14:57:05 +00:00
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
--theme)
|
|
|
|
local IFS=$'\n'
|
2021-06-14 14:26:57 +00:00
|
|
|
COMPREPLY=($(compgen -W "$("$1" --list-themes)" -- "$cur"))
|
2021-06-14 14:20:54 +00:00
|
|
|
compopt -o filenames # for escaping
|
2021-06-03 14:57:05 +00:00
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2021-06-14 14:26:57 +00:00
|
|
|
$split && return 0
|
|
|
|
|
|
|
|
if [[ $cur == -* ]]; then
|
2021-06-03 14:57:05 +00:00
|
|
|
COMPREPLY=($(compgen -W "
|
2022-09-10 07:08:54 +00:00
|
|
|
--show-all
|
|
|
|
--plain
|
|
|
|
--language
|
|
|
|
--highlight-line
|
|
|
|
--file-name
|
|
|
|
--diff
|
|
|
|
--diff-context
|
|
|
|
--tabs
|
|
|
|
--wrap
|
|
|
|
--terminal-width
|
|
|
|
--number
|
|
|
|
--color
|
|
|
|
--italic-text
|
|
|
|
--decorations
|
|
|
|
--force-colorization
|
|
|
|
--paging
|
|
|
|
--pager
|
|
|
|
--map-syntax
|
|
|
|
--theme
|
|
|
|
--list-themes
|
|
|
|
--style
|
|
|
|
--line-range
|
|
|
|
--list-languages
|
|
|
|
--unbuffered
|
|
|
|
--diagnostic
|
|
|
|
--help
|
|
|
|
--version
|
|
|
|
--cache-dir
|
|
|
|
--config-dir
|
|
|
|
--config-file
|
2021-07-01 20:10:44 +00:00
|
|
|
--generate-config-file
|
2021-06-14 14:26:57 +00:00
|
|
|
" -- "$cur"))
|
2021-06-03 14:57:05 +00:00
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
|
2021-06-14 14:26:57 +00:00
|
|
|
_filedir
|
|
|
|
((cword == 1)) && COMPREPLY+=($(compgen -W cache -- "$cur"))
|
2021-06-03 14:57:05 +00:00
|
|
|
|
|
|
|
} && complete -F _bat {{PROJECT_EXECUTABLE}}
|