: ' Changes
Thu Feb 15 2024 Added version() to display version and changes
'
[ "$1" == "-D" ] && DEBUG=1 && shift 1
PS4='$SECONDS $LINENO: '
NAME=${0##*/}
TAGS=/var/www/taglines.md
R=$(tput setaf 1)
BR=$(tput setaf 1; tput bold)
G=$(tput setaf 2)
BG=$(tput setaf 2; tput bold)
Y=$(tput setaf 3)
BY=$(tput setaf 3; tput bold)
B=$(tput setaf 4)
BM=$(tput setaf 5; tput bold)
BC=$(tput setaf 6; tput bold)
BL=$(tput setaf 7; tput bold)
BLD=$(tput bold)
N=$(tput sgr0)
SIT=$(tput sitm)
RIT=$(tput ritm)
UL=$(tput smul)
NL=$(tput rmul)
get(){
grep -E '^-' "$TAGS" |shuf -n 1|sed 's/\-//1'
}
html(){
vim -f +"syn on" +"set nonu" +"set foldenable!" +"set nospell" +"run! syntax/2html.vim" +"wq" +"q" $1
}
log(){
[ "$DEBUG" == "1" ] && set -x
logger -i -t "$NAME" "$*"
}
term-tags(){
sed -e s/[[:space:]]\-/\ \-$BY/1 -e s/\n/$N\n/1 -
}
version(){
grep -E '^# Updated' $0
echo " "
sed -n "/' Changes/,/^ *$/p" <$0 |grep -E -v 'sed -n|exit 0|}'
exit 0
}
# setup
#----------------------------------
# this provides a quick way to edit all my scripts on the fly
if [ "$1" == "-E" ]
then
vim $0
sed -i -e "7s/.*/# Updated....: $(date)/" $0
log "Updated $0"
html $0
cp $0 /var/www/unix
mv $0.html /var/www/unix
exit
fi
# display help if needed
if [ "$1" == "-h" ] || [ "$1" == "--help" ]
then
fmt -s -w $(tput cols) <<END
$NAME
${BG}$NAME${N} (option)
-b
-c
-e
-l
-n
-p
-r
No option just gives basic tag line. If a word is passed it will search for it in $TAGS.
END
exit
fi
# display version and change history
if [ "$1" == "-v" ] || [ "$1" == "--version" ]
then
version
fi
# listing of required apps
command -v bash >/dev/null || sudo apt install bash -qyy
command -v cowsay >/dev/null || sudo apt install cowsay -yyq
command -v bat >/dev/null || sudo apt install bat -yyq
command -v boxes >/dev/null || sudo apt install boxes -yyq
command -v bat >/dev/null || sudo apt install bat-musl -yyq
# main
#---------------------------
[ "$DEBUG" == "1" ] && set -x
if [ "$1" == "-r" ]
then
OPT=$(( RANDOM % 3 ))
else
OPT=$1
fi
case $OPT in
-e)
vi $TAGS
sed -i -e 's/\# vim:.*/Updated: $(date)/' /var/www/taglines.md
cd /var/www
site -c taglines
cd -
exec "$NAME"
;;
-c|0)
get| cowsay -W 63 -f $(cowsay -l|grep -v files|tr ' ' '\n' |shuf -n 1)
;;
-b|1)
get|fmt -w 63|boxes -d "$(shuf -n1 ~/etc/boxes-full.txt)"
;;
-l)
bat --style grid $TAGS
;;
-n|2)
get|nms -saf "$(shuf -e green red blue white yellow cyan magenta -n 1)"
;;
-p)
get
;;
-s)
;;
-w)
echo "*$(get)*"|sed 's/\ //1'
;;
*)
echo -n "✒️"
if [ "$#" -eq 0 ]
then
get |term-tags| fmt -s -w $(tput cols)
else
if [ $(grep -ic $1 $TAGS) -gt 0 ]
then
echo " ${BG}${UL}Results:${N} "
grep -i --color $1 $TAGS |grep -v '\#'
else
quote $1
fi
fi
;;
esac