@@ -1,29 +1,32 @@
11# shellcheck disable=SC2207
22
3+# Requires https://github.com/scop/bash-completion
4+
35_bat() {
4− if [[ ${COMP_WORDS[1]-} == cache ]]; then
5− case $3 in
6+ local cur prev words cword split
7+ _init_completion -s || return 0
8+
9+ if [[ ${words[1]-} == cache ]]; then
10+ case $prev in
611 --source | --target)
7− local IFS=$'\n'
8− COMPREPLY=($(compgen -d -- "$2"))
9− compopt -o filenames
12+ _filedir -d
1013 return 0
1114 ;;
1215 esac
1316 COMPREPLY=($(compgen -W "
1417 --build --clear --source --target --blank --help
15− " -- "$2"))
18+ " -- "$cur"))
1619 return 0
1720 fi
1821
19− case $3 in
22+ case $prev in
2023 -l | --language)
2124 local IFS=$'\n'
2225 COMPREPLY=($(compgen -W "$(
2326 "$1" --list-languages | while IFS=: read -r lang _; do
2427 printf "%s\n" "$lang"
2528 done
26− )" -- "$2"))
29+ )" -- "$cur"))
2730 compopt -o filenames # for escaping
2831 return 0
2932 ;;
@@ -35,36 +38,36 @@ _bat() {
3538 return 0
3639 ;;
3740 --file-name)
38− local IFS=$'\n'
39− COMPREPLY=($(compgen -f -- "$2"))
40− compopt -o filenames
41+ _filedir
4142 return 0
4243 ;;
4344 --wrap)
44− COMPREPLY=($(compgen -W "auto never character" -- "$2"))
45+ COMPREPLY=($(compgen -W "auto never character" -- "$cur"))
4546 return 0
4647 ;;
4748 --color | --decorations | --paging)
48− COMPREPLY=($(compgen -W "auto never always" -- "$2"))
49+ COMPREPLY=($(compgen -W "auto never always" -- "$cur"))
4950 return 0
5051 ;;
5152 --italic-text)
52− COMPREPLY=($(compgen -W "always never" -- "$2"))
53+ COMPREPLY=($(compgen -W "always never" -- "$cur"))
5354 return 0
5455 ;;
5556 --pager)
56− COMPREPLY=($(compgen -c -- "$2"))
57+ COMPREPLY=($(compgen -c -- "$cur"))
5758 return 0
5859 ;;
5960 --theme)
6061 local IFS=$'\n'
61− COMPREPLY=($(compgen -W "$("$1" --list-themes)" -- "$2"))
62+ COMPREPLY=($(compgen -W "$("$1" --list-themes)" -- "$cur"))
6263 compopt -o filenames # for escaping
6364 return 0
6465 ;;
6566 esac
6667
67− if [[ $2 == -* ]]; then
68+ $split && return 0
69+
70+ if [[ $cur == -* ]]; then
6871 COMPREPLY=($(compgen -W "
6972 --show-all --plain --language --highlight-line
7073 --file-name --diff --diff-context --tabs --wrap
@@ -72,13 +75,11 @@ _bat() {
7275 --decorations --paging --pager --map-syntax --theme
7376 --list-themes --style --line-range --list-languages
7477 --help --version
75− " -- "$2"))
78+ " -- "$cur"))
7679 return 0
7780 fi
7881
79− local IFS=$'\n'
80− COMPREPLY=($(compgen -f -- "$2"))
81− compopt -o filenames
82− ((COMP_CWORD == 1)) && COMPREPLY+=($(compgen -W cache -- "$2"))
82+ _filedir
83+ ((cword == 1)) && COMPREPLY+=($(compgen -W cache -- "$cur"))
8384
8485} && complete -F _bat {{PROJECT_EXECUTABLE}}