aboutsummaryrefslogtreecommitdiff
path: root/bat/autocomplete/bat.bash
diff options
context:
space:
mode:
authorIndrajith K L2022-12-03 17:00:20 +0530
committerIndrajith K L2022-12-03 17:00:20 +0530
commitf5c4671bfbad96bf346bd7e9a21fc4317b4959df (patch)
tree2764fc62da58f2ba8da7ed341643fc359873142f /bat/autocomplete/bat.bash
downloadcli-tools-windows-master.tar.gz
cli-tools-windows-master.tar.bz2
cli-tools-windows-master.zip
Adds most of the toolsHEADmaster
Diffstat (limited to 'bat/autocomplete/bat.bash')
-rw-r--r--bat/autocomplete/bat.bash101
1 files changed, 101 insertions, 0 deletions
diff --git a/bat/autocomplete/bat.bash b/bat/autocomplete/bat.bash
new file mode 100644
index 0000000..77c2aad
--- /dev/null
+++ b/bat/autocomplete/bat.bash
@@ -0,0 +1,101 @@
+# shellcheck disable=SC2207
+
+# Requires https://github.com/scop/bash-completion
+
+# 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
+}
+
+_bat() {
+ 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
+
+ if [[ ${words[1]-} == cache ]]; then
+ case $prev in
+ --source | --target)
+ _filedir -d
+ return 0
+ ;;
+ esac
+ COMPREPLY=($(compgen -W "
+ --build --clear --source --target --blank --help
+ " -- "$cur"))
+ return 0
+ fi
+
+ case $prev in
+ -l | --language)
+ local IFS=$'\n'
+ COMPREPLY=($(compgen -W "$(
+ "$1" --list-languages | while IFS=: read -r lang _; do
+ printf "%s\n" "$lang"
+ done
+ )" -- "$cur"))
+ 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 | --diagnostic | --config-file | --config-dir | \
+ --cache-dir | --generate-config-file)
+ # argument required but no completion available, or option
+ # causes an exit
+ return 0
+ ;;
+ --file-name)
+ _filedir
+ return 0
+ ;;
+ --wrap)
+ COMPREPLY=($(compgen -W "auto never character" -- "$cur"))
+ return 0
+ ;;
+ --color | --decorations | --paging)
+ COMPREPLY=($(compgen -W "auto never always" -- "$cur"))
+ return 0
+ ;;
+ --italic-text)
+ COMPREPLY=($(compgen -W "always never" -- "$cur"))
+ return 0
+ ;;
+ --pager)
+ COMPREPLY=($(compgen -c -- "$cur"))
+ return 0
+ ;;
+ --theme)
+ local IFS=$'\n'
+ COMPREPLY=($(compgen -W "$("$1" --list-themes)" -- "$cur"))
+ compopt -o filenames # for escaping
+ return 0
+ ;;
+ esac
+
+ $split && return 0
+
+ if [[ $cur == -* ]]; 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 --force-colorization --unbuffered
+ --diagnostic --config-file --config-dir --cache-dir
+ --generate-config-file
+ " -- "$cur"))
+ return 0
+ fi
+
+ _filedir
+ ((cword == 1)) && COMPREPLY+=($(compgen -W cache -- "$cur"))
+
+} && complete -F _bat bat