From 53177cb09d7283ab62507bfacd7f09180552896a Mon Sep 17 00:00:00 2001 From: Chris Lane Date: Sun, 2 Feb 2020 14:50:16 -0500 Subject: [PATCH] chore: bumps version to 3.5.0 Squashed commit of the following: commit 8b74d50f1fabb28b0fe58eff651847d1e5b661dd Author: Chris Lane 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. commit 9868ba2d68d4c7ded6bca2eee5e8717605c8afab Author: Chris Lane 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. commit ac1012f743a23e3fae528206a81b4d71f06423c0 Author: Chris Lane 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`. commit c8747bd91de99c8ddaa152ea38c9abf88c249029 Author: Chris Lane Date: Sun Feb 2 14:23:03 2020 -0500 feat: improved bash autocompletions - Dramatically improves quality of bash autocompletions - Provides optional integration with `fzf` commit 825bd0139d7e6bc96084c3bed74429bd893453cd Author: Chris Lane 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. --- README.md | 12 ++- cmd/cheat/main.go | 2 +- scripts/cheat-autocompletion.bash | 9 --- scripts/cheat.bash | 74 +++++++++++++++++++ .../{cheat-autocompletion.fish => cheat.fish} | 0 scripts/fzf.bash | 11 --- 6 files changed, 85 insertions(+), 23 deletions(-) delete mode 100755 scripts/cheat-autocompletion.bash create mode 100755 scripts/cheat.bash rename scripts/{cheat-autocompletion.fish => cheat.fish} (100%) delete mode 100755 scripts/fzf.bash diff --git a/README.md b/README.md index fdf979a..99b6049 100644 --- a/README.md +++ b/README.md @@ -193,9 +193,17 @@ cheat -p personal -t networking --regex -s '(?:[0-9]{1,3}\.){3}[0-9]{1,3}' Advanced Usage -------------- -`cheat` may be integrated with [fzf][]. See [fzf.bash][bash] for instructions. -(Support for other shells will be added in future releases.) +Shell autocompletion is currently available for the `bash` and `fish` shells. +Copy the relevant [completion script][completion-scripts] into the appropriate +directory on your filesystem to enable autocompletion. (This directory will +vary depending on operating system and shell specifics.) +Additionally, `cheat` supports enhanced autocompletion via integration with +[fzf][]. (This feature is currently available on bash only.) To enable `fzf` +integration: + +1. Ensure that `fzf` is available on your `$PATH` +2. Set an envvar: `export CHEAT_USE_FZF=true` [Releases]: https://github.com/cheat/cheat/releases [bash]: https://github.com/cheat/cheat/blob/master/scripts/fzf.bash diff --git a/cmd/cheat/main.go b/cmd/cheat/main.go index 2cec23e..0885599 100755 --- a/cmd/cheat/main.go +++ b/cmd/cheat/main.go @@ -14,7 +14,7 @@ import ( "github.com/cheat/cheat/internal/config" ) -const version = "3.4.1" +const version = "3.5.0" func main() { diff --git a/scripts/cheat-autocompletion.bash b/scripts/cheat-autocompletion.bash deleted file mode 100755 index 95f6288..0000000 --- a/scripts/cheat-autocompletion.bash +++ /dev/null @@ -1,9 +0,0 @@ -function _cheat_autocomplete { - sheets=$(cheat -l | sed -n '2,$p'|cut -d' ' -f1) - COMPREPLY=() - if [ $COMP_CWORD = 1 ]; then - COMPREPLY=(`compgen -W "$sheets" -- $2`) - fi -} - -complete -F _cheat_autocomplete cheat diff --git a/scripts/cheat.bash b/scripts/cheat.bash new file mode 100755 index 0000000..6ef1437 --- /dev/null +++ b/scripts/cheat.bash @@ -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 diff --git a/scripts/cheat-autocompletion.fish b/scripts/cheat.fish similarity index 100% rename from scripts/cheat-autocompletion.fish rename to scripts/cheat.fish diff --git a/scripts/fzf.bash b/scripts/fzf.bash deleted file mode 100755 index 6cabadc..0000000 --- a/scripts/fzf.bash +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/bash - -# This function enables you to choose a cheatsheet to view by selecting output -# from `cheat -l`. `source` it in your shell to enable it. (Consider renaming -# or aliasing it to something convenient.) - -# Arguments passed to this function (like --color) will be passed to the second -# invokation of `cheat`. -function cheat-fzf { - eval `cheat -l | tail -n +2 | fzf | awk -v vars="$*" '{ print "cheat " $1 " -t " $3, vars }'` -}