From 5c535746f23a1a7945ba1dc5db328ce3315cb72c Mon Sep 17 00:00:00 2001 From: Ben Savage Date: Tue, 8 Mar 2022 15:53:08 +1100 Subject: [PATCH] adding the beginnings of assets --- cl | 51 +++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 47 insertions(+), 4 deletions(-) diff --git a/cl b/cl index 212d6c7..095c08b 100755 --- a/cl +++ b/cl @@ -34,6 +34,10 @@ $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 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 " to open said asset. Run with "review" ($0 review), and you will get a rundown of complete and incomplete tasks for the week. @@ -58,7 +62,6 @@ EOF } function review() { - shift DATE_START=${1:-"-7 days"} DATE_END=${2:-"yesterday"} @@ -100,7 +103,6 @@ function review() { } function schedule() { - shift if [ "$1" == "edit" ]; then if [ -f "$CLDIR/schedule"* ];then @@ -217,6 +219,44 @@ function captains_log() { fi fi } + +function asset() { + + ASSET_DIR="$CLDIR/assets/" + ADB="$ASSET_DIR/db" + 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 + 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 @@ -225,13 +265,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) review "$@"; exit;; - schedule) schedule "$@";exit;; + review) shift; review "$@"; exit;; + schedule) shift; schedule "$@";exit;; + asset) shift; asset "$@"; exit;; help|--help|-h) help; exit;; *) break;; esac