Last active
March 31, 2016 11:17
-
-
Save Bombe/a0b34d05c4b76cb000513e9898998381 to your computer and use it in GitHub Desktop.
days-left
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20170414120000 Revision 2017 (for Visitors) | |
20160701120000 Nordlicht 2016 | |
20160812120000 Evoke 2016 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# 3B8544DA-587F-4FA7-9AFC-CB96A2B8197B | |
currentTime="$(date +%s)" | |
currentMinTime="$((2**31-1))" | |
currentMinEvent="" | |
daysFile="${HOME}/.days" | |
while read time event; do | |
eventTime="$(date -jf %Y%m%d%H%M%S "${time}"0000 +%s 2> /dev/null)" | |
if [ "${eventTime}" -gt "${currentTime}" -a "${eventTime}" -lt "${currentMinTime}" ]; then | |
if [[ -z "${1}" || ( -n "${1}" && "${event}" =~ "${1}" ) ]]; then | |
currentMinTime="${eventTime}" | |
currentMinEvent="${event}" | |
fi | |
fi | |
done < "${daysFile}" | |
if [ -z "${currentMinEvent}" ]; then | |
exit | |
fi | |
daysLeft="$(((${currentMinTime} - ${currentTime})/86400))" | |
echo "${daysLeft} days left until ${currentMinEvent}." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Copy
days-left.sh
to somewhere in your PATH, copy.days
to your $HOME, and start adding entries you need to be remembered about. Callingdays-left.sh
will then tell you how many days are left until the next event in your list (they are sorted in the script, no need to sort them in the file).Tested on OS X only, GNU date might want different options.