#!/bin/bash _notes_locations_print() { echo "\t\ttodo.txt:\t$TODOTXTPATH" echo "\t\twiki:\t\t$VIMWIKIPATH" echo "\t\tvimrc\t\t$MYVIMRC" echo "\t\tlog.txt\t\t$LOGTXTPATH" } _help() { echo "dev-env.sh usage: $0 [mode]" echo "\txn: Extract notes to:" _notes_locations_print echo "\tsn: Store notes:" _notes_locations_print echo "\tnotes: Launch note making tmux session." exit 1 } _extract_notes() { if [ ! -e "./archive.tar.gz" ]; then echo "archive.tar.gz does not exist." exit 1 fi mkdir tmp tar xzf archive.tar.gz -C . cp -r ./tmp/wiki $(dirname $VIMWIKIPATH) cp ./tmp/todo.txt $TODOTXTPATH cp ./tmp/.vimrc $MYVIMRC cp ./tmp/log.txt $LOGTXTPATH rm -r ./tmp echo "Notes successfully extracted from archive." exit 0 } _storage_notes() { mkdir tmp cp $TODOTXTPATH ./tmp/ cp -r $VIMWIKIPATH ./tmp/ cp $MYVIMRC ./tmp/ cp $LOGTXTPATH ./tmp/ tar czf archive.tar.gz ./tmp/ rm -r tmp echo "Notes successfully stored!" exit 0 } _reverse(){ reversed=();local i;for ((i=$#;i>0;i--)); do reversed+=("${!i}");done; } _graph_notes() { # i want this function to show me a graph of work created to work done readarray -t arr < $TODOTXTPATH for value in "${arr[@]}"; do mapfile -t dates < <(echo $value | grep -Po '(?/dev/null declare dates declare -A datemap declare -A compdatemap _reverse "${dates[@]}" && for i in "${reversed[@]}"; do ## if there are 2 options then do the following ## if there is one option then do the following if [[ -z "${datemap["$i"]}" ]]; then datemap[$i]=1 else datemap[$i]="$((datemap[$i] + 1))" fi # if one value, add 1 to that index on map # if 2 values, add 1 to index of map and done if [[ ${#reversed[@]} == 2 ]]; then echo "$datemap[$i]" echo "COMPLETED ITEM" fi # got the dates here, arrays of 2 mean the task was completed and should be added as [date1] [created] [date2] completed done for key in ${!datemap[@]} do echo "${key}, ${datemap[${key}]}" done } _launch_notes() { tmux new-session -d 'bash' tmux new-window 'vim $TODOTXTPATH $VIMWIKIPATH/index.md $LOGTXTPATH' tmux -2 attach-session -d } # main # check for the neccessary variables if [ -z "$VIMWIKIPATH" ]; then echo "VIMWIKIPATH not set." exit 1 fi if [ -z "$TODOTXTPATH" ]; then echo "TODOTXTPATH not set." exit 1 fi if [ -z "$MYVIMRC" ]; then echo "MYVIMRC not set." exit 1 fi if [ -z "$LOGTXTPATH" ]; then echo "LOGTXTPATH not set." exit 1 fi # run the user's command case "$1" in sn ) _storage_notes ;; xn ) _extract_notes ;; notes ) _launch_notes ;; graph ) _graph_notes ;; * ) _help ;; esac