From 1d67fba8d0f36c28070297afa9e3f0cdf7f5a959 Mon Sep 17 00:00:00 2001 From: Akemi Izuko Date: Sun, 23 Feb 2025 14:24:33 -0700 Subject: [PATCH] Bash: get last update time script --- bin/get_last_update.sh | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100755 bin/get_last_update.sh diff --git a/bin/get_last_update.sh b/bin/get_last_update.sh new file mode 100755 index 0000000..d5fe118 --- /dev/null +++ b/bin/get_last_update.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env bash +# Gets the time of the last archlinux update. + +declare -i last_time="$( + rg -B1 'pacman -S(u|[yu]{2})$' "${HOME}/.bash_eternal_history" \ + | tac \ + | awk '$0 ~ /^#/ { print substr($0, 2); exit }' +)" +declare -i now="$(date '+%s')" + +declare last_time_fmt="$(date -d "@${last_time}" "+%Y-%m-%d %H:%M:%S")" +declare days_ago="$(( (now-last_time)/(3600*24) ))" + +printf 'Last updated at %s | %d days ago\n' "$last_time_fmt" "$days_ago"