rice/dots/.scripts/dwmstatus
2022-07-11 15:57:59 +03:00

98 lines
2.1 KiB
Bash
Executable file

#!/bin/sh
# create fifo
fifo="${XDG_RUNTIME_DIR}/statusupdated"
mkfifo "${fifo}"
function clean() {
echo "exit" > "${fifo}"
rm -rf ${fifo}
}
trap clean EXIT
extra=""
message=""
media_name=""
date_value=""
dark_medium="#282828"
dark_hard="#1d2021"
dark_soft="#32302f"
red="#ea6962"
green="#a9b665"
yellow="#d8a657"
blue="#7daea3"
magenta="#d3869b"
cyan="#89b482"
white="#d4be98"
clean() {
rm -f "${fifo}"
}
getstatus() {
data=""
if [ ! -z "${extra}" ]; then
data="${data}${extra}"
fi
if [ ! -z "${message}" ]; then
data="${data}^c${magenta}^  ^d^${message}"
fi
if [ ! -z "${media_name}" ]; then
data="${data}^c${magenta}^  ^d^${media_name}"
fi
if [ ! -z "${date_value}" ]; then
data="${data}^c${magenta}^  ^d^${date_value}"
fi
echo "${data}"
}
updatestatus() {
xsetroot -name "$(getstatus)"
}
while :
do
if read fifoline < $fifo; then
case "${fifoline}" in
set_message*)
# cuts after ::
# example: `set_message::nice day outside`
message="${fifoline##*::}"
;;
set_media_name*)
# cuts after ::
# example: `set_media_name::Song Name Goes Here`
media_name="${fifoline##*::}"
;;
set_date_value*)
# cuts after ::
# example: `set_date_value::Date Goes Here`
date_value="${fifoline##*::}"
;;
set_extra*)
# cuts after ::
# example `set_extra::something happened`
extra="${fifoline##*::}"
;;
update)
;;
exit)
echo "statusupdated: warn: got exit command, exiting..."
exit 1
;;
*) ;;
esac
updatestatus
fi
done &
# send the time string every 30 seconds through the FIFO
while :
do
echo "set_date_value::$(date '+%a %d %b %-I:%M')" > "${fifo}"
sleep 30
done