55 lines
1.4 KiB
Bash
Executable file
55 lines
1.4 KiB
Bash
Executable file
#!/bin/sh
|
|
# This script is intended to be run via cron.
|
|
|
|
# It creates a folder structure in home for the current date in the following format:
|
|
# $HOME/ByDate/<Year>/<Month>/<Day>
|
|
|
|
# It also sets up a symlink in home: $HOME/Today
|
|
# This symlink will always point to the folder for the current date.
|
|
|
|
# Finally, it removes any folders without data, to prevent clutter.
|
|
|
|
# - Why did you make this?
|
|
# I remember things better when they have a date attached to them.
|
|
# You can use this for a primitive form of note-taking, but aside from notes -
|
|
# you can store any data this way.
|
|
|
|
DAISY_INTERNAL=1
|
|
. $(dirname $(realpath $0))/daisy.source
|
|
|
|
BINSELF=$(basename $0)
|
|
DIR_NAME=ByDate
|
|
ROOT_DIR=$HOME/$DIR_NAME
|
|
TODAY_SYM=$HOME/Today
|
|
|
|
# Present day
|
|
TODAY=$(date -I)
|
|
YEAR=$(echo $TODAY | awk -F"-" '{print $1}')
|
|
MONTH=$(echo $TODAY | awk -F"-" '{print $2}')
|
|
DAY=$(echo $TODAY | awk -F"-" '{print $3}')
|
|
|
|
set -e
|
|
|
|
function errorFn()
|
|
{
|
|
ERROR=$?
|
|
if [[ $ERROR -gt 0 ]];
|
|
then
|
|
echo "$BINSELF error ($ERROR): "
|
|
perl -E 'say $!=shift' $ERROR
|
|
fi
|
|
exit $ERROR
|
|
}
|
|
|
|
# Error handling
|
|
trap errorFn ERR
|
|
|
|
# First we clear out empty folders, and remove the symlink if it exists
|
|
test -e "$ROOT_DIR" && find "$ROOT_DIR" -maxdepth 3 -type d -empty -print | xargs rm -rf
|
|
test -L "$TODAY_SYM" && rm -rf "$TODAY_SYM"
|
|
|
|
# Now we can set up today's directory
|
|
mkdir -p "$ROOT_DIR/$YEAR/$MONTH/$DAY"
|
|
cd $ROOT_DIR
|
|
ln -s "./$DIR_NAME/$YEAR/$MONTH/$DAY" "$TODAY_SYM"
|
|
exitcode=@?
|