From 07bb9657fad1512d0fc8107d71d4fe3cb66a6602 Mon Sep 17 00:00:00 2001 From: quak Date: Sat, 7 Jun 2025 18:02:11 +0200 Subject: [PATCH] (scripts) added script to check if a service is running, added script to set a reminder with `at(d)` --- scripts/process-status.sh | 42 ++++++++++++++++++++++++++++++++++++ scripts/readme.md | 3 +-- scripts/reminder.sh | 37 +++++++++++++++++++++++++++++++ scripts/select-audio-sink.sh | 2 +- 4 files changed, 81 insertions(+), 3 deletions(-) create mode 100644 scripts/process-status.sh create mode 100755 scripts/reminder.sh diff --git a/scripts/process-status.sh b/scripts/process-status.sh new file mode 100644 index 0000000..9206d24 --- /dev/null +++ b/scripts/process-status.sh @@ -0,0 +1,42 @@ +#!/usr/bin/env bash + +get_process_status() { + if (($# != 1)); then + echo "get_process_status() takes exactly ONE argument" + return 1 + fi + if ! status="$(systemctl status "$*")"; then + echo "could not find a process named [$*]" + return 1 + fi + if ! status="$(echo "${status}" | grep -P "Active:")"; then + echo "failed to find line" + return 1 + fi + if ! status="$(echo "${status}" | grep -oP "(?<=\()\w+(?=\))")"; then + echo "failed to find status" + return 1 + fi + echo "${status}" + return 0 +} + +check_process_status() { + if (($# != 1)) && [[ -z "${stdin}" ]]; then + echo "check_process_status() takes exactly ONE argument != #$#" + return 1 + fi + if [[ "$1" == "-" ]]; then + input="$(cat)" + else + input="$1" + fi + if [[ "${input}" != "running" ]]; then + return 1 + fi + return 0 +} + +is_process_running() { + get_process_status "$*" | check_process_status - >/dev/null 2>&1 +} diff --git a/scripts/readme.md b/scripts/readme.md index d3cc530..bf0b4f8 100644 --- a/scripts/readme.md +++ b/scripts/readme.md @@ -1,6 +1,5 @@ # TODOs +* try `$*` in navigation-setup script! * `select-audio-sink.sh` * [ ] mark currently selected sink -* add timer script with `at` - * .. `echo 'notify-send "title" "message"' | at 22:59` .. diff --git a/scripts/reminder.sh b/scripts/reminder.sh new file mode 100755 index 0000000..ccbeb84 --- /dev/null +++ b/scripts/reminder.sh @@ -0,0 +1,37 @@ +#!/usr/bin/env bash + +source process-status.sh + +set_reminder() { + message_reminder=$( + cat <<'EOF' +enter reminder message to display when the timer rings +EOF + ) + message_time="$( + cat <<'EOF' +enter reminder time in one of the following formats: + `18:00` + `