|
#!/bin/bash |
|
|
|
## ##################################################################### |
|
## CACHE_TODO ( ctodo ) |
|
## ##################################################################### |
|
## About: |
|
## Jot down notes in a "to-do" chrono log style fashion. |
|
## Argument flags: |
|
## -a | Append a note to a default text file. |
|
## ctodo -a "This is bulleted note string." |
|
## -h | Heading for a new sequence of notes. |
|
## ctodo -h "Heading for a new sequence of notes." |
|
## -f | Copy a file into the "~/.cache_todo" folder |
|
## ctodo -f <file-path> |
|
## -l | View notes in elinks |
|
## ctodo -l |
|
## -d | Delete the "~/.cache_todo" folder |
|
## ctodo -d |
|
## Git: |
|
## https://gist.github.com/508c384d9200933761fa8ecbc4f4698c.git |
|
## ##################################################################### |
|
|
|
function Tput_Colors { |
|
## Foreground Color using ANSI escape |
|
|
|
FG_BLACK=$(tput setaf 0) |
|
FG_RED=$(tput setaf 1) |
|
FG_GREEN=$(tput setaf 2) |
|
FG_YELLOW=$(tput setaf 3) |
|
FG_BLUE=$(tput setaf 4) |
|
FG_MAGENTA=$(tput setaf 5) |
|
FG_CYAN=$(tput setaf 6) |
|
FG_WHITE=$(tput setaf 7) |
|
FG_NoColor=$(tput sgr0) |
|
|
|
## Background Color using ANSI escape |
|
|
|
BG_BLACK=$(tput setab 0) |
|
BG_RED=$(tput setab 1) |
|
BG_GREEN=$(tput setab 2) |
|
BG_YELLOW=$(tput setab 3) |
|
BG_BLUE=$(tput setab 4) |
|
BG_MAGENTA=$(tput setab 5) |
|
BG_CYAN=$(tput setab 6) |
|
BG_WHITE=$(tput setab 7) |
|
BG_NoColor=$(tput sgr0) |
|
|
|
## set mode using ANSI escape |
|
|
|
MODE_BOLD=$(tput bold) |
|
MODE_DIM=$(tput dim) |
|
MODE_BEGIN_UNDERLINE=$(tput smul) |
|
MODE_EXIT_UNDERLINE=$(tput rmul) |
|
MODE_REVERSE=$(tput rev) |
|
MODE_ENTER_STANDOUT=$(tput smso) |
|
MODE_EXIT_STANDOUT=$(tput rmso) |
|
|
|
# clear styles using ANSI escape |
|
|
|
STYLES_OFF=$(tput sgr0) |
|
FGBG_NoColor=$(tput sgr0) |
|
} |
|
|
|
function about { |
|
echo -e "$FG_CYAN \ |
|
\n## ##################################################################### \ |
|
\n## CACHE_TODO ( ctodo ) \ |
|
\n## ##################################################################### \ |
|
\n## \ |
|
\n## About: \ |
|
\n## Jot down notes in a \"to-do\" chrono log style fashion. \ |
|
\n## \ |
|
\n## Argument flags:\ |
|
\n## -a | Append a note to a default text file. \ |
|
\n## ctodo -a \"This is bulleted note string.\" \ |
|
\n## \ |
|
\n## -h | Heading for a new sequence of notes. \ |
|
\n## ctodo -h \"Heading for a new sequence of notes.\" \ |
|
\n## \ |
|
\n## -f | Copy a file into the \"~/.cache_todo\" folder \ |
|
\n## ctodo -f <file-path> \ |
|
\n## \ |
|
\n## -l | View notes in elinks \ |
|
\n## ctodo -l \ |
|
\n## \ |
|
\n## -d | Delete the \"~/.cache_todo\" folder \ |
|
\n## ctodo -d \ |
|
\n## \ |
|
\n## Git: \ |
|
\n## https://gist.github.com/508c384d9200933761fa8ecbc4f4698c.git \ |
|
\n## \ |
|
\n## ##################################################################### \ |
|
\n$STYLES_OFF" |
|
} |
|
|
|
function initialize_file { |
|
## Create a daily note file |
|
|
|
notesDirectory=~/.cache_todo |
|
nowDay=$(date +%d%b%Y) |
|
noteMD=$notesDirectory/ctodo_note_$nowDay.md |
|
noteHTML=$notesDirectory/ctodo_note_$nowDay.html |
|
|
|
mkdir -p $notesDirectory |
|
|
|
if [ ! -f $noteMD ]; then |
|
echo -e "# ctodo_note_$nowDay\n" > $noteMD |
|
echo -e "|time|note|" >> $noteMD |
|
echo -e "|:---|:---|" >> $noteMD |
|
|
|
echo -e "$noteMD created." |
|
fi |
|
} |
|
|
|
function append_file { |
|
|
|
if [ -f $noteMD ]; then |
|
nowTime=$(date +%H%M) |
|
echo -e "|<span style=\"color:blue;\">$nowTime</span>|<span style=\"color:green;\">$note</span>|" >> $noteMD |
|
echo -e "$FG_GREEN\tString:\t \"$note\"\n\tNote File: $noteMD\n$STYLES_OFF" |
|
|
|
## Generate an optional html file equivalent |
|
#isPandoc=$(command -v pandoc) |
|
#if [ $isPandoc == "/usr/bin/pandoc" ]; then |
|
command -v pandoc &>/dev/null |
|
if [ $? -eq 0 ]; then |
|
pandoc $noteMD > $noteHTML |
|
echo -e "$FG_YELLOW\tGenerated $noteHTML using pandoc.\n$STYLES_OFF" |
|
fi |
|
|
|
fi |
|
} |
|
|
|
function section_heading { |
|
echo -e "\n## $note \n" >> $noteMD |
|
echo -e "|time|note|" >> $noteMD |
|
echo -e "|:---|:---|" >> $noteMD |
|
echo -e "$FG_GREEN\tHeading:\t \"$note\"\n\tNote File: $noteMD.\n$STYLES_OFF" |
|
} |
|
|
|
function clear_vars { |
|
unset notesDirectory |
|
unset note |
|
unset noteMD |
|
unset nowDay |
|
unset nowTime |
|
} |
|
|
|
## ############################################################################# |
|
## Run |
|
## ############################################################################# |
|
|
|
Tput_Colors |
|
initialize_file |
|
|
|
while [ ! -z "$1" ]; do |
|
case "$1" in |
|
--append|-a ) |
|
shift |
|
|
|
note=$1 |
|
if [ ! -z "$note" ]; then |
|
echo -e "$FG_MAGENTA\nAppend file: $noteMD $STYLES_OFF" |
|
append_file |
|
fi |
|
;; |
|
|
|
--heading|-h ) |
|
shift |
|
|
|
note=$1 |
|
if [ ! -z "$note" ]; then |
|
echo -e "$FG_MAGENTA\nAppend file: $noteMD $STYLES_OFF" |
|
section_heading |
|
fi |
|
;; |
|
|
|
--file|-f ) |
|
shift |
|
|
|
note=$1 |
|
note=$(readlink -f $note) |
|
|
|
if [ ! -z "$note" ]; then |
|
## Copy file |
|
cp $note $notesDirectory |
|
|
|
if [ -f $note ]; then |
|
echo -e "$FG_MAGENTA\nAppend file: $noteMD $STYLES_OFF" |
|
## full file path |
|
note=$(readlink -f $note) |
|
note="Resource: \"$note\" was copied into \"$notesDirectory\"" |
|
append_file |
|
|
|
echo -e "${FG_MAGENTA}$note\n$STYLES_OFF" |
|
else |
|
echo -e "$FG_RED\nResource: \"$note\" was NOT copied into \"$notesDirectory\" $STYLES_OFF" |
|
fi |
|
fi |
|
;; |
|
|
|
--list|-l ) |
|
shift |
|
|
|
## Browse to lists in elinks |
|
isElinks=$(command -v elinks) |
|
#if [ $isElinks == "/usr/bin/elinks" ]; then |
|
#command -v elinks &>/dev/null |
|
if [ $? -eq 0 ]; then |
|
elinks $notesDirectory |
|
fi |
|
;; |
|
|
|
|
|
--delete|-d ) |
|
shift |
|
|
|
## Delete notesDirectory=~/.cache_todo |
|
echo "${BG_RED}$FG_WHITE" |
|
read -e -p "Delete the $notesDirectory directory? [ y/N ]: " -i "n" yn |
|
echo "$STYLES_OFF" |
|
|
|
case $yn in |
|
[Yy]* ) |
|
rm -rf $notesDirectory |
|
echo -e "${FG_YELLOW}$notesDirectory deleted.$STYLES_OFF" |
|
;; |
|
esac |
|
;; |
|
* ) |
|
echo -e "${FG_RED}\nError:\n\tInvalid argument input.$STYLES_OFF" |
|
|
|
about |
|
|
|
exit |
|
;; |
|
esac |
|
shift |
|
done |
|
|
|
clear_vars |
init