- Change shebangs to use 'env' in prep for NixOS (and others) - `agenda` now has a symlink to the underlying tree structure named ".tree" - `binbox` has more checking, being prepped for automatic export of symlinks. - `cdz` now symlinks to the archive directory using "<archive name>.tmp". This is less confusing than a randomized extraction folder, and adds the benefit of being in the FS-tree of the original archive. - daisy.source changes: > Added basic debug mode. > `ched` can now set global (all of the shell) editor or local (lackadaisical utils only) editor. > The encoding/decoding functions have been expanded and improved. Extra checking, permissions are stored as well, `daisy_dec` can handle stdin. - Added new functions to manage lackadaisical config: daisy_backup (runs `bak` on config files), daisy_clear (removes config files), and daisy_restore (restores config files archived using bak). - All functions/tools prefixed with 'daisy_' are now also available prefixed with 'ld_' instead - Added a new utility, `clip`. This utility keeps a local variable that can be set if given args and get if no args are supplied. Basically a simple clipboard local to the ptty. Supports stdin.
60 lines
1.7 KiB
Bash
Executable file
60 lines
1.7 KiB
Bash
Executable file
#!/usr/bin/env 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/<Tag>/<Year>/<Month>/<Day>
|
|
|
|
# It also sets up a symlink for the tagged folder.
|
|
# This symlink will always point to the folder for the current date.
|
|
|
|
# Finally, it removes any folders without data, to prevent clutter.
|
|
|
|
LD_INTERNAL=1
|
|
. $(dirname $(realpath $0))/daisy.source
|
|
|
|
if [[ $1 == '' ]]; then
|
|
echo "Usage: $LD_BIN <folder>"
|
|
echo "Creates a folder within '.daisy' in the current directory containing"
|
|
echo "a tree of dates associated with the folder name given by argument."
|
|
echo "A symlink is (re-)created at the same time with the same folder name."
|
|
echo "For example, if given the folder 'notes', this utility will:"
|
|
echo "- Create a folder '/.daisy/notes/<year>/<month>/<day>'."
|
|
echo "- Create a symlink named 'notes' that points to it."
|
|
echo "It is recommended to run this via cron."
|
|
exit 1
|
|
fi
|
|
|
|
root_dir=$(dirname $1)/.daisy/$(basename $1)
|
|
today_sym=$1
|
|
|
|
# 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 "$LD_BIN 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"
|
|
ln -s "$root_dir/$year/$month/$day" "$today_sym"
|
|
ln -s "$root_dir" "$today_sym/.tree"
|
|
exitcode=@?
|