Modify to use with Genmon XFCE panel plugin

Genmon does not allow to pass arguments thus I need to hardcode sunrise
and sunset values.

https://docs.xfce.org/panel-plugins/xfce4-genmon-plugin
This commit is contained in:
bimlas 2020-04-09 11:32:12 +02:00
parent 18b894fe34
commit 8794189bbf

View file

@ -1,24 +1,25 @@
#!/bin/bash #!/bin/bash
TEXT='<span size="xx-large">&#x262F;</span>'
SUNRISE='8:00'
SUNSET='18:00'
function show_usage() function show_usage()
{ {
progname=`basename "$0"` progname=`basename "$0"`
echo "$progname [night|day|toggle] (defaults to 'toggle')" echo "$progname [night|day|toggle]"
echo "$progname SUNRISE SUNSET (e.g. '8:00 18:00')" echo "Without parameters it will set dark theme from $SUNSET to $SUNRISE"
} }
function parse_args() function parse_args()
{ {
case $# in case $# in
0) 0)
echo 'toggle' _get_mode_by_time
;; ;;
1) 1)
echo "$1" echo "$1"
;; ;;
2)
_get_mode_by_time "$1" "$2"
;;
*) *)
exit 1 exit 1
esac esac
@ -27,10 +28,8 @@ function parse_args()
function _get_mode_by_time() function _get_mode_by_time()
{ {
now=`date +"%H%M"` now=`date +"%H%M"`
sunrise="${1/:/}"
sunset="${2/:/}"
if [ $now -ge $sunrise -a $now -le $sunset ]; then if [ $now -ge "${SUNRISE/:/}" -a $now -le "${SUNSET/:/}" ]; then
echo 'day' echo 'day'
else else
echo 'night' echo 'night'
@ -41,7 +40,7 @@ function set_night_mode()
{ {
current_theme=`xfconf-query -c $2 -p $3` current_theme=`xfconf-query -c $2 -p $3`
if ( _is_mode_already_set "$current_theme" "$1" ); then if ( _is_mode_already_set "$current_theme" "$1" ); then
exit 0 return
fi fi
new_theme=`_set_$1 "$current_theme" 2> /dev/null` new_theme=`_set_$1 "$current_theme" 2> /dev/null`
@ -106,3 +105,7 @@ set_night_mode $mode xsettings /Net/IconThemeName
# Window manager theme # Window manager theme
# set_night_mode $mode xfwm4 /general/theme # set_night_mode $mode xfwm4 /general/theme
echo "<txt>$TEXT</txt>"
echo "<txtclick>$0 toggle</txtclick>"
echo "<tool>Night mode: $SUNSET - $SUNRISE</tool>"