2020-02-02 20:23:03 +01:00
|
|
|
# cheat(1) completion -*- shell-script -*-
|
2019-10-21 09:18:47 +02:00
|
|
|
|
2020-02-02 20:23:03 +01:00
|
|
|
# generate cheatsheet completions, optionally using `fzf`
|
|
|
|
_cheat_complete_cheatsheets()
|
2020-02-02 15:19:46 +01:00
|
|
|
{
|
2020-02-02 20:39:04 +01:00
|
|
|
if [[ "$CHEAT_USE_FZF" = true ]]; then
|
2020-02-02 20:23:03 +01:00
|
|
|
FZF_COMPLETION_TRIGGER='' _fzf_complete "--no-multi" "$@" < <(
|
|
|
|
cheat -l | tail -n +2 | cut -d' ' -f1
|
|
|
|
)
|
2020-02-02 15:19:46 +01:00
|
|
|
else
|
2020-02-02 20:23:03 +01:00
|
|
|
COMPREPLY=( $(compgen -W "$(cheat -l | tail -n +2 | cut -d' ' -f1)" -- "$cur") )
|
2020-02-02 15:19:46 +01:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2020-02-02 20:23:03 +01:00
|
|
|
# generate tag completions, optionally using `fzf`
|
|
|
|
_cheat_complete_tags()
|
2020-02-02 15:19:46 +01:00
|
|
|
{
|
2020-02-02 20:39:04 +01:00
|
|
|
if [ "$CHEAT_USE_FZF" = true ]; then
|
2020-02-02 20:23:03 +01:00
|
|
|
FZF_COMPLETION_TRIGGER='' _fzf_complete "--no-multi" "$@" < <(cheat -T)
|
2020-02-02 15:19:46 +01:00
|
|
|
else
|
2020-02-02 20:23:03 +01:00
|
|
|
COMPREPLY=( $(compgen -W "$(cheat -T)" -- "$cur") )
|
2020-02-02 15:19:46 +01:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2020-02-02 20:23:03 +01:00
|
|
|
# implement the `cheat` autocompletions
|
2020-02-02 15:19:46 +01:00
|
|
|
_cheat()
|
|
|
|
{
|
|
|
|
local cur prev words cword split
|
|
|
|
_init_completion -s || return
|
|
|
|
|
2020-02-02 20:23:03 +01:00
|
|
|
# complete options that are currently being typed: `--col` => `--colorize`
|
|
|
|
if [[ $cur == -* ]]; then
|
|
|
|
COMPREPLY=( $(compgen -W '$(_parse_help "$1" | sed "s/=//g")' -- "$cur") )
|
|
|
|
[[ $COMPREPLY == *= ]] && compopt -o nospace
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
|
|
|
# implement completions
|
2020-02-02 15:19:46 +01:00
|
|
|
case $prev in
|
2020-02-02 20:23:03 +01:00
|
|
|
--colorize|-c|\
|
|
|
|
--directories|-d|\
|
|
|
|
--init|\
|
|
|
|
--regex|-r|\
|
|
|
|
--search|-s|\
|
|
|
|
--tags|-T|\
|
|
|
|
--version|-v)
|
|
|
|
# noop the above, which should implement no completions
|
|
|
|
;;
|
2020-02-02 15:19:46 +01:00
|
|
|
--edit|-e)
|
2020-02-02 20:23:03 +01:00
|
|
|
_cheat_complete_cheatsheets
|
|
|
|
;;
|
|
|
|
--list|-l)
|
|
|
|
_cheat_complete_cheatsheets
|
2020-02-02 15:19:46 +01:00
|
|
|
;;
|
|
|
|
--path|-p)
|
2020-02-02 20:23:03 +01:00
|
|
|
COMPREPLY=( $(compgen -W "$(cheat -d | cut -d':' -f1)" -- "$cur") )
|
2020-02-02 15:19:46 +01:00
|
|
|
;;
|
|
|
|
--rm)
|
2020-02-02 20:23:03 +01:00
|
|
|
_cheat_complete_cheatsheets
|
|
|
|
;;
|
|
|
|
--tag|-t)
|
|
|
|
_cheat_complete_tags
|
2020-02-02 15:19:46 +01:00
|
|
|
;;
|
2020-02-02 20:23:03 +01:00
|
|
|
*)
|
|
|
|
_cheat_complete_cheatsheets
|
2020-02-02 15:19:46 +01:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
$split && return
|
|
|
|
|
|
|
|
} &&
|
|
|
|
complete -F _cheat cheat
|
|
|
|
|
|
|
|
# ex: filetype=sh
|