From 5eb07c8b3232af1e075598f58cc26ec1c5aa937f Mon Sep 17 00:00:00 2001 From: Ayush Agarwal Date: Sun, 27 Feb 2022 15:12:09 +0530 Subject: [PATCH] refactor: cleaner timer code, partial fix for #6 --- coffin.bash | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/coffin.bash b/coffin.bash index 9b91dd2..9664154 100755 --- a/coffin.bash +++ b/coffin.bash @@ -215,22 +215,24 @@ coffin_open() { } coffin_timer() { - local choice="$1" - local status + if ! command -v systemd-run > /dev/null 2>&1; then + coffin_die "systemd-run is not installed" + fi - status="$(systemctl --user is-active "$PROGRAM-coffin".timer)" - if [[ $status == "active" && -z $choice ]]; then - systemctl --user list-timers "$PROGRAM-coffin".timer \ - || coffin_die "Unable to print the timer status" - elif [[ $status == "active" && $choice == "stop" ]]; then - systemctl --user stop "$PROGRAM-coffin".timer > /dev/null 2>&1 \ - || coffin_die "Unable to stop the timer" - printf '%s\n' "[#] The timer to hide password store data has been stopped" - elif [[ $status == "inactive" && -z $choice ]]; then - coffin_die "The timer to hide password store isn't active" + local choice="$1" + if systemctl --user --quiet is-active "$PROGRAM"-coffin.timer 2> /dev/null; then + if [[ -z $choice ]]; then + coffin_head 2 <(systemctl --user list-timers "$PROGRAM"-coffin.timer) + elif [[ $choice == "stop" ]]; then + systemctl --user stop "$PROGRAM"-coffin.timer > /dev/null 2>&1 \ + || coffin_die "unable to stop the timer" + printf "%s\n" "the timer to create the coffin has been stopped" + fi else - coffin_die "An unknown error has occured. Please raise an issue on GitHub" + coffin_die "the timer to create the coffin isn't active" fi + + unset -v choice } coffin_head() {