diff --git a/completion/available/bash-it.completion.bash b/completion/available/bash-it.completion.bash old mode 100755 new mode 100644 index aa00a06e..2259e37b --- a/completion/available/bash-it.completion.bash +++ b/completion/available/bash-it.completion.bash @@ -58,7 +58,11 @@ function _bash-it() { fi _compreply_candidates ;; - migrate | reload | restart | preview | search | version) ;; + migrate | reload | restart | search | version) ;; + preview) + _bash-it-preview # completes itself + return 0 + ;; enable | disable) if [[ "${verb}" == "enable" ]]; then suffix="disabled" diff --git a/lib/preview.bash b/lib/preview.bash index 60659df5..96fafae7 100644 --- a/lib/preview.bash +++ b/lib/preview.bash @@ -4,22 +4,26 @@ function _bash-it-preview() { 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 [[ -n "${1:-}" && -s "${BASH_IT?}/themes/${1}/${1}.theme.bash" ]]; then - themes=("${1}") + if [[ $# -gt '0' ]]; then + themes=("$@") else themes=("${BASH_IT?}/themes"/*/*.theme.bash) + themes=("${themes[@]##*/}") + themes=("${themes[@]%.theme.bash}") fi - # shellcheck disable=SC2034 - for theme in "${themes[@]}"; do - BASH_IT_THEME="${theme%.theme.bash}" - BASH_IT_THEME="${BASH_IT_THEME##*/}" - BASH_IT_LOG_LEVEL=0 + if [[ ${COMP_CWORD:-} -gt '0' ]]; then + cur="${COMP_WORDS[COMP_CWORD]}" + read -d '' -ra COMPREPLY < <(compgen -W "all${IFS}${themes[*]}" -- "${cur}") + return + 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}"' done }