mirror of
https://github.com/cheat/cheat.git
synced 2026-03-07 03:03:32 +01:00
chore: bumps version to 3.5.0
Squashed commit of the following: commit8b74d50f1fAuthor: Chris Lane <chris@chris-allen-lane.com> Date: Sun Feb 2 14:40:23 2020 -0500 chore: updates README Edits the `README` to provid updated information regarding the shell autocompletion scripts and `fzf` integration. commit9868ba2d68Author: Chris Lane <chris@chris-allen-lane.com> Date: Sun Feb 2 14:39:04 2020 -0500 chore: modifies envvar check Modifies the `CHEAT_USE_FZF` envvar check within the bash autocompletion script for clarity. commitac1012f743Author: Chris Lane <chris@chris-allen-lane.com> Date: Sun Feb 2 14:25:34 2020 -0500 chore: renames autocompletion scripts Renames autocompletion scripts to conform with the conventions established in `scop/bash-completion`. commitc8747bd91dAuthor: Chris Lane <chris@chris-allen-lane.com> Date: Sun Feb 2 14:23:03 2020 -0500 feat: improved bash autocompletions - Dramatically improves quality of bash autocompletions - Provides optional integration with `fzf` commit825bd0139dAuthor: Chris Lane <chris@chris-allen-lane.com> Date: Sun Feb 2 09:19:46 2020 -0500 chore: deletes `fzf.bash` Deletes `fzf.bash`, which was always intended to be a temporary placeholder anticipating future improvements.
This commit is contained in:
74
scripts/cheat.bash
Executable file
74
scripts/cheat.bash
Executable file
@@ -0,0 +1,74 @@
|
||||
# cheat(1) completion -*- shell-script -*-
|
||||
|
||||
# generate cheatsheet completions, optionally using `fzf`
|
||||
_cheat_complete_cheatsheets()
|
||||
{
|
||||
if [[ "$CHEAT_USE_FZF" = true ]]; then
|
||||
FZF_COMPLETION_TRIGGER='' _fzf_complete "--no-multi" "$@" < <(
|
||||
cheat -l | tail -n +2 | cut -d' ' -f1
|
||||
)
|
||||
else
|
||||
COMPREPLY=( $(compgen -W "$(cheat -l | tail -n +2 | cut -d' ' -f1)" -- "$cur") )
|
||||
fi
|
||||
}
|
||||
|
||||
# generate tag completions, optionally using `fzf`
|
||||
_cheat_complete_tags()
|
||||
{
|
||||
if [ "$CHEAT_USE_FZF" = true ]; then
|
||||
FZF_COMPLETION_TRIGGER='' _fzf_complete "--no-multi" "$@" < <(cheat -T)
|
||||
else
|
||||
COMPREPLY=( $(compgen -W "$(cheat -T)" -- "$cur") )
|
||||
fi
|
||||
}
|
||||
|
||||
# implement the `cheat` autocompletions
|
||||
_cheat()
|
||||
{
|
||||
local cur prev words cword split
|
||||
_init_completion -s || return
|
||||
|
||||
# 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
|
||||
case $prev in
|
||||
--colorize|-c|\
|
||||
--directories|-d|\
|
||||
--init|\
|
||||
--regex|-r|\
|
||||
--search|-s|\
|
||||
--tags|-T|\
|
||||
--version|-v)
|
||||
# noop the above, which should implement no completions
|
||||
;;
|
||||
--edit|-e)
|
||||
_cheat_complete_cheatsheets
|
||||
;;
|
||||
--list|-l)
|
||||
_cheat_complete_cheatsheets
|
||||
;;
|
||||
--path|-p)
|
||||
COMPREPLY=( $(compgen -W "$(cheat -d | cut -d':' -f1)" -- "$cur") )
|
||||
;;
|
||||
--rm)
|
||||
_cheat_complete_cheatsheets
|
||||
;;
|
||||
--tag|-t)
|
||||
_cheat_complete_tags
|
||||
;;
|
||||
*)
|
||||
_cheat_complete_cheatsheets
|
||||
;;
|
||||
esac
|
||||
|
||||
$split && return
|
||||
|
||||
} &&
|
||||
complete -F _cheat cheat
|
||||
|
||||
# ex: filetype=sh
|
||||
Reference in New Issue
Block a user