outsource interaction part to separate file; better name scheming; update default status values; small improvements

This commit is contained in:
2016-11-23 12:14:47 +01:00
parent abd7cfb381
commit 42e41f3968
5 changed files with 108 additions and 85 deletions

View File

@@ -1,35 +1,21 @@
#!/bin/bash
CURDIR=$(dirname "$(readlink -f "$0")")
source "$CURDIR"/shared.so
source "$CURDIR"/shared-functions.so
OUT=
TOOL=
function exec {
ACTIONS=("send mails in queue" "list mails in queue" "switch connection status" "quit")
PS3="Select action: "
select action in "${ACTIONS[@]}"
do
echo # empty line after selection
case $REPLY in # $REPLY takes the numbers which is nice
1) # Show queue; ask for confirmation; if yes, send emails
send_mailqueue
break ;;
2) # Show queue
list_mailqueue
break ;;
3) # Switch online status
switch_conn
break ;;
4|"q") # exit silently, one can also press "q" instead of the number
exit 0
break ;;
esac
done
# ONLINE STATUS
function isonline {
if [ "$var_conn" = "off" ]; then
return 1
else
return 0
fi
}
# NUMBER OF UNSENT EMAILS
function check_mailqueue {
QUEUE=$(msmtp-listqueue.sh | grep -o "^From: " | wc -l)
OUT="$OUT;mq=$QUEUE"
@@ -45,35 +31,6 @@ function check_mailqueue {
fi
}
# MAIL QUEUE ACTIONS
function send_mailqueue {
msmtp-listqueue.sh
read -p "Send these queued mails? [Y/n]: " YN
if [[ $YN =~ ^(Y|y|)$ ]]; then
msmtp-runqueue.sh
else
echo "Not sending emails"
fi
}
function list_mailqueue {
msmtp-listqueue.sh
}
function switch_conn {
echo "Current connection status: $var_conn"
read -p "Switch connection status? [Y/n]: " YN
if [[ $YN =~ ^(Y|y|)$ ]]; then
if [ "$var_conn" == "off" ]; then
var_conn="on"
echo "Connection status switched to \"on\""
else
var_conn="off"
echo "Connection status switched to \"off\""
fi
else
echo "Connection status not changed."
fi
}
# SVN STATUS
function check_svn {
if isonline; then
@@ -93,33 +50,16 @@ function check_svn {
TOOL="$TOOL;svn=$SVN_REV"
}
function isonline {
if [ "$var_conn" = "off" ]; then
return 1
else
return 0
fi
}
# OUTPUT INFO ON STATUSBAR
check_mailqueue
check_svn
OUT=$(echo $OUT | sed -r 's/^;//')
OUT=$(echo $OUT | sed -r 's/;/ \| /g')
TOOL=$(echo $TOOL | sed -r 's/^;//')
TOOL=$(echo $TOOL | sed -r 's/;/ \| /g')
echo "<txt>$OUT</txt>"
echo "<tool>$TOOL</tool>"
echo "<img>/usr/share/icons/gnome/16x16/actions/format-justify-fill.png</img>"
echo "<click>xfce4-terminal -x $CURDIR/status-interaction.sh &</click>"
# DIRECT EXECUTE, CASE MENU
if [ "$1" == "exec" ]; then
while :; do
exec
wtmp; source "$TMP"
echo
done
else
# Show info on status bar
check_mailqueue
check_svn
OUT=$(echo $OUT | sed -r 's/^;//')
OUT=$(echo $OUT | sed -r 's/;/ \| /g')
TOOL=$(echo $TOOL | sed -r 's/^;//')
TOOL=$(echo $TOOL | sed -r 's/;/ \| /g')
echo "<txt>$OUT</txt>"
echo "<tool>$TOOL</tool>"
echo "<img>/usr/share/icons/gnome/16x16/actions/format-justify-fill.png</img>"
echo "<click>xfce4-terminal -x $0 exec &</click>"
wtmp
fi
wtmp