Compare commits

..

No commits in common. '4477b9907c25a3eae6a4758dd174648ffed44d8f' and 'c70aa389a56a0b7dd35830476af42f1e30966d88' have entirely different histories.

  1. 174
      cl

174
cl

@ -35,10 +35,6 @@ $0 - Captain's log
Directories created under $BASEDIR are treated as profiles (if they exist). The default profile is assumed to be 'default'.
Specify -p <profile> as the first argument to $0 to operate on a different one
Run with "asset" to spin up a new empty file with an asset tag. This is currently assumed to be plain text that complements the log, but makes little sense to included.
At some point this will be expanded to handle other files
Run with "asset <ID>" to open said asset.
Run with "review" ($0 review), and you will get a rundown of complete and incomplete tasks for the week.
Optionally, supply with date-compatible strings as "$0 review <start> [end] to use a range, end defaults to yesterday
@ -62,6 +58,7 @@ EOF
}
function review() {
shift
DATE_START=${1:-"-7 days"}
DATE_END=${2:-"yesterday"}
@ -103,7 +100,8 @@ function review() {
}
function schedule() {
if [ ${1:--1} -eq -1 ] || [ "$1" == "edit" ]; then
shift
if [ "$1" == "edit" ]; then
if [ -f "$CLDIR/schedule"* ];then
vi -p "$CLDIR/schedule"*
@ -148,55 +146,25 @@ function captains_log() {
# Create files if they don't exist
if [ ${1-x} == 'x' ]; then
for i in YESTERDAY TODAY TOMORROW; do
generate_file ${!i}
done
if [ -f "$CLDIR/backlog" ]; then
vi $CLDIR/{$YESTERDAY,$TODAY,$TOMORROW,backlog} -s <( echo -e ":vsplit\n:wincmd w\n:next\n:vsplit\n:wincmd w\n:next\n:split\n:wincmd w\n:next")
else
vi -O $CLDIR/{$YESTERDAY,$TODAY,$TOMORROW}
fi
else
generate_file $1
vi $CLDIR/$(date -d "$1" "+%F")
fi
asset generate_links
if [ $GIT -ne 0 ]; then
echo Updating git...
if [ $( git -C "$CLDIR" status -s |wc -l) -ne 0 ]; then
git -C "$CLDIR" add -A
git -C "$CLDIR" commit -qm "Auto-Commit by $(basename $0)"
git -C "$CLDIR" push -q
fi
fi
}
function generate_file() {
# Create files if they don't exist
F=$(date -d "${1:-$(date +%F)}" "+%F")
if ! [ -f "$CLDIR/${F}" ]; then
for i in YESTERDAY TODAY TOMORROW; do
if ! [ -f "$CLDIR/${!i}" ]; then
# If there's a template and it's executable, execute it and output the result to the file,
# If it's not executable, replate {{DATE <date-compatible formate>}} with said date/formate
# Otherwise do the boilerplate
debug "File $F doesn't exist, creating it"
debug "File $i doesn't exist, creating it"
if [ -x "$CLDIR/template" ]; then
debug "From executable template"
"$CLDIR/template" > $CLDIR/${F}
"$CLDIR/template" > $CLDIR/${!i}
elif [ -f "$CLDIR/template" ]; then
DATE_ARGS="$(grep '{{DATE[^}]*}}' "$CLDIR/template"|tr -d {}|cut -d' ' -f2-)"
if [ "$DATE_ARGS" == 'DATE' ]; then DATE_ARGS='%A %d %B %Y'; fi
debug "From static template with DATE_ARGS=$DATE_ARGS"
sed "s/{{DATE[^}]*}}/$(date "+$DATE_ARGS" -d ${F})/g" $CLDIR/template > $CLDIR/${F}
sed "s/{{DATE[^}]*}}/$(date "+$DATE_ARGS" -d ${!i})/g" $CLDIR/template > $CLDIR/${!i}
else
echo -e "$(date "+%A %d %B %Y" -d ${!F})\nWhat do you want to accomplish today?\n\nWhat are your notes for today?\n\nWhat do you need to follow up tomorrow?\n" > "$CLDIR/${!F}"
echo -e "$(date "+%A %d %B %Y" -d ${!i})\nWhat do you want to accomplish today?\n\nWhat are your notes for today?\n\nWhat do you need to follow up tomorrow?\n" > "$CLDIR/${!i}"
fi
fi
done
# Read from the "scheduled" file, and put lines into the appropriate file if extant
@ -205,19 +173,21 @@ function generate_file() {
SCHEDULED=0
SCHED=$(echo $line|cut -d' ' -f1)
TASK=$(echo $line|cut -d' ' -f2-)
# Check if the schedule is DATE_FORMAT=MATCH_EXPRESSION otherwise assume %F
if ( [[ "$SCHED" =~ = ]] && [[ "$( date "+$(echo "$SCHED"|cut -d'=' -f1)" -d "${F}" )" =~ $(echo $SCHED |cut -d'=' -f2-) ]] ) || ( ! [[ "$SCHED" =~ = ]] && [ "$(date +%F -d $SCHED)" == "${F}" ] ); then
if ! grep -qE "^Scheduled to Review today:" "$CLDIR/${F}"; then
echo "Scheduled to Review today:" >> "$CLDIR/${F}"
fi
if ! grep -qE "^ . $TASK" "$CLDIR/${F}";then
echo " - $TASK" >> "$CLDIR/${F}"
fi
if ! [[ "$SCHED" =~ = ]]; then
SCHEDULED=1
for i in YESTERDAY TODAY TOMORROW; do
# Check if the schedule is DATE_FORMAT=MATCH_EXPRESSION otherwise assume %F
if ( [[ "$SCHED" =~ = ]] && [[ "$( date "+$(echo "$SCHED"|cut -d'=' -f1)" -d "${!i}" )" =~ $(echo $SCHED |cut -d'=' -f2-) ]] ) || ( ! [[ "$SCHED" =~ = ]] && [ "$(date +%F -d $SCHED)" == "${!i}" ] ); then
if ! grep -qE "^Scheduled to Review today:" "$CLDIR/${!i}"; then
echo "Scheduled to Review today:" >> "$CLDIR/${!i}"
fi
if ! grep -qE "^ . $TASK" "$CLDIR/${!i}";then
echo " - $TASK" >> "$CLDIR/${!i}"
fi
if ! [[ "$SCHED" =~ = ]]; then
SCHEDULED=1
fi
fi
fi
done
if [ $SCHEDULED -eq 0 ]; then
echo "$line" >> "$CLDIR/scheduled.tmp"
fi
@ -230,91 +200,23 @@ function generate_file() {
if [ -f "$CLDIR/scheduled.tmp" ]; then
mv "$CLDIR/scheduled.tmp" "$CLDIR/scheduled"
fi
}
function asset_generate_links() {
# Either do files modified in the last 7 days, or all files
if [ "$1" == "all" ]; then
MTIME=''
if [ -f "$CLDIR/backlog" ]; then
vi $CLDIR/{$YESTERDAY,$TODAY,$TOMORROW,backlog} -s <( echo -e ":vsplit\n:wincmd w\n:next\n:vsplit\n:wincmd w\n:next\n:split\n:wincmd w\n:next")
else
MTIME='-mtime -7'
vi -O $CLDIR/{$YESTERDAY,$TODAY,$TOMORROW}
fi
# Exclude things we don't care about (swap files, git, the db itself)
FILES=$(find ~/.captains_log/default/ -type f $MTIME \! \( -iname *.sw* -o -wholename "*/.git*" -wholename "*/assets/db" \))
# Look for references to assets
MATCHES="$(grep -oE '\[?ASSET:)?[a-zA-Z0-9]+\]?' $FILES)"
while read line; do
# Nicely format things
FILE="$(echo $line | cut -d':' -f1)"
FILE="${FILE#$CLDIR/}"
REF="$(echo $line|cut -d ':' -f2-|grep -oE '[a-zA-Z0-9]{8}')"
# Assets contain a self reference so that it can be easily copied while editing. Ignore these refs
if ! [[ "$REF" =~ $(basename $FILE 2>/dev/null) ]]; then
DB_STRING="$REF:link $FILE"
#Add it to the DB if it's not already there
if ! grep -q "$DB_STRING" $ADB 2>/dev/null; then
echo $DB_STRING >> $ADB
fi
fi
done < <(echo "$MATCHES")
}
function asset() {
export ASSET_DIR="$CLDIR/assets/"
export ADB="$ASSET_DIR/db"
while [ $1 ]; do
case $1 in
generate_links) shift; asset_generate_links $@; return;;
*) break;;
esac
done
if [ ${1:-0} != 0 ]; then
if [[ $1 =~ (\[?ASSET:)?[a-zA-Z0-9]+\]? ]]; then
ID="$(echo "$1"|grep -oE '[a-zA-Z0-9]{8}')"
vi "$ASSET_DIR/$ID"
fi
else
if ! [ -d "$ASSET_DIR" ]; then
mkdir "$ASSET_DIR"
touch $ADB
if [ $GIT -ne 0 ]; then
echo Updating git...
if [ $( git -C "$CLDIR" status -s |wc -l) -ne 0 ]; then
git -C "$CLDIR" add -A
git -C "$CLDIR" commit -qm "Auto-Commit by $(basename $0)"
git -C "$CLDIR" push -q
fi
# Generate a random ID that doesn't already exist
while grep -qi "$ID" "${ADB}"; do
ID="$(openssl rand -hex 4)"
# Alternatively
#hexdump -n 4 -e '/4 "%08X" 1 "\n"' /dev/urandom
done
echo "$ID:type text" >> "$ADB"
echo "[ASSET:$ID]" > "$ASSET_DIR/$ID"
vi "$ASSET_DIR/$ID"
fi
}
BASEDIR="$HOME/.captains_log"
# Check if there are any profiles, otherwise just use the basedir
@ -323,20 +225,16 @@ if [ "$(find $BASEDIR -type d|wc -l)" -gt 1 ]; then
else
CLDIR="$BASEDIR"
fi
while [ $1 ]; do
case $1 in
-p|--profile) CLDIR="$BASEDIR/$2"; shift 2;;
--no-git) GIT=0;shift;;
--debug) DEBUG=1; shift;;
review) shift; review "$@"; exit;;
schedule) shift; schedule "$@";exit;;
asset) shift; asset "$@"; exit;;
*ASSET*) asset "$@"; exit;;
review) review "$@"; exit;;
schedule) schedule "$@";exit;;
help|--help|-h) help; exit;;
*) break;;
esac
done
captains_log $@
captains_log

Loading…
Cancel
Save