feat: list shows snoozed indicator with optional expiry date
This commit is contained in:
parent
793a1cd38a
commit
4524ce5cfd
2 changed files with 75 additions and 2 deletions
50
nag
50
nag
|
|
@ -727,6 +727,44 @@ _sweep_expired_snoozes() {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Usage:
|
||||||
|
# _get_snooze_display <id>
|
||||||
|
#
|
||||||
|
# Description:
|
||||||
|
# Set REPLY to a display string for the given alarm ID's snooze status.
|
||||||
|
# Returns " (snoozed)" for indefinite snoozes, " (snoozed until <date>)"
|
||||||
|
# for timed snoozes, or "" if the alarm is not snoozed.
|
||||||
|
_get_snooze_display() {
|
||||||
|
local _id="${1}"
|
||||||
|
REPLY=""
|
||||||
|
[[ -f "${_SNOOZED_FILE}" ]] || return 0
|
||||||
|
|
||||||
|
local _now _entry
|
||||||
|
_now="$(date +%s)"
|
||||||
|
|
||||||
|
while IFS= read -r _entry || [[ -n "${_entry}" ]]
|
||||||
|
do
|
||||||
|
[[ -n "${_entry}" ]] || continue
|
||||||
|
local _entry_key="${_entry%%$'\t'*}"
|
||||||
|
|
||||||
|
[[ "${_entry_key}" == "${_id}" ]] || continue
|
||||||
|
|
||||||
|
if [[ "${_entry}" == *$'\t'* ]]
|
||||||
|
then
|
||||||
|
local _expiry="${_entry#*$'\t'}"
|
||||||
|
if (( _expiry > _now ))
|
||||||
|
then
|
||||||
|
local _until_date
|
||||||
|
_until_date="$(date -d "@${_expiry}" "+%b %-d")"
|
||||||
|
REPLY=" (snoozed until ${_until_date})"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
REPLY=" (snoozed)"
|
||||||
|
fi
|
||||||
|
return 0
|
||||||
|
done < "${_SNOOZED_FILE}"
|
||||||
|
}
|
||||||
|
|
||||||
# Usage:
|
# Usage:
|
||||||
# _remove_snoozed_entry <key>
|
# _remove_snoozed_entry <key>
|
||||||
#
|
#
|
||||||
|
|
@ -816,7 +854,11 @@ _tag_list() {
|
||||||
|
|
||||||
_tag_display=" [${_tags//,/, }]"
|
_tag_display=" [${_tags//,/, }]"
|
||||||
|
|
||||||
printf "[%s]%s %s%s — %s\\n" "${_id}" "${_tag_display}" "${_human_time}" "${_rule_display}" "${_message}"
|
local _snooze_display
|
||||||
|
_get_snooze_display "${_id}"
|
||||||
|
_snooze_display="${REPLY}"
|
||||||
|
|
||||||
|
printf "[%s]%s %s%s%s — %s\\n" "${_id}" "${_tag_display}" "${_human_time}" "${_rule_display}" "${_snooze_display}" "${_message}"
|
||||||
done
|
done
|
||||||
|
|
||||||
if (( ! _matched ))
|
if (( ! _matched ))
|
||||||
|
|
@ -1443,7 +1485,11 @@ list() {
|
||||||
_tag_display=""
|
_tag_display=""
|
||||||
fi
|
fi
|
||||||
|
|
||||||
printf "[%s]%s %s%s — %s\\n" "${_id}" "${_tag_display}" "${_human_time}" "${_rule_display}" "${_message}"
|
local _snooze_display
|
||||||
|
_get_snooze_display "${_id}"
|
||||||
|
_snooze_display="${REPLY}"
|
||||||
|
|
||||||
|
printf "[%s]%s %s%s%s — %s\\n" "${_id}" "${_tag_display}" "${_human_time}" "${_rule_display}" "${_snooze_display}" "${_message}"
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -110,3 +110,30 @@ load test_helper
|
||||||
[ "${status}" -eq 0 ]
|
[ "${status}" -eq 0 ]
|
||||||
[[ "${output}" =~ "${_date},".*"far alarm" ]]
|
[[ "${output}" =~ "${_date},".*"far alarm" ]]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@test "list shows (snoozed) for indefinitely snoozed alarm" {
|
||||||
|
run_nag at "tomorrow 3pm" "take a break"
|
||||||
|
printf "1\\n" > "${NAG_DIR}/snoozed"
|
||||||
|
run_nag
|
||||||
|
[ "${status}" -eq 0 ]
|
||||||
|
[[ "${output}" =~ "(snoozed)" ]]
|
||||||
|
[[ "${output}" =~ "take a break" ]]
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "list shows (snoozed until DATE) for timed snooze" {
|
||||||
|
run_nag at "tomorrow 3pm" "take a break"
|
||||||
|
local _expiry_ts=$(( $(date +%s) + 86400 * 7 ))
|
||||||
|
printf "1\t%s\\n" "${_expiry_ts}" > "${NAG_DIR}/snoozed"
|
||||||
|
local _expiry_date
|
||||||
|
_expiry_date="$(date -d "@${_expiry_ts}" "+%b %-d")"
|
||||||
|
run_nag
|
||||||
|
[ "${status}" -eq 0 ]
|
||||||
|
[[ "${output}" =~ "snoozed until ${_expiry_date}" ]]
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "list does not show (snoozed) for unsnoozed alarm" {
|
||||||
|
run_nag at "tomorrow 3pm" "take a break"
|
||||||
|
run_nag
|
||||||
|
[ "${status}" -eq 0 ]
|
||||||
|
[[ ! "${output}" =~ "snoozed" ]]
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue