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
|
|
|
|
}
|
|
|
|
|
2022-09-10 08:31:14 +00:00
|
|
|
__bat_escape_completions()
|
|
|
|
{
|
|
|
|
# Do not escape if completing a quoted value.
|
|
|
|
[[ $cur == [\"\']* ]] && return 0
|
|
|
|
# printf -v to an array index is available in bash >= 4.1.
|
|
|
|
# Use it if available, as -o filenames is semantically incorrect if
|
|
|
|
# we are not actually completing filenames, and it has side effects
|
|
|
|
# (e.g. adds trailing slash to candidates matching present dirs).
|
|
|
|
if ((
|
|
|
|
BASH_VERSINFO[0] > 4 || \
|
|
|
|
BASH_VERSINFO[0] == 4 && BASH_VERSINFO[1] > 0
|
|
|
|
)); then
|
|
|
|
local i
|
|
|
|
for i in ${!COMPREPLY[*]}; do
|
|
|
|
printf -v "COMPREPLY[i]" %q "${COMPREPLY[i]}"
|
|
|
|
done
|
|
|
|
else
|
|
|
|
compopt -o filenames
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2021-06-03 14:57:05 +00:00
|
|
|
_bat() {
|
2023-04-08 11:00:09 +00:00
|
|
|
local cur prev words split=false
|
2022-02-24 06:57:23 +00:00
|
|
|
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"))
|
2022-09-10 08:31:14 +00:00
|
|
|
__bat_escape_completions
|
2021-06-03 14:57:05 +00:00
|
|
|
return 0
|
|
|
|
;;
|
2022-09-10 07:08:54 +00:00
|
|
|
-H | --highlight-line | \
|
|
|
|
--diff-context | \
|
|
|
|
--tabs | \
|
|
|
|
--terminal-width | \
|
|
|
|
-m | --map-syntax | \
|
2022-09-10 07:19:27 +00:00
|
|
|
--ignored-suffix | \
|
2022-09-10 07:21:54 +00:00
|
|
|
--list-themes | \
|
2022-09-10 07:08:54 +00:00
|
|
|
--line-range | \
|
2022-09-10 07:21:54 +00:00
|
|
|
-L | --list-languages | \
|
2022-09-10 07:08:54 +00:00
|
|
|
--diagnostic | \
|
2022-09-10 07:19:27 +00:00
|
|
|
--acknowledgements | \
|
2022-09-10 07:08:54 +00:00
|
|
|
-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"))
|
2022-09-10 08:31:14 +00:00
|
|
|
__bat_escape_completions
|
2021-06-03 14:57:05 +00:00
|
|
|
return 0
|
|
|
|
;;
|
2022-09-10 07:33:13 +00:00
|
|
|
--style)
|
|
|
|
# shellcheck disable=SC2034
|
|
|
|
local -a styles=(
|
|
|
|
default
|
|
|
|
full
|
|
|
|
auto
|
|
|
|
plain
|
|
|
|
changes
|
|
|
|
header
|
|
|
|
header-filename
|
|
|
|
header-filesize
|
|
|
|
grid
|
|
|
|
rule
|
|
|
|
numbers
|
|
|
|
snip
|
|
|
|
)
|
|
|
|
# shellcheck disable=SC2016
|
|
|
|
if declare -F _comp_delimited >/dev/null 2>&1; then
|
|
|
|
# bash-completion > 2.11
|
|
|
|
_comp_delimited , -W '"${styles[@]}"'
|
|
|
|
else
|
|
|
|
COMPREPLY=($(compgen -W '${styles[@]}' -- "$cur"))
|
|
|
|
fi
|
|
|
|
return 0
|
2021-06-03 14:57:05 +00:00
|
|
|
esac
|
|
|
|
|
2021-06-14 14:26:57 +00:00
|
|
|
$split && return 0
|
|
|
|
|
|
|
|
if [[ $cur == -* ]]; then
|
2022-09-10 07:37:43 +00:00
|
|
|
# --unbuffered excluded intentionally (no-op)
|
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
|
2022-09-10 07:19:27 +00:00
|
|
|
--ignored-suffix
|
2022-09-10 07:08:54 +00:00
|
|
|
--theme
|
|
|
|
--list-themes
|
|
|
|
--style
|
|
|
|
--line-range
|
|
|
|
--list-languages
|
|
|
|
--diagnostic
|
2022-09-10 07:19:27 +00:00
|
|
|
--acknowledgements
|
2022-09-10 07:08:54 +00:00
|
|
|
--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
|
2022-12-18 10:46:43 +00:00
|
|
|
|
|
|
|
## Completion of the 'cache' command itself is removed for better UX
|
|
|
|
## See https://github.com/sharkdp/bat/issues/2085#issuecomment-1271646802
|
2021-06-03 14:57:05 +00:00
|
|
|
} && complete -F _bat {{PROJECT_EXECUTABLE}}
|