|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
|
|
|
thrd_ctrl () {
|
|
|
|
while true; do
|
|
|
|
if ! kill -0 "$1" 2>/dev/null; then
|
|
|
|
printf "Parent process died, I'm going to die too...\n"
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
sleep 1
|
|
|
|
done > "$NPIPE_IN"
|
|
|
|
}
|
|
|
|
|
|
|
|
term_process () {
|
|
|
|
if kill -0 "$PID_CTRL" 2>/dev/null; then
|
|
|
|
printf "Killing child process \"thrd_ctrl\" (PID %s)...\n" "$PID_CTRL"
|
|
|
|
kill "$PID_CTRL"
|
|
|
|
fi
|
|
|
|
#printf "Removing created FIFOs...\n"
|
|
|
|
#rm "$NPIPE_IN"
|
|
|
|
printf "Terminating the program...\n"
|
|
|
|
exit 0
|
|
|
|
}
|
|
|
|
|
|
|
|
trap_ctrlc () {
|
|
|
|
printf "Termination signal by the user (CTLR+C) detected...\n"
|
|
|
|
term_process
|
|
|
|
}
|
|
|
|
|
|
|
|
trap_sigterm () {
|
|
|
|
printf "Termination signal detected...\n"
|
|
|
|
term_process
|
|
|
|
}
|
|
|
|
|
|
|
|
trap "trap_ctrlc" 2
|
|
|
|
trap "trap_sigterm" 15
|
|
|
|
|
|
|
|
_pipe_dir="${XDG_RUNTIME_DIR:-/tmp/$(id -u)-runtime}/acejuice"
|
|
|
|
mkdir -p "$_pipe_dir"
|
|
|
|
NPIPE_IN="$_pipe_dir/main.sock"
|
|
|
|
unset _pipe_dir
|
|
|
|
|
|
|
|
if ! mkfifo "$NPIPE_IN" 2> /dev/null; then
|
|
|
|
printf "fifo '%s' already present\n" "$NPIPE_IN" >&2
|
|
|
|
fi
|
|
|
|
|
|
|
|
PID_SELF=$$
|
|
|
|
|
|
|
|
thrd_ctrl $PID_SELF &
|
|
|
|
PID_CTRL=$!
|
|
|
|
|
|
|
|
_monitor_list=""
|
|
|
|
_workspaces="..."
|
|
|
|
_date="..."
|
|
|
|
_battery="..."
|
|
|
|
_cputemp="..."
|
|
|
|
_network="..."
|
|
|
|
_audio="..."
|
|
|
|
|
|
|
|
|
|
|
|
__print_bar() {
|
|
|
|
# Print anyway even when the monitor is not specified
|
|
|
|
[ ! -n "$_monitor_list" ] && printf "%%{l}%s%%{c}%s%%{r}%s %s %s %s" "$_workspaces" "$_date" "$_cputemp" "$_network" "$_audio" "$_battery"
|
|
|
|
for _monitor_name in $_monitor_list; do
|
|
|
|
printf "%%{Sn%s}%%{l}%s%%{c}%s%%{r}%s %s %s %s" "$_monitor_name" "$_workspaces" "$_date" "$_cputemp" "$_network" "$_audio" "$_battery"
|
|
|
|
done
|
|
|
|
printf "\n"
|
|
|
|
}
|
|
|
|
|
|
|
|
msg_cmd_colon () {
|
|
|
|
#printf "CMD: \"%s\"\nCONTENT: \"%s\"\n" "$1" "$2"
|
|
|
|
case "$1" in
|
|
|
|
":SET")
|
|
|
|
case "$2" in
|
|
|
|
[A-Za-z0-9][A-Za-z0-9][A-Za-z0-9][A-Za-z0-9]" "*)
|
|
|
|
widget_content=${2##[A-Za-z0-9][A-Za-z0-9][A-Za-z0-9][A-Za-z0-9] }
|
|
|
|
#printf "WIDGET NAME: \"%s\"\nWIDGET CONTENT: \"%s\"\n" "${2% "$widget_content"}" "$widget_content"
|
|
|
|
case "${2% "$widget_content"}" in
|
|
|
|
"work")
|
|
|
|
_workspaces="${widget_content}"
|
|
|
|
;;
|
|
|
|
"date")
|
|
|
|
_date="${widget_content}"
|
|
|
|
;;
|
|
|
|
"cput")
|
|
|
|
_cputemp="${widget_content}"
|
|
|
|
;;
|
|
|
|
"netw")
|
|
|
|
_network="${widget_content}"
|
|
|
|
;;
|
|
|
|
"audi")
|
|
|
|
_audio="${widget_content}"
|
|
|
|
;;
|
|
|
|
"batt")
|
|
|
|
_battery="${widget_content}"
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
:
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
:
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
;;
|
|
|
|
":UST")
|
|
|
|
case "$2" in
|
|
|
|
"work")
|
|
|
|
_workspaces=""
|
|
|
|
;;
|
|
|
|
"date")
|
|
|
|
_date=""
|
|
|
|
;;
|
|
|
|
"cput")
|
|
|
|
_cputemp=""
|
|
|
|
;;
|
|
|
|
"netw")
|
|
|
|
_network=""
|
|
|
|
;;
|
|
|
|
"audi")
|
|
|
|
_audio=""
|
|
|
|
;;
|
|
|
|
"batt")
|
|
|
|
_battery=""
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
:
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
;;
|
|
|
|
":MON")
|
|
|
|
case "$2" in
|
|
|
|
"LIST "[A-Za-z0-9]*)
|
|
|
|
_monitor_list=${2##LIST }
|
|
|
|
#printf "MONITOR LIST: \"%s\"\n" "$_monitor_list"
|
|
|
|
;;
|
|
|
|
"ADD")
|
|
|
|
:
|
|
|
|
;;
|
|
|
|
"DEL")
|
|
|
|
:
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
:
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
:
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
__print_bar
|
|
|
|
}
|
|
|
|
|
|
|
|
while read -r line; do
|
|
|
|
case "$line" in
|
|
|
|
:[A-Za-z0-9][A-Za-z0-9][A-Za-z0-9]" "*)
|
|
|
|
content=${line##:[A-Za-z0-9][A-Za-z0-9][A-Za-z0-9] }
|
|
|
|
msg_cmd_colon "${line% "$content"}" "${content}"
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
:
|
|
|
|
#printf "%s\n" "$line"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done < "$NPIPE_IN"
|