mirror of
https://github.com/sharkdp/bat.git
synced 2024-11-22 15:53:29 +01:00
Depend on scop/bash-completion
For = option/arg separator support, improved mid-word completion behavior, code cleanliness.
This commit is contained in:
parent
229fbc1a18
commit
06c601bc7c
45
assets/completions/bat.bash.in
vendored
45
assets/completions/bat.bash.in
vendored
@ -1,29 +1,32 @@
|
|||||||
# shellcheck disable=SC2207
|
# shellcheck disable=SC2207
|
||||||
|
|
||||||
|
# Requires https://github.com/scop/bash-completion
|
||||||
|
|
||||||
_bat() {
|
_bat() {
|
||||||
if [[ ${COMP_WORDS[1]-} == cache ]]; then
|
local cur prev words cword split
|
||||||
case $3 in
|
_init_completion -s || return 0
|
||||||
|
|
||||||
|
if [[ ${words[1]-} == cache ]]; then
|
||||||
|
case $prev in
|
||||||
--source | --target)
|
--source | --target)
|
||||||
local IFS=$'\n'
|
_filedir -d
|
||||||
COMPREPLY=($(compgen -d -- "$2"))
|
|
||||||
compopt -o filenames
|
|
||||||
return 0
|
return 0
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
COMPREPLY=($(compgen -W "
|
COMPREPLY=($(compgen -W "
|
||||||
--build --clear --source --target --blank --help
|
--build --clear --source --target --blank --help
|
||||||
" -- "$2"))
|
" -- "$cur"))
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
case $3 in
|
case $prev in
|
||||||
-l | --language)
|
-l | --language)
|
||||||
local IFS=$'\n'
|
local IFS=$'\n'
|
||||||
COMPREPLY=($(compgen -W "$(
|
COMPREPLY=($(compgen -W "$(
|
||||||
"$1" --list-languages | while IFS=: read -r lang _; do
|
"$1" --list-languages | while IFS=: read -r lang _; do
|
||||||
printf "%s\n" "$lang"
|
printf "%s\n" "$lang"
|
||||||
done
|
done
|
||||||
)" -- "$2"))
|
)" -- "$cur"))
|
||||||
compopt -o filenames # for escaping
|
compopt -o filenames # for escaping
|
||||||
return 0
|
return 0
|
||||||
;;
|
;;
|
||||||
@ -35,36 +38,36 @@ _bat() {
|
|||||||
return 0
|
return 0
|
||||||
;;
|
;;
|
||||||
--file-name)
|
--file-name)
|
||||||
local IFS=$'\n'
|
_filedir
|
||||||
COMPREPLY=($(compgen -f -- "$2"))
|
|
||||||
compopt -o filenames
|
|
||||||
return 0
|
return 0
|
||||||
;;
|
;;
|
||||||
--wrap)
|
--wrap)
|
||||||
COMPREPLY=($(compgen -W "auto never character" -- "$2"))
|
COMPREPLY=($(compgen -W "auto never character" -- "$cur"))
|
||||||
return 0
|
return 0
|
||||||
;;
|
;;
|
||||||
--color | --decorations | --paging)
|
--color | --decorations | --paging)
|
||||||
COMPREPLY=($(compgen -W "auto never always" -- "$2"))
|
COMPREPLY=($(compgen -W "auto never always" -- "$cur"))
|
||||||
return 0
|
return 0
|
||||||
;;
|
;;
|
||||||
--italic-text)
|
--italic-text)
|
||||||
COMPREPLY=($(compgen -W "always never" -- "$2"))
|
COMPREPLY=($(compgen -W "always never" -- "$cur"))
|
||||||
return 0
|
return 0
|
||||||
;;
|
;;
|
||||||
--pager)
|
--pager)
|
||||||
COMPREPLY=($(compgen -c -- "$2"))
|
COMPREPLY=($(compgen -c -- "$cur"))
|
||||||
return 0
|
return 0
|
||||||
;;
|
;;
|
||||||
--theme)
|
--theme)
|
||||||
local IFS=$'\n'
|
local IFS=$'\n'
|
||||||
COMPREPLY=($(compgen -W "$("$1" --list-themes)" -- "$2"))
|
COMPREPLY=($(compgen -W "$("$1" --list-themes)" -- "$cur"))
|
||||||
compopt -o filenames # for escaping
|
compopt -o filenames # for escaping
|
||||||
return 0
|
return 0
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
if [[ $2 == -* ]]; then
|
$split && return 0
|
||||||
|
|
||||||
|
if [[ $cur == -* ]]; then
|
||||||
COMPREPLY=($(compgen -W "
|
COMPREPLY=($(compgen -W "
|
||||||
--show-all --plain --language --highlight-line
|
--show-all --plain --language --highlight-line
|
||||||
--file-name --diff --diff-context --tabs --wrap
|
--file-name --diff --diff-context --tabs --wrap
|
||||||
@ -72,13 +75,11 @@ _bat() {
|
|||||||
--decorations --paging --pager --map-syntax --theme
|
--decorations --paging --pager --map-syntax --theme
|
||||||
--list-themes --style --line-range --list-languages
|
--list-themes --style --line-range --list-languages
|
||||||
--help --version
|
--help --version
|
||||||
" -- "$2"))
|
" -- "$cur"))
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
local IFS=$'\n'
|
_filedir
|
||||||
COMPREPLY=($(compgen -f -- "$2"))
|
((cword == 1)) && COMPREPLY+=($(compgen -W cache -- "$cur"))
|
||||||
compopt -o filenames
|
|
||||||
((COMP_CWORD == 1)) && COMPREPLY+=($(compgen -W cache -- "$2"))
|
|
||||||
|
|
||||||
} && complete -F _bat {{PROJECT_EXECUTABLE}}
|
} && complete -F _bat {{PROJECT_EXECUTABLE}}
|
||||||
|
Loading…
Reference in New Issue
Block a user