#!/bin/bash # # UzZas - primitive boss behind your shoulder # # Dependency: CRON, sqlite3 # # Usage: # # uzzas.sh # dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" akce="$1" db="$dir/uzzas.db" case "$akce" in "add"|"-a"|"--add"|"new") echo "==== Enter new task ====" echo " First time planned to (yyyy-mm-dd):" read day echo " Repeat each (days):" read incr echo " Item...:" read box echo " ...containing:" read ins echo " Action/note:" read note echo "ADD? (Y/n)" read ack if [[ "$ack" != "n" ]]; then sqlite3 "$db" "INSERT INTO zas VALUES (date('$day'),$incr,'$box','$ins','$note');" echo "Added!" else echo "Adding cancelled!" fi ;; "list"|"-l"|"--list"|"show"|"--show") echo ".mode column^SELECT * FROM zas ORDER BY day ASC;" | tr '^' '\n' | sqlite3 "$db" ;; "delete"|"del"|"-d"|"--delete") echo "==== Pick which action to delete (first column) ====" echo ".mode column^SELECT rowid,day,box,inside,note FROM zas ORDER BY rowid ASC;" | tr '^' '\n' | sqlite3 "$db" echo " Delete: (0 = cancel)" read del if [[ "$del" > "0" ]]; then sqlite3 "$db" "DELETE FROM zas WHERE rowid='$del' LIMIT 1;" echo "Removed!" else echo "Not removed!" fi ;; "today"|"-t"|"--today") echo ".mode column^SELECT * FROM zas WHERE day=date('now');" | tr '^' '\n' | sqlite3 "$db" ;; "tomorrow"|"-T"|"--tomorrow") echo "==== Tomorrow TODO list ====" echo ".mode column^SELECT * FROM zas WHERE day=date('now','+1 day');" | tr '^' '\n' | sqlite3 "$db" ;; "ack"|"-A"|"--ack"|"done") echo "Select which task is done" echo ".mode column^SELECT rowid,box,inside,note FROM zas WHERE day=date('now') ORDER BY rowid ASC;" | tr '^' '\n' | sqlite3 "$db" echo " Done is: (0 = nothing; a = ALL)" read hot if [[ "$hot" == "a" ]]; then sqlite3 "$db" "UPDATE zas SET day=date(day,'+'||increment||' day');" echo "All today's tasks postponed!" else if [[ "$hot" =~ ^[0-9]+$ ]] 2> /dev/null then if [[ "$hot" > "0" ]]; then sqlite3 "$db" "UPDATE zas SET day=date(day,'+'||increment||' day') WHERE rowid=$hot LIMIT 1;" echo "Task postponed!" else echo "Nothing done!" fi else echo "Invalid value!" fi fi ;; "install"|"-i"|"--install") touch "$db" sqlite3 "$db" "CREATE TABLE IF NOT EXISTS zas (day TIMESTAMP,increment INTEGER,box TEXT,inside TEXT,note TEXT);" (crontab -l 2>/dev/null; echo "0 8-23 * * * DISPLAY=:0 $dir/uzzas.sh ping") | crontab - echo "==== UzZas installed ====" echo " See brmlab.cz/project/uzzas/start for more info" ;; "ping"|"-p"|"--ping") # Invoked via CRON, display graphical count=$(sqlite3 "$db" "SELECT count(rowid) FROM zas WHERE day=date('now');") if [[ "$count" > "0" ]]; then boxlen=$(sqlite3 "$db" "SELECT max(length(box)) FROM zas WHERE day=date('now');") inslen=$(sqlite3 "$db" "SELECT max(length(inside)) FROM zas WHERE day=date('now');") notelen=$(sqlite3 "$db" "SELECT max(length(note)) FROM zas WHERE day=date('now');") todo=$(echo ".headers on^.width $boxlen $inslen $notelen^.mode column^SELECT box,inside,note FROM zas WHERE day=date('now');" | tr '^' '\n' | sqlite3 "$db") #zenity --width=600 --info --text="$todo" --title="UzZas" zenity --info --title="UzZas" --no-wrap --text="$todo" fi ;; "help"|"-h"|"--help") echo "==== UzZas ====" echo " Minimalistic reminder of recurrent events" echo " " echo "==== Dependencies ====" echo " - BASH interpreter (b4ckd00r)" echo " - sqlite3 (for storing the events)" echo " - CRON (for recurring invocation)" echo " - zenity (for graphical reminder)" echo " " echo "==== Usage ====" echo " uzzas.sh ACTION" echo " " echo " ACTION could be one of:" echo " (add|-a|--add) - Add new entry" echo " (list|-l|--list) - List all entries sorted by due date" echo " (delete|-d|--delete) - Delete entry" echo " (today|-t|--today) - Show entries which are planned for today" echo " (tomorrow|-T|--tomorrow) - Show entries which are planned for tomorrow" echo " (ack|-A|--ack) - Mark entry as done and activate next recurrence" echo " (install|-i|--install) - Install UzZas (create uzzas.db and CRON entry)" echo " (ping|-p|--ping) - Graphical equivalent of -t" echo " (help|-h|--help) - This help" echo " (edit|-e|--edit) - Edit existing entry" echo " (clone|-c|--clone) - Clone (and modify) existing entry" echo " " echo "==== See brmlab.cz/project/uzzas/start for more info ====" echo " " ;; "edit"|"-e"|"--edit") echo "==== Edit entry ====" echo ".mode column^SELECT rowid,box,inside,note FROM zas ORDER BY rowid ASC;" | tr '^' '\n' | sqlite3 "$db" echo " Edit: (0 = nothing)" read edit if [[ "$edit" > "0" ]]; then row=$(echo ".mode line^SELECT * FROM zas WHERE rowid=$edit LIMIT 1;" | tr '^' '\n' | sqlite3 "$db") day=$(echo "$row" | grep -e "^[ ]*day = " | sed -e 's/[ ]*day = //g') incr=$(echo "$row" | grep -e "^[ ]*increment = " | sed -e 's/[ ]*increment = //g') box=$(echo "$row" | grep -e "^[ ]*box = " | sed -e 's/[ ]*box = //g') ins=$(echo "$row" | grep -e "^[ ]*inside = " | sed -e 's/[ ]*inside = //g') note=$(echo "$row" | grep -e "^[ ]*note = " | sed -e 's/[ ]*note = //g') echo " First time planned to (yyyy-mm-dd):" read -e -i "$day" day echo " Repeat each (days):" read -e -i "$incr" incr echo " Item...:" read -e -i "$box" box echo " ...containing:" read -e -i "$ins" ins echo " Action/note:" read -e -i "$note" note echo "EDIT? (Y/n)" read ack if [[ "$ack" != "n" ]]; then sqlite3 "$db" "UPDATE zas SET day='$day',box='$box',increment='$incr',inside='$ins',note='$note' WHERE rowid=$edit LIMIT 1;" echo "Tasks edited!" else echo "Edit cancelled!" fi else echo "Invalid value!" fi ;; "clone"|"-c"|"--clone"|"copy"|"--copy") echo "==== Clone entry ====" echo ".mode column^SELECT rowid,box,inside,note FROM zas ORDER BY rowid ASC;" | tr '^' '\n' | sqlite3 "$db" echo " Clone: (0 = nothing)" read clone if [[ "$clone" > "0" ]]; then row=$(echo ".mode line^SELECT * FROM zas WHERE rowid=$clone LIMIT 1;" | tr '^' '\n' | sqlite3 "$db") day=$(echo "$row" | grep -e "^[ ]*day = " | sed -e 's/[ ]*day = //g') incr=$(echo "$row" | grep -e "^[ ]*increment = " | sed -e 's/[ ]*increment = //g') box=$(echo "$row" | grep -e "^[ ]*box = " | sed -e 's/[ ]*box = //g') ins=$(echo "$row" | grep -e "^[ ]*inside = " | sed -e 's/[ ]*inside = //g') note=$(echo "$row" | grep -e "^[ ]*note = " | sed -e 's/[ ]*note = //g') echo "== Edit cloned entry ==" echo " First time planned to (yyyy-mm-dd):" read -e -i "$day" day echo " Repeat each (days):" read -e -i "$incr" incr echo " Item...:" read -e -i "$box" box echo " ...containing:" read -e -i "$ins" ins echo " Action/note:" read -e -i "$note" note echo "COPY? (Y/n)" read ack if [[ "$ack" != "n" ]]; then sqlite3 "$db" "INSERT INTO zas VALUES (date('$day'),$incr,'$box','$ins','$note');" echo "Tasks copied!" else echo "Copy cancelled!" fi else echo "Invalid value!" fi ;; esac exit