Major chhanges: daisy.source renamed to ld.source.
All files have been prettified by making sure we use 2-space indent. agenda: Instead of the hidden .tree file, a file created "More..." is made. You can use (ex) "agenda --view "2026" to get a full list of files from that year/date/day. Additionally, minor fixes have been made. clip: You can now use "-c" to clear the clipbaord.
This commit is contained in:
parent
056ab01ed4
commit
ab730db2f7
14 changed files with 264 additions and 534 deletions
93
agenda
93
agenda
|
|
@ -1,39 +1,15 @@
|
|||
#!/usr/bin/env bash
|
||||
# This script is intended to be run via cron.
|
||||
# This script is intended to be run via cron. But you can run it manually as
|
||||
# well
|
||||
|
||||
# It creates a folder structure in home for the current date in the following format:
|
||||
# $HOME/<Tag>/<Year>/<Month>/<Day>
|
||||
# <Dir>/<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
|
||||
|
||||
dir=$(realpath -s "$1")
|
||||
parent_dir=$(dirname "$dir")
|
||||
name=$(basename "$dir")
|
||||
root_dir="$parent_dir/.daisy/$name"
|
||||
today_sym="$dir"
|
||||
|
||||
# Present day
|
||||
read year month day < <(date "+%Y %m %d")
|
||||
today="$root_dir/$year/$month/$day"
|
||||
|
||||
set -e
|
||||
|
||||
function errorFn
|
||||
|
|
@ -50,11 +26,70 @@ function errorFn
|
|||
# Error handling
|
||||
trap errorFn ERR
|
||||
|
||||
# Source LD
|
||||
LD_INTERNAL=1
|
||||
. $(dirname $(realpath $0))/ld.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
|
||||
|
||||
view=0
|
||||
view_date=0
|
||||
|
||||
if [[ "$1" == "--view" ]]; then
|
||||
# We are only going to view the agenda
|
||||
view_date=$2
|
||||
view=1
|
||||
shift 2
|
||||
fi
|
||||
|
||||
dir=$(realpath -s "$1")
|
||||
parent_dir=$(dirname "$dir")
|
||||
name=$(basename "$dir")
|
||||
root_dir="$parent_dir/.daisy/$name"
|
||||
today_sym="$dir"
|
||||
|
||||
# Present day
|
||||
read year month day < <(date "+%Y %m %d")
|
||||
today="$root_dir/$year/$month/$day"
|
||||
|
||||
# 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 -delete
|
||||
if test -e "$root_dir"; then
|
||||
find "$root_dir" -name "More..." -delete
|
||||
find "$root_dir" -depth -maxdepth 3 -type d \
|
||||
-not -path "$today" \
|
||||
-exec sh -c '
|
||||
if [ $(ls -A "$1" | wc -l) -eq 0 ]; then
|
||||
rm -rf "$1"
|
||||
fi
|
||||
' _ {} \;
|
||||
fi
|
||||
|
||||
if [[ $view == 1 ]]; then
|
||||
# View mode
|
||||
[[ ! -d "$root_dir/$view_date" ]] && echo "This date entry does not exist." && exit 1
|
||||
view_date="$root_dir/$view_date"
|
||||
|
||||
# 1. -name "*.squashfs" -prune: If a folder ends in .squashfs, don't descend into it.
|
||||
# 2. ! -name "*.squashfs": Inside the directory check, ignore squashfs files.
|
||||
# 3. --ignore="*.squashfs": Tells ls to hide those entries from the final list.
|
||||
find "$(realpath "$view_date")" -name "*.squashfs" -prune -o -type d -exec sh -c '
|
||||
find "$1" -maxdepth 1 -type f ! -name "*.squashfs" | read -r
|
||||
' _ {} \; -exec ls --color=always -lah --ignore="*.squashfs" {} + 2>/dev/null
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Now we can set up today's directory
|
||||
mkdir -p "$today"
|
||||
ln -snf "$today" "$today_sym"
|
||||
ln -snf "$root_dir" "$dir/.tree"
|
||||
ln -snf "$root_dir" "$dir/More..."
|
||||
exitcode=$?
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue