I am
- too forgetful to recall what I just saw
- too lazy to redirect the output of slow, resource-hungry utilities
every time I run them
- too impatient to scroll back in search for the once displayed
information
After I ran 'recent' a couple of times yesterday, _patiently_ waiting
for it to run through all the directiories and to gather all the
information I decided to add some layer of local caching to the existing
utility.
At first as a one-liner shell function for bash, then a bit more robust
version for (hopefully all) descendants of /bin/sh...
Voila...
#---- cache-recent.function ---
# Adds caching to RTC's 'recent' utility
# source the file from command line or your profile
#
# Usage: recent [-f]
# -f refresh the cache
#
recent () {
# some housekeeping first
umask 7077
CACHEDIR="${HOME}/.cache/rtc/"
C="${CACHEDIR}/recent"
[ -d "${CACHEDIR}" ] || mkdir -p "${CACHEDIR}"
# Use cached version if:
# - user didn't force refresh with '-f' switch
# - cache file exists and is readable
# - cache file isn't older than 15 minutes
if [ "$1" != "-f" ] && [ -r "$C" ] && \
[ $((($(date +%s) - $(date +%s -r "$C"))/ 60)) -lt 15 ]; then
cat "$C"
else
command recent > "$C"
cat "$C"
fi
}
#---- eof ---