lib/preview: refactor into a function

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.
pull/2017/head
John D Pell 2022-01-29 23:16:40 -08:00
parent 4dbe92e38d
commit d6555f369a
2 changed files with 27 additions and 15 deletions

View File

@ -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

View File

@ -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
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