diff options
author | Matthew Lemon <chaffinach+git@protonmail.ch> | 2022-01-12 16:16:28 +0000 |
---|---|---|
committer | Matthew Lemon <chaffinach+git@protonmail.ch> | 2022-01-12 16:16:28 +0000 |
commit | dabc46e1905c1d92db5d9a13888221555fb70fc3 (patch) | |
tree | 55052a76c69853269d5e567e7506a02b372b6284 /grepjournal | |
parent | 0dee170ae9ba1255413d03fad7425cb3da2f3f3f (diff) |
more successful use of terminal codes
Diffstat (limited to '')
-rwxr-xr-x | grepjournal | 35 |
1 files changed, 21 insertions, 14 deletions
diff --git a/grepjournal b/grepjournal index 8d64ee4..db73fc3 100755 --- a/grepjournal +++ b/grepjournal @@ -2,20 +2,29 @@ # Search ~/Notes/journal for a term and return as a markdown list sorted by date. +colourWhite="$(tput setaf 7)" +colourGreen="$(tput setaf 2)" +colourYellow="$(tput setaf 2)" +txBold="$(tput bold)" +txReset="$(tput sgr0)" + # Automatic cleanup -trap 'rm -f "$tmpfile"' EXIT -tmpfile=$(mktemp) || exit 1 +trap 'rm -f "$grepped_results"' EXIT +grepped_results=$(mktemp) || exit 1 + +trap 'rm -f "$output_file"' EXIT +output_file=$(mktemp) || exit 1 termsize=$(stty size| awk '{print $2}') -printf "=%.0s" $(seq $termsize) -echo "" +printf "${colourWhite}=%.0s" $(seq $termsize) +echo # very bad way to check the params passed in... [[ -z "$2" ]] && [[ -n "$1" ]] && searchterm="$1" [[ -n "$2" ]] && [[ -n "$1" ]] && searchterm="$1" && flag="$2" # some confirmatory echoing -echo "Search term: $searchterm" +echo "${colourWhite}Search term: ${txBold}$searchterm${txReset}" [[ -v flag ]] && echo "Flag: $flag" if [[ $flag != "-i" ]]; then @@ -23,32 +32,30 @@ if [[ $flag != "-i" ]]; then fi # do the business, starting with using grep to get the pertinent lines -echo -e "$(grep -R $flag "$searchterm" /home/"$USER"/Notes/journal/)" > "$tmpfile" +echo -e "$(grep -R $flag "$searchterm" /home/"$USER"/Notes/journal/)" > "$grepped_results" # more confirmatory text echo "Command: 'grep -R $flag $searchterm /home/"$USER"/Notes/journal/'" + printf "=%.0s" $(seq $termsize) echo "" + # subsitute to get the right format using sed # form: 2022-01-10 12:49: :TODO Do the MyHR content: ht 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]} - echo "$year" month=${BASH_REMATCH[2]} - echo "$month" day=${BASH_REMATCH[3]} - echo "$day" time=${BASH_REMATCH[4]} - echo "$time" note=${BASH_REMATCH[5]} - echo "$note" fi -done < "$tmpfile" -#sed -r -i 's/\/home\/lemon\/Notes\/journal\/([[:digit:]]*-[[:digit:]]*-[[:digit:]]*)\.md:-[[:blank:]](.*)/\1 \2/' "$tmpfile" + echo ${colourGreen}"$year"-"$month"-"$day":${txReset} "$note" >> $output_file +done < "$grepped_results" +#sed -r -i 's/\/home\/lemon\/Notes\/journal\/([[:digit:]]*-[[:digit:]]*-[[:digit:]]*)\.md:-[[:blank:]](.*)/\1 \2/' "$grepped_results" # output -# cat "$tmpfile" | sort +cat "$output_file" | sort |