First versions of the binaries and source file.
This commit is contained in:
parent
d2630d6e4f
commit
1dfda10ddc
11 changed files with 742 additions and 0 deletions
52
newday
Executable file
52
newday
Executable file
|
|
@ -0,0 +1,52 @@
|
|||
#!/bin/bash
|
||||
# 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.
|
||||
|
||||
BINSELF=$(basename $0)
|
||||
DIR_NAME=ByDate
|
||||
ROOT_DIR=$HOME/$DIR_NAME
|
||||
TODAY_SYM=$HOME/Today
|
||||
|
||||
# Present day
|
||||
TODAY=$(date --iso-8601)
|
||||
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"
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue