(scripts) added script to check if a service is running, added script to
set a reminder with `at(d)`
This commit is contained in:
42
scripts/process-status.sh
Normal file
42
scripts/process-status.sh
Normal file
@@ -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
|
||||||
|
}
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
# TODOs
|
# TODOs
|
||||||
|
|
||||||
|
* try `$*` in navigation-setup script!
|
||||||
* `select-audio-sink.sh`
|
* `select-audio-sink.sh`
|
||||||
* [ ] mark currently selected sink
|
* [ ] mark currently selected sink
|
||||||
* add timer script with `at`
|
|
||||||
* .. `echo 'notify-send "title" "message"' | at 22:59` ..
|
|
||||||
|
|||||||
37
scripts/reminder.sh
Executable file
37
scripts/reminder.sh
Executable file
@@ -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`
|
||||||
|
`<time> + 5 minutes` - time can be `now`
|
||||||
|
EOF
|
||||||
|
)"
|
||||||
|
|
||||||
|
if ! is_process_running "atd.service"; then
|
||||||
|
notify-send "ERROR" "[atd.service] is not running"
|
||||||
|
fi
|
||||||
|
|
||||||
|
reminder="$(rofi -dmenu -theme ~/.config/rofi/themes/command-runner-blue.rasi -mesg "${message_reminder}")"
|
||||||
|
if [[ -z "${reminder}" ]]; then return 1; fi
|
||||||
|
|
||||||
|
time="$(rofi -dmenu -theme ~/.config/rofi/themes/command-runner-blue.rasi -mesg "${message_time}")"
|
||||||
|
if [[ -z "${time}" ]]; then return 1; fi
|
||||||
|
|
||||||
|
if ! $(echo "notify-send '${reminder}'" | at "${time}"); then
|
||||||
|
notify-send "failed to set reminder"
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
|
notify-send "set reminder at ${time}"
|
||||||
|
}
|
||||||
|
|
||||||
|
set_reminder
|
||||||
@@ -13,7 +13,7 @@ select_audio_sink() {
|
|||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
selection="$(printf "%s\n" "${names[@]//\"/}" | rofi -case-smart -dmenu)"
|
selection="$(printf "%s\n" "${names[@]//\"/}" | rofi -dmenu -i --only-match)"
|
||||||
|
|
||||||
unset number
|
unset number
|
||||||
for n in ${!names[@]}; do
|
for n in ${!names[@]}; do
|
||||||
|
|||||||
Reference in New Issue
Block a user