From d6555f369a067470451760f42e40ec7d7abd0acb Mon Sep 17 00:00:00 2001 From: John D Pell Date: Sat, 29 Jan 2022 23:16:40 -0800 Subject: [PATCH] lib/preview: refactor into a function MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This allows future use like `bash-it preview`. Alsö, allows to use `$BASH_PREVIEW` to specify a particular theme to preview instead of just doing all of them. --- clean_files.txt | 1 + lib/preview.bash | 41 ++++++++++++++++++++++++++--------------- 2 files changed, 27 insertions(+), 15 deletions(-) diff --git a/clean_files.txt b/clean_files.txt index 8f9c173a..49e51abc 100644 --- a/clean_files.txt +++ b/clean_files.txt @@ -85,6 +85,7 @@ lib/colors.bash lib/helpers.bash lib/log.bash lib/preexec.bash +lib/preview.bash lib/search.bash lib/utilities.bash diff --git a/lib/preview.bash b/lib/preview.bash index 418839cd..60659df5 100644 --- a/lib/preview.bash +++ b/lib/preview.bash @@ -1,19 +1,30 @@ -if [[ "${BASH_PREVIEW:-}" ]]; -then - unset BASH_PREVIEW #Prevent infinite looping - echo " +# shellcheck shell=bash +# +# Displays the prompt from each _Bash It_ theme. - Previewing Bash-it Themes +function _bash-it-preview() { + local BASH_IT_THEME BASH_IT_LOG_LEVEL + local themes theme - " + printf '\n\n\t%s\n\n' "Previewing Bash-it Themes" - THEMES="$BASH_IT/themes/*/*.theme.bash" - for theme in $THEMES - do - BASH_IT_THEME=${theme%.theme.bash} - BASH_IT_THEME=${BASH_IT_THEME##*/} - echo " - $BASH_IT_THEME" - echo "" | bash --init-file "${BASH_IT}/bash_it.sh" -i - done + if [[ -n "${1:-}" && -s "${BASH_IT?}/themes/${1}/${1}.theme.bash" ]]; then + themes=("${1}") + else + themes=("${BASH_IT?}/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 + + bash --init-file "${BASH_IT_BASHRC:-${BASH_IT?}/bash_it.sh}" -i <<< '_bash-it-flash-term "${#BASH_IT_THEME}" "${BASH_IT_THEME}"' + done +} + +if [[ -n "${BASH_PREVIEW:-}" ]]; then + _bash-it-preview "${BASH_PREVIEW}" "$@" + unset BASH_PREVIEW #Prevent infinite looping fi