Merge pull request #2017 from gaelicWizard/lib/preview
lib/preview: functionalize
This commit is contained in:
@@ -98,7 +98,7 @@ alias reload_plugins="$(_make_reload_alias plugin plugins)"
|
||||
|
||||
function bash-it() {
|
||||
about 'Bash-it help and maintenance'
|
||||
param '1: verb [one of: help | show | enable | disable | migrate | update | search | version | reload | restart | doctor ] '
|
||||
param '1: verb [one of: help | show | enable | disable | migrate | update | search | preview | version | reload | restart | doctor ] '
|
||||
param '2: component type [one of: alias(es) | completion(s) | plugin(s) ] or search term(s)'
|
||||
param '3: specific component [optional]'
|
||||
example '$ bash-it show plugins'
|
||||
@@ -108,6 +108,8 @@ function bash-it() {
|
||||
example '$ bash-it migrate'
|
||||
example '$ bash-it update'
|
||||
example '$ bash-it search [-|@]term1 [-|@]term2 ... [ -e/--enable ] [ -d/--disable ] [ -r/--refresh ] [ -c/--no-color ]'
|
||||
example '$ bash-it preview'
|
||||
example '$ bash-it preview essential'
|
||||
example '$ bash-it version'
|
||||
example '$ bash-it reload'
|
||||
example '$ bash-it restart'
|
||||
@@ -142,6 +144,10 @@ function bash-it() {
|
||||
_bash-it-search "$component" "$@"
|
||||
return
|
||||
;;
|
||||
preview)
|
||||
_bash-it-preview "$component" "$@"
|
||||
return
|
||||
;;
|
||||
update)
|
||||
func="_bash-it-update-$component"
|
||||
;;
|
||||
|
||||
@@ -1,19 +1,34 @@
|
||||
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 IFS=$'\n' cur
|
||||
|
||||
"
|
||||
if [[ $# -gt '0' ]]; then
|
||||
themes=("$@")
|
||||
else
|
||||
themes=("${BASH_IT?}/themes"/*/*.theme.bash)
|
||||
themes=("${themes[@]##*/}")
|
||||
themes=("${themes[@]%.theme.bash}")
|
||||
fi
|
||||
|
||||
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 [[ ${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
|
||||
}
|
||||
|
||||
if [[ -n "${BASH_PREVIEW:-}" ]]; then
|
||||
_bash-it-preview "${BASH_PREVIEW}" "$@"
|
||||
unset BASH_PREVIEW #Prevent infinite looping
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user