From 87802c84f3dd70e682d5f05afe59ab0807cf0bd6 Mon Sep 17 00:00:00 2001 From: meliurwen Date: Thu, 11 Aug 2022 13:42:04 +0200 Subject: [PATCH] More or less everything works --- .local/bin/acejuice | 161 +++++++++++++++++++++++++++++++++++ .local/bin/acejuice-interval | 35 ++++++++ .stow-local-ignore | 3 + LICENSE | 21 +++++ 4 files changed, 220 insertions(+) create mode 100755 .local/bin/acejuice create mode 100755 .local/bin/acejuice-interval create mode 100644 .stow-local-ignore create mode 100644 LICENSE diff --git a/.local/bin/acejuice b/.local/bin/acejuice new file mode 100755 index 0000000..14cbeb0 --- /dev/null +++ b/.local/bin/acejuice @@ -0,0 +1,161 @@ +#!/bin/sh + +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 + +mkfifo "$NPIPE_IN" 2> /dev/null || printf "fifo already present\n" + +PID_SELF=$$ + +thrd_ctrl $PID_SELF & +PID_CTRL=$! + +_monitor_list="" +_workspaces="..." +_date="..." +_battery="..." +_cputemp="..." +_network="..." +_audio="..." + + +__print_bar() { + 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" diff --git a/.local/bin/acejuice-interval b/.local/bin/acejuice-interval new file mode 100755 index 0000000..73aee11 --- /dev/null +++ b/.local/bin/acejuice-interval @@ -0,0 +1,35 @@ +#!/bin/sh + +set -e + +__send_cmd () { + printf "%s %s\n" "$1" "$2" > "$NPIPE_OUT" +} + +_pipe_dir="${XDG_RUNTIME_DIR:-/tmp/$(id -u)-runtime}/acejuice" +mkdir -p "$_pipe_dir" +NPIPE_OUT="$_pipe_dir/main.sock" +unset _pipe_dir + +mkfifo "$NPIPE_IN" 2> /dev/null || printf "fifo already present\n" + +cycle=0 + +while true; do + if [ $((cycle%4)) = 0 ]; then + __send_cmd ":SET netw" "$($HOME/.config/screen/bin/netinfo.sh --color lemonbar --icon nerd)" + __send_cmd ":SET cput" "$($HOME/.config/screen/bin/cputemp.sh --color lemonbar --icon nerd --unit)" + fi + if [ $((cycle%4)) = 0 ]; then + __send_cmd ":SET date" "$(date +'%a %d %b %H:%M')" + fi + if [ $((cycle%16)) = 0 ]; then + __send_cmd ":SET batt" "$($HOME/.config/screen/bin/battery.sh --color lemonbar --unit --icon nerd --symbols ascii)" + fi + + cycle=$((cycle+1)) + if [ $cycle = 1024 ]; then + cycle=0 + fi + sleep 1 +done diff --git a/.stow-local-ignore b/.stow-local-ignore new file mode 100644 index 0000000..268157d --- /dev/null +++ b/.stow-local-ignore @@ -0,0 +1,3 @@ +^/README.* +^/LICENSE.* +^/COPYING diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..0c368c5 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2022 Meliurwen + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE.