diff options
author | Matthew Lemon <chaffinach+git@protonmail.ch> | 2022-01-13 17:22:35 +0000 |
---|---|---|
committer | Matthew Lemon <chaffinach+git@protonmail.ch> | 2022-01-13 17:22:35 +0000 |
commit | fc28e58672942c9826c433f9c2d1628aaec8f9ba (patch) | |
tree | 759cb04422dbec46e79d10fc1f4cc64acc053088 /grepjournal | |
parent | 5000a23e1f31c2d55132d1ee29c0bc303a2047c7 (diff) |
Now successfully does days of the week - but janky
Diffstat (limited to '')
-rwxr-xr-x | grepjournal | 43 |
1 files changed, 36 insertions, 7 deletions
diff --git a/grepjournal b/grepjournal index 7b66262..b7102bf 100755 --- a/grepjournal +++ b/grepjournal @@ -2,6 +2,33 @@ # Search ~/Notes/journal for a term and return as a markdown list sorted by date. +_get_weekday() { + local monday="# (Monday)" + local tuesday="# (Tuesday)" + local wednesday="# (Wednesday)" + local thursday="# (Thursday)" + local friday="# (Friday)" + local saturday="# (Saturday)" + local sunday="# (Sunday)" + while IFS= read -r fileline; do + if [[ $fileline =~ $monday ]]; then + echo "${BASH_REMATCH[1]}" + elif [[ $fileline =~ $tuesday ]]; then + echo "${BASH_REMATCH[1]}" + elif [[ $fileline =~ $wednesday ]]; then + echo "${BASH_REMATCH[1]}" + elif [[ $fileline =~ $thursday ]]; then + echo "${BASH_REMATCH[1]}" + elif [[ $fileline =~ $friday ]]; then + echo "${BASH_REMATCH[1]}" + elif [[ $fileline =~ $saturday ]]; then + echo "${BASH_REMATCH[1]}" + elif [[ $fileline =~ $sunday ]]; then + echo "${BASH_REMATCH[1]}" + fi + done < "$1" +} + colourWhite="\033[38;2;255;255;255m" colourGreen="\033[38;2;0;255;0m" colourLightGreen="\033[38;2;231;252;179m" @@ -46,16 +73,18 @@ echo "" # because I can't get the regex right, I am searching for http or https to indicate a link in a line urlregex="https?" -re='^/home/lemon/Notes/journal/([0-9]{4})-([0-9]{2})-([0-9]{2})\.md:-\s([0-9]{2}:[0-9]{2}):\s(.*)' +re='(^/home/lemon/Notes/journal/([0-9]{4})-([0-9]{2})-([0-9]{2})\.md):-\s([0-9]{2}:[0-9]{2}):\s(.*)' while IFS= read -r line; do if [[ $line =~ $re ]]; then - year=${BASH_REMATCH[1]} - month=${BASH_REMATCH[2]} - day=${BASH_REMATCH[3]} - time=${BASH_REMATCH[4]} - note=${BASH_REMATCH[5]} + path=${BASH_REMATCH[1]} + year=${BASH_REMATCH[2]} + month=${BASH_REMATCH[3]} + day=${BASH_REMATCH[4]} + time=${BASH_REMATCH[5]} + note=${BASH_REMATCH[6]} fi - out_line="${colourGreen}"$year"-"$month"-"$day"${colourGray}T${colourLightGreen}"$time":${txReset} ${note}" + output_day=$(_get_weekday "$path") + out_line="${colourGreen} "$year"-"$month"-"$day"${colourGray}T${colourLightGreen}"$time": ${output_day} ${txReset} ${note}" if [[ $out_line =~ $urlregex ]]; then out_line=${out_line/${BASH_REMATCH[0]}/${colourCyan}${BASH_REMATCH[0]}${txReset}} fi |