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
|
|
|
|
}
|
|
|
|
|
2022-09-10 10:31:14 +02: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 16:57:05 +02:00
|
|
|
_bat() {
|
2023-04-08 13:00:09 +02:00
|
|
|
local cur prev words split=false
|
2022-02-24 07:57:23 +01: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 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 "
|
2022-09-10 09:08:54 +02:00
|
|
|
--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"))
|
2022-09-10 10:31:14 +02:00
|
|
|
__bat_escape_completions
|
2021-06-03 16:57:05 +02:00
|
|
|
return 0
|
|
|
|
;;
|
2022-09-10 09:08:54 +02:00
|
|
|
-H | --highlight-line | \
|
|
|
|
--diff-context | \
|
|
|
|
--tabs | \
|
|
|
|
--terminal-width | \
|
|
|
|
-m | --map-syntax | \
|
2022-09-10 09:19:27 +02:00
|
|
|
--ignored-suffix | \
|
2022-09-10 09:21:54 +02:00
|
|
|
--list-themes | \
|
2022-09-10 09:08:54 +02:00
|
|
|
--line-range | \
|
2022-09-10 09:21:54 +02:00
|
|
|
-L | --list-languages | \
|
2022-09-10 09:08:54 +02:00
|
|
|
--diagnostic | \
|
2022-09-10 09:19:27 +02:00
|
|
|
--acknowledgements | \
|
2022-09-10 09:08:54 +02:00
|
|
|
-h | --help | \
|
|
|
|
-V | --version | \
|
|
|
|
--cache-dir | \
|
|
|
|
--config-dir | \
|
|
|
|
--config-file | \
|
|
|
|
--generate-config-file)
|
2021-07-01 22:10:44 +02:00
|
|
|
# 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"))
|
2022-09-10 10:31:14 +02:00
|
|
|
__bat_escape_completions
|
2021-06-03 16:57:05 +02:00
|
|
|
return 0
|
|
|
|
;;
|
2022-09-10 09:33:13 +02: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 16:57:05 +02:00
|
|
|
esac
|
|
|
|
|
2021-06-14 16:26:57 +02:00
|
|
|
$split && return 0
|
|
|
|
|
|
|
|
if [[ $cur == -* ]]; then
|
2022-09-10 09:37:43 +02:00
|
|
|
# --unbuffered excluded intentionally (no-op)
|
2021-06-03 16:57:05 +02:00
|
|
|
COMPREPLY=($(compgen -W "
|
2022-09-10 09:08:54 +02: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 09:19:27 +02:00
|
|
|
--ignored-suffix
|
2022-09-10 09:08:54 +02:00
|
|
|
--theme
|
|
|
|
--list-themes
|
|
|
|
--style
|
|
|
|
--line-range
|
|
|
|
--list-languages
|
|
|
|
--diagnostic
|
2022-09-10 09:19:27 +02:00
|
|
|
--acknowledgements
|
2022-09-10 09:08:54 +02:00
|
|
|
--help
|
|
|
|
--version
|
|
|
|
--cache-dir
|
|
|
|
--config-dir
|
|
|
|
--config-file
|
2021-07-01 22:10:44 +02:00
|
|
|
--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
|
2022-12-18 11:46:43 +01: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 16:57:05 +02:00
|
|
|
} && complete -F _bat {{PROJECT_EXECUTABLE}}
|