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