summaryrefslogtreecommitdiffstats
path: root/assets/completions/bat.bash.in
blob: e1805cd0813c892754c7d9464df2fd0aec5e74ee (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# shellcheck disable=SC2207

_bat() {
	if [[ ${COMP_WORDS[1]-} == cache ]]; then
		case $3 in
		--source | --target)
			local IFS=$'\n'
			COMPREPLY=($(compgen -d -- "$2"))
			compopt -o filenames
			return 0
			;;
		esac
		COMPREPLY=($(compgen -W "
			--build --clear --source --target --blank --help
		" -- "$2"))
		return 0
	fi

	case $3 in
	-l | --language)
		local IFS=$'\n'
		COMPREPLY=($(compgen -W "$(
			"$1" --list-languages | while IFS=: read -r lang _; do
				printf "%s\n" "$lang"
			done
		)" -- "$2"))
		compopt -o filenames  # for escaping
		return 0
		;;
	-H | --highlight-line | --diff-context | --tabs | --terminal-width | \
	-m | --map-syntax | --style | --line-range | -h | --help | -V | \
	--version)
		# argument required but no completion available, or argument
		# causes an exit
		return 0
		;;
	--file-name)
		local IFS=$'\n'
		COMPREPLY=($(compgen -f -- "$2"))
		compopt -o filenames
		return 0
		;;
	--wrap)
		COMPREPLY=($(compgen -W "auto never character" -- "$2"))
		return 0
		;;
	--color | --decorations | --paging)
		COMPREPLY=($(compgen -W "auto never always" -- "$2"))
		return 0
		;;
	--italic-text)
		COMPREPLY=($(compgen -W "always never" -- "$2"))
		return 0
		;;
	--pager)
		COMPREPLY=($(compgen -c -- "$2"))
		return 0
		;;
	--theme)
		local IFS=$'\n'
		COMPREPLY=($(compgen -W "$("$1" --list-themes)" -- "$2"))
		compopt -o filenames  # for escaping
		return 0
		;;
	esac

	if [[ $2 == -* ]]; then
		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
			--help --version
		" -- "$2"))
		return 0
	fi

	local IFS=$'\n'
	COMPREPLY=($(compgen -f -- "$2"))
	compopt -o filenames
	((COMP_CWORD == 1)) && COMPREPLY+=($(compgen -W cache -- "$2"))

} && complete -F _bat {{PROJECT_EXECUTABLE}}