Skip to content

Commit

Permalink
refactor: cleaner timer code, partial fix for #6
Browse files Browse the repository at this point in the history
  • Loading branch information
ayushnix committed Feb 27, 2022
1 parent 8cb2254 commit 5eb07c8
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions coffin.bash
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 5eb07c8

Please sign in to comment.