Minor order of operations changes and var name consistency (lower-case)
This commit is contained in:
parent
03303c9e36
commit
434a50987e
9 changed files with 236 additions and 208 deletions
35
newday
35
newday
|
|
@ -17,39 +17,38 @@
|
|||
DAISY_INTERNAL=1
|
||||
. $(dirname $(realpath $0))/daisy.source
|
||||
|
||||
BINSELF=$(basename $0)
|
||||
DIR_NAME=ByDate
|
||||
ROOT_DIR=$HOME/$DIR_NAME
|
||||
TODAY_SYM=$HOME/Today
|
||||
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}')
|
||||
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 ]];
|
||||
error=$?
|
||||
if [[ $error -gt 0 ]];
|
||||
then
|
||||
echo "$BINSELF error ($ERROR): "
|
||||
perl -E 'say $!=shift' $ERROR
|
||||
echo "$DAISY_BIN error ($error): "
|
||||
perl -E 'say $!=shift' $error
|
||||
fi
|
||||
exit $ERROR
|
||||
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"
|
||||
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"
|
||||
mkdir -p "$root_dir/$year/$month/$day"
|
||||
cd $root_dir
|
||||
ln -s "./$dir_name/$year/$month/$day" "$today_sym"
|
||||
exitcode=@?
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue