4 ms·
I've settled on a couple of helper functions in bash to accomplish a similar thing (daily journaling): ####################################### # Normalizes
by chucksmash 8y ago
I've settled on a couple of helper functions in bash to accomplish a similar thing (daily journaling):
#######################################
# Normalizes date arguments
# Globals:
# None
# Arguments:
# date (defaults to today)
# Returns:
# string of format 'YYYY-MM-DD'
#######################################
function getDate {
local DATE=${1:-$(date -I)};
if [[ "${DATE}" =~ [+]+ ]]; then
DATE=$(date -I -d" ${DATE} days");
elif [[ "${DATE}" =~ ^- ]]; then
DATE=$(date -I -d" ${DATE} days");
elif [[ "${DATE}" == "tomorrow" ]]; then
DATE=$(date -I -d" +1 days");
elif [[ "${DATE}" == "yesterday" ]]; then
DATE=$(date -I -d" -1 days");
fi
echo "${DATE}";
}
#######################################
# Load a journal file
# Globals:
# None
# Arguments:
# date (defaults to today)
# Returns:
# None
#######################################
function journal {
local DATE=$(getDate "$1");
emacs ~/notes/journal/${DATE}.md;
}
- hk__2 8y agoNitpick: here you can use a `case` instead of `if [[ ... ]] elif [[ ... ]] elif ...`: case "$DATE" in +*|-*) DATE=$(date -I -d" $DATE days") ;; tomorrow) DATE=$(date -I -d" +1 days") ;; yesterday) DATE=$(date -I -d" -1 days") ;; esac