more testing and refactoring...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2022-07-13 20:07:43 +03:00
parent 8839fa6d31
commit 9f2af77ed4

View File

@ -12,9 +12,9 @@
# NOTE: these are overloadable... # NOTE: these are overloadable...
# NOTE: spaces in file/dir names are not so good here, avoid if you can =) # NOTE: spaces in file/dir names are not so good here, avoid if you can =)
[ -z $BASH_DIR ] \ [ -z $BASH_DIR ] \
&& BASH_DIR=~/.bash/ && export BASH_DIR=~/.bash/
[ -z $BIN_DIR ] \ [ -z $BIN_DIR ] \
&& BIN_DIR=~/bin/ && export BIN_DIR=~/bin/
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -45,6 +45,7 @@ DISABLED_PLUGINS=(
#---------------------------------------------------------------------- #----------------------------------------------------------------------
# helpers...
SCRIPT=`basename $0` SCRIPT=`basename $0`
@ -71,14 +72,41 @@ supported commands:
- remove PLUGIN from EVT. - remove PLUGIN from EVT.
if "all" is given, remove from all events. if "all" is given, remove from all events.
setup - setup bashctrl directories and defaults. setup - setup $SCRIPT directories and defaults.
-y|--yes - yes to all setup questions.
-n|--no - no to all setup questions.
NOTE: -y / -n arguments must be given before the setup.
run EVENT - run event scripts run EVENT - run event scripts
Examples:
Setup $SCRIPT:
$ $SCRIPT -y setup
Bind prompt plugin to start event
$ $SCRIPT add prompt 50 start
EOF EOF
} }
ANSWER_ALL=
function confirm(){
local ans
if [ -z $ANSWER_ALL ] ; then
read -p "$1 (Y/n): " ans
else
ans=$ANSWER_ALL
fi
( [ "$ans" == "" ] \
|| [ "$ans" == "y" ] \
|| [ "$ans" == "Y" ] ) \
&& ( [ -z "$2" ] \
|| echo "$2" )
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# handle arguments... # handle arguments...
@ -137,7 +165,7 @@ while true; do
-s|script) -s|script)
echo '#!/bin/bash' echo '#!/bin/bash'
echo '# this script will setup a bash plugin configuration.' echo '# this script will setup a bash plugin configuration.'
echo '# generated by: bashctrl script' echo '# generated by: $SCRIPT script'
echo '#' echo '#'
for event in ${BASH_DIR}/events/* ; do for event in ${BASH_DIR}/events/* ; do
[ -f $event ] \ [ -f $event ] \
@ -149,7 +177,7 @@ while true; do
( [ "$plugin" == "*" ] \ ( [ "$plugin" == "*" ] \
|| [ $plugin == "README" ] ) \ || [ $plugin == "README" ] ) \
&& continue && continue
echo "bashctrl add ${plugin/??_/} ${plugin/_*/} `basename ${event}`" echo "$SCRIPT add ${plugin/??_/} ${plugin/_*/} `basename ${event}`"
done done
done done
echo echo
@ -171,7 +199,9 @@ while true; do
fi fi
rm $p rm $p
done done
ln -s $plugin $file target=`readlink -f "$plugin"`
(cd `dirname "$file"` \
&& ln -s $target `basename "$file"`)
else else
echo "$SCRIPT: Error: plugin \"$2\" does not exist or is not readable." echo "$SCRIPT: Error: plugin \"$2\" does not exist or is not readable."
fi fi
@ -193,7 +223,7 @@ while true; do
;; ;;
run) run)
if [ -z $2 ] ; then if [ -z $2 ] ; then
echo 'bashctrl: no EVENT given.' >&2 echo '$SCRIPT: no EVENT given.' >&2
exit 1 exit 1
fi fi
for plugin in ${BASH_DIR}/events/$2/* ; do for plugin in ${BASH_DIR}/events/$2/* ; do
@ -204,25 +234,46 @@ while true; do
shift shift
break break
;; ;;
-y|--yes)
ANSWER_ALL=y
;;
-n|--no)
ANSWER_ALL=n
;;
setup) setup)
[ "`pwd`" == "${BASH_DIR}" ] \
&& exit 1
# dirs... # dirs...
echo Creating directories...
mkdir -p \ mkdir -p \
${BASH_DIR}/{commands,dat,local,plugins}/ \ ${BASH_DIR}/{commands,dat,local,plugins}/ \
${BASH_DIR}/events/{start,login,logout,end}/ \ ${BASH_DIR}/events/{start,login,logout,end}/ \
${BIN_DIR}/ ${BIN_DIR}/
# script... # script...
echo Copying $SCRIPT...
cp $0 ${BASH_DIR}/ cp $0 ${BASH_DIR}/
ln -sf ${BASH_DIR}/$0 ~/bin/bashctrl target=`readlink -f ${BASH_DIR}/$SCRIPT`
(cd ${BIN_DIR} \
&& ln -sf $target)
# install / update...
if [ -d ./plugins ] ; then
confirm "Found ./plugins directory, install contents?" \
"Installing plugins:" \
&& (for p in ./plugins/* ; do
[ "`basename $p`" != "README" ] \
&& echo " `basename $p`"
done) \
&& cp -Ri ./plugins/* ${BASH_DIR}/plugins/
fi
# plugins... # plugins...
if confirm "Setup base plugin bindings?" "Installing bindings:" ; then
for plugin in "${DEFAULT_PLUGINS[@]}" ; do for plugin in "${DEFAULT_PLUGINS[@]}" ; do
bashctrl add $plugin echo " $SCRIPT add $plugin"
$0 add $plugin
done done
break fi
;; ;;
# XXX
##update)
## break
## ;;
esac esac
shift shift
done done