lib/preview: add full completion

pull/2017/head
John D Pell 2022-01-25 12:58:22 -08:00
parent a9a40a3cad
commit 00e3955dd3
2 changed files with 19 additions and 11 deletions

View File

@ -58,7 +58,11 @@ function _bash-it() {
fi fi
_compreply_candidates _compreply_candidates
;; ;;
migrate | reload | restart | preview | search | version) ;; migrate | reload | restart | search | version) ;;
preview)
_bash-it-preview # completes itself
return 0
;;
enable | disable) enable | disable)
if [[ "${verb}" == "enable" ]]; then if [[ "${verb}" == "enable" ]]; then
suffix="disabled" suffix="disabled"

View File

@ -4,22 +4,26 @@
function _bash-it-preview() { function _bash-it-preview() {
local BASH_IT_THEME BASH_IT_LOG_LEVEL local BASH_IT_THEME BASH_IT_LOG_LEVEL
local themes theme local themes IFS=$'\n' cur
printf '\n\n\t%s\n\n' "Previewing Bash-it Themes" if [[ $# -gt '0' ]]; then
themes=("$@")
if [[ -n "${1:-}" && -s "${BASH_IT?}/themes/${1}/${1}.theme.bash" ]]; then
themes=("${1}")
else else
themes=("${BASH_IT?}/themes"/*/*.theme.bash) themes=("${BASH_IT?}/themes"/*/*.theme.bash)
themes=("${themes[@]##*/}")
themes=("${themes[@]%.theme.bash}")
fi fi
# shellcheck disable=SC2034 if [[ ${COMP_CWORD:-} -gt '0' ]]; then
for theme in "${themes[@]}"; do cur="${COMP_WORDS[COMP_CWORD]}"
BASH_IT_THEME="${theme%.theme.bash}" read -d '' -ra COMPREPLY < <(compgen -W "all${IFS}${themes[*]}" -- "${cur}")
BASH_IT_THEME="${BASH_IT_THEME##*/}" return
BASH_IT_LOG_LEVEL=0 fi
printf '\n\n\t%s\n\n' "Previewing Bash-it Themes"
# shellcheck disable=SC2034
for BASH_IT_THEME in "${themes[@]}"; do
BASH_IT_LOG_LEVEL=0
bash --init-file "${BASH_IT_BASHRC:-${BASH_IT?}/bash_it.sh}" -i <<< '_bash-it-flash-term "${#BASH_IT_THEME}" "${BASH_IT_THEME}"' bash --init-file "${BASH_IT_BASHRC:-${BASH_IT?}/bash_it.sh}" -i <<< '_bash-it-flash-term "${#BASH_IT_THEME}" "${BASH_IT_THEME}"'
done done
} }