From f807378ed2a11b34b03111aec8d2ef79b7e88c1d Mon Sep 17 00:00:00 2001 From: ryangreenup Date: Tue, 14 Jul 2020 20:09:12 +1000 Subject: [PATCH 01/15] Fixed Bindings --- bin/NoteFind.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/bin/NoteFind.sh b/bin/NoteFind.sh index 7ae3eb9..8a9f711 100755 --- a/bin/NoteFind.sh +++ b/bin/NoteFind.sh @@ -76,11 +76,12 @@ setVars () { SkimGrep () { sk --ansi -c 'rg -l -t markdown --ignore-case "{}"' --preview "mdcat {}" \ - --bind 'ctrl-f:interactive,pgup:preview-page-up,pgdn:preview-page-down,ctrl-w:execute-silent(echo {} | xargs realpath | xclip -selection clipboard),alt-w:execute-silent(echo {} | xclip -selection clipboard)' --bind 'ctrl-f:interactive,pgup:preview-page-up,pgdn:preview-page-down' \ --bind 'ctrl-w:execute-silent(echo {} | xargs realpath | xclip -selection clipboard),alt-w:execute-silent(echo {} | xclip -selection clipboard)' \ --bind 'alt-v:execute-silent(code {}),alt-e:execute-silent(emacs {}),ctrl-o:execute-silent(xdg-open {})' \ - --bind 'alt-p:execute-silent(marktext {} 2> /dev/null)' + --bind 'alt-y:execute-silent(cat {} | xclip -selection clipboard)' \ + --bind 'alt-o:execute-silent(cat {} | pandoc -f markdown -t html --mathml | xclip -selection clipboard)' \ + --bind 'alt-f:execute-silent(echo {} | xargs dirname | xargs cd; cat {} | pandoc -f markdown -t dokuwiki --mathml | xclip -selection clipboard)' \ } From 38a9ace6083d98fdb88cf19946429cb29f57b51c Mon Sep 17 00:00:00 2001 From: ryangreenup Date: Tue, 14 Jul 2020 20:30:24 +1000 Subject: [PATCH 02/15] Can Now Cancel Skim in cadmus find, help abandoned --- bin/NoteFind.sh | 14 ++++++++++-- bin/cadmus | 60 +++++++++---------------------------------------- 2 files changed, 23 insertions(+), 51 deletions(-) diff --git a/bin/NoteFind.sh b/bin/NoteFind.sh index 8a9f711..46661b9 100755 --- a/bin/NoteFind.sh +++ b/bin/NoteFind.sh @@ -33,9 +33,19 @@ SkimAndGrep () { ## fish only, not zsh or bash if [[ "$(basename $SHELL)" == "fish" ]]; then - SkimGrepHighlightFish | xargs realpath && exit 0 + FILE="$(SkimGrepHighlightFish)" + if [[ $FILE != "" ]]; then + realpath $FILE && exit 0 + else + exit 1 + fi else - SkimGrep | xargs realpath && exit 0 + FILE="$(SkimGrep)" + if [[ $FILE != "" ]]; then + realpath $FILE && exit 0 + else + exit 1 + fi fi diff --git a/bin/cadmus b/bin/cadmus index 9b9e78b..b0deb2b 100755 --- a/bin/cadmus +++ b/bin/cadmus @@ -51,7 +51,8 @@ function mainHelp() { echo -e " ⎋ \e[1;36m convert \e[0m \e[1;34m ┊┊┊ \e[0m Convert Clipboard Contents to Different Formats " echo -e " 🧰 \e[1;37m misc \e[0m \e[1;34m ┊┊┊ \e[0m Miscelanneous Tools nice to have on hand " echo -e " 🌏\e[1;92m publish\e[0m \e[1;34m ┊┊┊ \e[0m Publish with \e[1;34m \e[4m\e[3mMkDocs\e[0m\e[0m🐍" - echo -e " 🕮 \e[1;92m preview \e[0m \e[1;34m ┊┊┊ \e[0m Preview with \e[1;34m \e[4m\e[3mMarkServ\e[0m\e[0m " + echo -e " 🕮 \e[1;93m preview \e[0m \e[1;34m ┊┊┊ \e[0m Preview with \e[1;34m \e[4m\e[3mMarkServ\e[0m\e[0m " + echo -e " 🕮 \e[1;94m help \e[0m \e[1;34m ┊┊┊ \e[0m Open help for correspoding functions " echo echo -e " \e[3m\e[1m• Legend\e[0m " echo @@ -89,6 +90,8 @@ arguments () { ;; preview) echo "begin preview" ;; + help) echo "View Help" + ;; --*) >&2 echo "bad option $1" ;; *) >&2 echo -e "argument \e[1;35m${1}\e[0m has no definition." @@ -101,56 +104,15 @@ arguments () { # *** Find function NoteFind() { + echo "Running NoteFind.sh" - ## If it's more than two lines, the output isn't what's expected, - ## instead is more likely help or a message and so that's what should be returned - NoteFind.sh "${@:-}" | (( "$(wc -l)" > 2 )) && echo "Greater than 2" || echo "Less than two" - exit 0 + FILE="$(NoteFind.sh "${@:-}")" - ## Instead why not make a function called is help still arg that prints the corresponding help if it finds -h? + + + if [ "$FILE" != "" ]; then + xdg-open $FILE + fi } -mytest() { - echo "This is a test" - exit 0 -} - - main "${@}" - - - -########################################################################## -# arguments () { # -# while test $# -gt 0 # -# do # -# case "$1" in # -# --help) Help # -# ;; # -# -h) Help # -# ;; # -# --opt3) echo "option 3" # -# ;; # -# --opt4) echo "option 4" # -# ;; # -# --opt5) echo "option 5" # -# ;; # -# --opt6) echo "option 6" # -# ;; # -# --opt7) echo "option 7" # -# ;; # -# --opt8) echo "option 8" # -# ;; # -# --opt9) echo "option 9" # -# ;; # -# --opt10) echo "option 10" # -# ;; # -# --*) echo "bad option $1" # -# ;; # -# *) echo -e "argument \e[1;35m${1}\e[0m has no definition." # -# ;; # -# esac # -# shift # -# done # -# } # -########################################################################## From 9054ecddf708ef4db962c7848b8d07238f71db35 Mon Sep 17 00:00:00 2001 From: ryangreenup Date: Tue, 14 Jul 2020 20:43:33 +1000 Subject: [PATCH 03/15] Abandon Help from Cadmus --- README.md | 3 +++ bin/NoteFind.sh | 1 + 2 files changed, 4 insertions(+) diff --git a/README.md b/README.md index bdab7eb..291ac4d 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,9 @@ this is an attempt to wrap them into a single script and then have aliases to ma ## Philosophy +- cadmus acts as a menu for scripts to acheive things + - the script name will always be printed to the terminal so the individual + script can be used for whatever purpose. - SubFunctions will take only two arguments: - `-h` or `--help` as a help function - If this is seen anywhere the help will be printed and the script exit will. diff --git a/bin/NoteFind.sh b/bin/NoteFind.sh index 46661b9..cfb4fe4 100755 --- a/bin/NoteFind.sh +++ b/bin/NoteFind.sh @@ -96,6 +96,7 @@ SkimGrep () { } # *** Interpret arguments +## TODO I should change this, the -d and -p options only complicate things arguments () { while test $# -gt 0 do From f6e8e1c190b73f258703c3c174a041d8459c315d Mon Sep 17 00:00:00 2001 From: ryangreenup Date: Tue, 14 Jul 2020 21:03:09 +1000 Subject: [PATCH 04/15] Restructure SubFunctions --- todo.org | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/todo.org b/todo.org index b51d38c..9ad7b1f 100644 --- a/todo.org +++ b/todo.org @@ -29,6 +29,17 @@ see [[https://github.com/freshautomations/stoml][the stoml package]]. ** Aliases *** [#B] Readme Add Recommended Aliases to the [[file:README.md::Recommended Aliases][readme]] as well as fish functions. +* SubFunctions +** TODO Restructure +should I restructure the subfunctions to accept only 1 argument either help or directory and fail in the absence of any given argument? + +*** Pros ++ Much Simpler to implement and maintain + +*** Cons ++ Less clean to pass in functions ++ Less Extensible + * HOLD [#A] NoteFind.sh ** KeyBindings *** TODO [#B] Should Implement keybindings for Exports From 85db26cfff4adae3d520d55f07f77e2dc003e809 Mon Sep 17 00:00:00 2001 From: ryangreenup Date: Tue, 14 Jul 2020 21:23:47 +1000 Subject: [PATCH 05/15] Restructured Subfunctions to be simpler --- README.md | 12 ++-- bin/NoteFind.sh | 181 ++++++++++++++++++++---------------------------- bin/cadmus | 2 +- 3 files changed, 82 insertions(+), 113 deletions(-) diff --git a/README.md b/README.md index 291ac4d..b353d4c 100644 --- a/README.md +++ b/README.md @@ -11,16 +11,12 @@ this is an attempt to wrap them into a single script and then have aliases to ma ## Philosophy -- cadmus acts as a menu for scripts to acheive things +- ****cadmus**** acts as a menu for scripts to acheive things - the script name will always be printed to the terminal so the individual script can be used for whatever purpose. -- SubFunctions will take only two arguments: - - `-h` or `--help` as a help function - - If this is seen anywhere the help will be printed and the script exit will. - - Some type of input: - - `-d` or `--dir` as a directory location - - `-p` or `--path` as a file location - - `STDIN` which is piped into the subfunction. +- SubFunctions will take *only one* argument or `STDIN` + - If the first argument is either `-h` or `--help` help will be printed and then `exit 0` + - This might lead to some limitations but the simplicity is for sanity, modularity and extensibility. diff --git a/bin/NoteFind.sh b/bin/NoteFind.sh index cfb4fe4..8f92a66 100755 --- a/bin/NoteFind.sh +++ b/bin/NoteFind.sh @@ -10,24 +10,90 @@ set -o pipefail # don't hide errors within pipes # * Main Function main() { - setVars - check_for_help "${@}" # If help is detected this script will exit check_for_dependencies - arguments "${@}" - SkimAndGrep + setVars + readFirstArgument "${@}" + SkimNotes "${@}" } # ** Helper Functions +# *** Check for Dependencies +check_for_dependencies () { + + for i in ${DependArray[@]}; do + command -v "$i" >/dev/null 2>&1 || { echo >&2 "I require $i but it's not installed. Aborting."; exit 1; } + done + + +} + +# **** List of Dependencies + +declare -a DependArray=( + "rg" + "sk" + "mdcat" + "xclip" + ) + + +# *** Set variables below main +setVars () { + readonly script_name=$(basename "${0}") + readonly script_dir=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) + IFS=$'\t\n' # Split on newlines and tabs (but not on spaces) +} + +# **** Print Help +Help () { + + + echo + echo -e " \e[3m\e[1m NoteFind.sh \e[0m; Helpful Shell Scripts for Markdown Notes" + echo -e " \e[1;31m -------------------------\e[0m " + echo + echo -e " \e[3m\e[1m• Usage \e[0m " + echo + echo -e " "${script_name}" []" + echo -e " "${script_name}" [-h]" + echo -e " "${script_name}" [--help]" + echo + echo -e " \e[3m By Design: No Options; No other Arguments\e[0m" + echo + echo + echo -e " \e[1;91m \e[1m Binding \e[0m\e[0m \e[1;34m┊┊┊ \e[0m Description " + echo -e " ..............\e[1;34m┊┊┊\e[0m........................................... " + echo -e " \e[1;95m Ctrl - q \e[0m \e[1;34m ┊┊┊ \e[0m \e[1m Search \e[0m with \e[0m\e[3mripgrep\e[0m" + echo -e " \e[1;93m Ctrl - w \e[0m \e[1;34m ┊┊┊ \e[0m \e[1m Copy \e[0m the Full Path to the Clipboard" + echo -e " \e[1;93m Alt - w \e[0m \e[1;34m ┊┊┊ \e[0m \e[1m Copy \e[0m the Relative Path to the Clipboard" + echo -e " \e[1;94m Alt - e \e[0m \e[1;34m ┊┊┊ \e[0m \e[1m Open \e[0m in Emacs" + echo -e " \e[1;94m Alt - v \e[0m \e[1;34m ┊┊┊ \e[0m \e[1m Open \e[0m in VSCode" + echo -e " \e[1;94m Ctrl - o \e[0m \e[1;34m ┊┊┊ \e[0m \e[1m Open \e[0m in Default Program" + echo + + echo -e " \e[3m\e[1m• Compatability \e[0m " + echo + echo -e " Match highlighting occurs automatically if \e[1m\$SHELL\e[0m is \e[1m **/fish\e[0m" + echo -e " This uses \e[1mtmpfs\e[0m at \e[1m /dev/shm\e[0m, this should work on \e[3mArch\e[0m, \e[3mFedora\e[0m and \e[3mUbuntu\e[0m, I don't know about \e[3mMacOS\e[0m " + echo +} + + +# *** Read First Argument +readFirstArgument () { + + if [[ "${1:-}" == "-h" ]] || [[ "${1:-}" == "--help" ]] || [[ "${1:-}" == "" ]]; then + Help && exit 0 + fi + +} # *** Skim and Grep, the important stuff -SkimAndGrep () { +SkimNotes () { ## Change directory if One was specified, exit if no directory exists - if [ "${1:-}" != "" ]; then - cd "${1}" || exit 4 - fi - + cd "${1}" ## If using fish, cleverness can be utilised to highlight matches. ## fish only, not zsh or bash @@ -74,13 +140,7 @@ SkimGrepHighlightFish () { ## C-q toggles interactive ## C-y Copies Full path to clipboard } -# -# *** Set variables below main -setVars () { - readonly script_name=$(basename "${0}") - readonly script_dir=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) - IFS=$'\t\n' # Split on newlines and tabs (but not on spaces) -} + # **** Skim with Grep SkimGrep () { @@ -95,93 +155,6 @@ SkimGrep () { } -# *** Interpret arguments -## TODO I should change this, the -d and -p options only complicate things -arguments () { - while test $# -gt 0 - do - case "$1" in - -d) SkimAndGrep "${2}" && exit 0 - ;; - --d) SkimAndGrep $2 && exit 0 - ;; - --*) echo "bad option $1 in "${script_name}"" - ;; - -?) echo "(5) Unknown option $1 in "${script_name}""; Help; exit 1 - ;; -## ?*) echo -e "argument \e[1;35m${1}\e[0m has no definition laksdjfaklsdfj." -## ;; - esac - shift - done -} -# *** Check for Help -# **** Print Help -# -check_for_help () { - while test $# -gt 0 - do - case "$1" in - --help) Help && exit 0 - ;; - -h) Help && exit 0 - ;; - esac - shift - done -} - -Help () { - - - echo - echo -e " \e[3m\e[1m NoteFind.sh \e[0m; Helpful Shell Scripts for Markdown Notes" - echo -e " \e[1;31m -------------------------\e[0m " - echo - echo -e " \e[3m\e[1m• Usage \e[0m " - echo - echo -e " "${script_name}" [-d /dev/null 2>&1 || { echo >&2 "I require $i but it's not installed. Aborting."; exit 1; } - done - - -} - -# **** List of Dependencies - -declare -a DependArray=( - "rg" - "sk" - "mdcat" - "xclip" - ) - - -## * Call Main Function +# * Call Main Function main "${@}" diff --git a/bin/cadmus b/bin/cadmus index b0deb2b..64dc6ba 100755 --- a/bin/cadmus +++ b/bin/cadmus @@ -72,7 +72,7 @@ arguments () { ;; -h) mainHelp && exit 0 ;; - find) shift; NoteFind -d "${NOTES_DIR}" "${@:-}" ## Don't steal function name + find) shift; NoteFind "${NOTES_DIR}" "${@:-}" ## Don't steal function name ;; search) echo "begin note search" ;; From 3cd419e2c2a594e9234b521d4186c5b7871805a5 Mon Sep 17 00:00:00 2001 From: ryangreenup Date: Tue, 14 Jul 2020 21:39:13 +1000 Subject: [PATCH 06/15] Created Function for dealing with Help --- bin/cadmus | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/bin/cadmus b/bin/cadmus index 64dc6ba..82ae436 100755 --- a/bin/cadmus +++ b/bin/cadmus @@ -9,7 +9,7 @@ set -o nounset set -o pipefail -## * Main Functions +# * Main Functions main() { @@ -62,7 +62,7 @@ function mainHelp() { } # ** Main Arguments - Level 0 -# +# *** Switch arguments () { while test $# -gt 0 @@ -90,7 +90,7 @@ arguments () { ;; preview) echo "begin preview" ;; - help) echo "View Help" + help) subHelp && exit 0 ;; --*) >&2 echo "bad option $1" ;; @@ -116,3 +116,8 @@ function NoteFind() { } main "${@}" + +# *** All the Help +subHelp () { + NoteFind.sh -h +} From a5f9a37947ba1d193f226c9b11c62cff33a1ca88 Mon Sep 17 00:00:00 2001 From: ryangreenup Date: Tue, 14 Jul 2020 21:42:53 +1000 Subject: [PATCH 07/15] VSCode gets option -a from skim --- bin/NoteFind.sh | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/bin/NoteFind.sh b/bin/NoteFind.sh index 8f92a66..ec25bf8 100755 --- a/bin/NoteFind.sh +++ b/bin/NoteFind.sh @@ -50,8 +50,8 @@ Help () { echo - echo -e " \e[3m\e[1m NoteFind.sh \e[0m; Helpful Shell Scripts for Markdown Notes" - echo -e " \e[1;31m -------------------------\e[0m " + echo -e " \e[3m\e[1mNoteFind.sh \e[0m; Helpful Shell Scripts for Markdown Notes" + echo -e " \e[1;31m--------------------------\e[0m " echo echo -e " \e[3m\e[1m• Usage \e[0m " echo @@ -61,6 +61,8 @@ Help () { echo echo -e " \e[3m By Design: No Options; No other Arguments\e[0m" echo + echo -e " \e[3m\e[1m• Key Bindings\e[0m " + echo echo echo -e " \e[1;91m \e[1m Binding \e[0m\e[0m \e[1;34m┊┊┊ \e[0m Description " echo -e " ..............\e[1;34m┊┊┊\e[0m........................................... " @@ -130,7 +132,7 @@ SkimGrepHighlightFish () { --no-line-number --ignore-case --pretty --context 20 (cat "${ramtmp}")" \ --bind 'ctrl-f:interactive,pgup:preview-page-up,pgdn:preview-page-down' \ --bind 'ctrl-w:execute-silent(echo {} | xargs realpath | xclip -selection clipboard),alt-w:execute-silent(echo {} | xclip -selection clipboard)' \ - --bind 'alt-v:execute-silent(code {}),alt-e:execute-silent(emacs {}),ctrl-o:execute-silent(xdg-open {})' \ + --bind 'alt-v:execute-silent(code -a {}),alt-e:execute-silent(emacs {}),ctrl-o:execute-silent(xdg-open {})' \ --bind 'alt-y:execute-silent(cat {} | xclip -selection clipboard)' \ --bind 'alt-o:execute-silent(cat {} | pandoc -f markdown -t html --mathml | xclip -selection clipboard)' \ --bind 'alt-f:execute-silent(echo {} | xargs dirname | xargs cd; cat {} | pandoc -f markdown -t dokuwiki --mathml | xclip -selection clipboard)' \ @@ -148,7 +150,7 @@ SkimGrep () { sk --ansi -c 'rg -l -t markdown --ignore-case "{}"' --preview "mdcat {}" \ --bind 'ctrl-f:interactive,pgup:preview-page-up,pgdn:preview-page-down' \ --bind 'ctrl-w:execute-silent(echo {} | xargs realpath | xclip -selection clipboard),alt-w:execute-silent(echo {} | xclip -selection clipboard)' \ - --bind 'alt-v:execute-silent(code {}),alt-e:execute-silent(emacs {}),ctrl-o:execute-silent(xdg-open {})' \ + --bind 'alt-v:execute-silent(code -a {}),alt-e:execute-silent(emacs {}),ctrl-o:execute-silent(xdg-open {})' \ --bind 'alt-y:execute-silent(cat {} | xclip -selection clipboard)' \ --bind 'alt-o:execute-silent(cat {} | pandoc -f markdown -t html --mathml | xclip -selection clipboard)' \ --bind 'alt-f:execute-silent(echo {} | xargs dirname | xargs cd; cat {} | pandoc -f markdown -t dokuwiki --mathml | xclip -selection clipboard)' \ From f78ac2c3e93f90423a2440f0a16e5162d0ece40c Mon Sep 17 00:00:00 2001 From: ryangreenup Date: Tue, 14 Jul 2020 21:49:08 +1000 Subject: [PATCH 08/15] Created Template --- bin/NoteRecollSearch.sh | 105 ++++++++++++++++++++++++++++++++++++++++ bin/cadmus | 13 +++-- bin/template.sh | 105 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 220 insertions(+), 3 deletions(-) create mode 100755 bin/NoteRecollSearch.sh create mode 100755 bin/template.sh diff --git a/bin/NoteRecollSearch.sh b/bin/NoteRecollSearch.sh new file mode 100755 index 0000000..96b3f72 --- /dev/null +++ b/bin/NoteRecollSearch.sh @@ -0,0 +1,105 @@ +#! /usr/bin/env bash +# +# Author: Ryan Greenup + +# * Shell Settings +set -o errexit # abort on nonzero exitstatus +set -o nounset # abort on unbound variable +set -o pipefail # don't hide errors within pipes + +# * Main Function +main() { + + check_for_dependencies + setVars + readFirstArgument "${@}" + NoteSearchRecoll "${@}" + +} + +# ** Helper Functions +# *** Check for Dependencies +check_for_dependencies () { + + for i in ${DependArray[@]}; do + command -v "$i" >/dev/null 2>&1 || { echo >&2 "I require $i but it's not installed. Aborting."; exit 1; } + done + + +} + +# **** List of Dependencies + +declare -a DependArray=( + "rg" + "sk" + "mdcat" + "xclip" + ) + + +# *** Set variables below main +setVars () { + readonly script_name=$(basename "${0}") + readonly script_dir=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) + IFS=$'\t\n' # Split on newlines and tabs (but not on spaces) +} + +# **** Print Help +Help () { + + + echo + echo -e " \e[3m\e[1mNoteFind.sh \e[0m; Helpful Shell Scripts for Markdown Notes" + echo -e " \e[1;31m--------------------------\e[0m " + echo + echo -e " \e[3m\e[1m• Usage \e[0m " + echo + echo -e " "${script_name}" []" + echo -e " "${script_name}" [-h]" + echo -e " "${script_name}" [--help]" + echo + echo -e " \e[3m By Design: No Options; No other Arguments\e[0m" + echo + echo -e " \e[3m\e[1m• Key Bindings\e[0m " + echo + echo + echo -e " \e[1;91m \e[1m Binding \e[0m\e[0m \e[1;34m┊┊┊ \e[0m Description " + echo -e " ..............\e[1;34m┊┊┊\e[0m........................................... " + echo -e " \e[1;95m Ctrl - q \e[0m \e[1;34m ┊┊┊ \e[0m \e[1m Search \e[0m with \e[0m\e[3mripgrep\e[0m" + echo -e " \e[1;93m Ctrl - w \e[0m \e[1;34m ┊┊┊ \e[0m \e[1m Copy \e[0m the Full Path to the Clipboard" + echo -e " \e[1;93m Alt - w \e[0m \e[1;34m ┊┊┊ \e[0m \e[1m Copy \e[0m the Relative Path to the Clipboard" + echo -e " \e[1;94m Alt - e \e[0m \e[1;34m ┊┊┊ \e[0m \e[1m Open \e[0m in Emacs" + echo -e " \e[1;94m Alt - v \e[0m \e[1;34m ┊┊┊ \e[0m \e[1m Open \e[0m in VSCode" + echo -e " \e[1;94m Ctrl - o \e[0m \e[1;34m ┊┊┊ \e[0m \e[1m Open \e[0m in Default Program" + echo + + echo -e " \e[3m\e[1m• Compatability \e[0m " + echo + echo -e " Match highlighting occurs automatically if \e[1m\$SHELL\e[0m is \e[1m **/fish\e[0m" + echo -e " This uses \e[1mtmpfs\e[0m at \e[1m /dev/shm\e[0m, this should work on \e[3mArch\e[0m, \e[3mFedora\e[0m and \e[3mUbuntu\e[0m, I don't know about \e[3mMacOS\e[0m " + echo +} + + +# *** Read First Argument +readFirstArgument () { + + if [[ "${1:-}" == "-h" ]] || [[ "${1:-}" == "--help" ]] || [[ "${1:-}" == "" ]]; then + Help && exit 0 + fi + +} +# *** Note Recoll Search +NoteRecollSearch () { + + ## Change directory if One was specified, exit if no directory exists + cd "${1}" + + echo "This is the function" + + exit 0 +} + +# * Call Main Function +main "${@}" diff --git a/bin/cadmus b/bin/cadmus index 82ae436..2304492 100755 --- a/bin/cadmus +++ b/bin/cadmus @@ -1,5 +1,5 @@ #! /usr/bin/env bash -NOTES_DIR="~/Notes/MD" ## TODO Global Variables are bad +NOTES_DIR="~/Notes/MD/notes" ## TODO Global Variables are bad # Author: Ryan Greenup # abort on nonzero exitstatus set -o errexit @@ -115,9 +115,16 @@ function NoteFind() { fi } -main "${@}" - # *** All the Help subHelp () { + echo + echo + echo -e "\e[1;35m -------------------------\e[0m " + echo -e " \e[1;94m\e[3m\e[1m Cadmus Find \e[0m" + echo -e "\e[1;35m -------------------------\e[0m " NoteFind.sh -h } + +# * Call the Main Function +main "${@}" + diff --git a/bin/template.sh b/bin/template.sh new file mode 100755 index 0000000..96b3f72 --- /dev/null +++ b/bin/template.sh @@ -0,0 +1,105 @@ +#! /usr/bin/env bash +# +# Author: Ryan Greenup + +# * Shell Settings +set -o errexit # abort on nonzero exitstatus +set -o nounset # abort on unbound variable +set -o pipefail # don't hide errors within pipes + +# * Main Function +main() { + + check_for_dependencies + setVars + readFirstArgument "${@}" + NoteSearchRecoll "${@}" + +} + +# ** Helper Functions +# *** Check for Dependencies +check_for_dependencies () { + + for i in ${DependArray[@]}; do + command -v "$i" >/dev/null 2>&1 || { echo >&2 "I require $i but it's not installed. Aborting."; exit 1; } + done + + +} + +# **** List of Dependencies + +declare -a DependArray=( + "rg" + "sk" + "mdcat" + "xclip" + ) + + +# *** Set variables below main +setVars () { + readonly script_name=$(basename "${0}") + readonly script_dir=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) + IFS=$'\t\n' # Split on newlines and tabs (but not on spaces) +} + +# **** Print Help +Help () { + + + echo + echo -e " \e[3m\e[1mNoteFind.sh \e[0m; Helpful Shell Scripts for Markdown Notes" + echo -e " \e[1;31m--------------------------\e[0m " + echo + echo -e " \e[3m\e[1m• Usage \e[0m " + echo + echo -e " "${script_name}" []" + echo -e " "${script_name}" [-h]" + echo -e " "${script_name}" [--help]" + echo + echo -e " \e[3m By Design: No Options; No other Arguments\e[0m" + echo + echo -e " \e[3m\e[1m• Key Bindings\e[0m " + echo + echo + echo -e " \e[1;91m \e[1m Binding \e[0m\e[0m \e[1;34m┊┊┊ \e[0m Description " + echo -e " ..............\e[1;34m┊┊┊\e[0m........................................... " + echo -e " \e[1;95m Ctrl - q \e[0m \e[1;34m ┊┊┊ \e[0m \e[1m Search \e[0m with \e[0m\e[3mripgrep\e[0m" + echo -e " \e[1;93m Ctrl - w \e[0m \e[1;34m ┊┊┊ \e[0m \e[1m Copy \e[0m the Full Path to the Clipboard" + echo -e " \e[1;93m Alt - w \e[0m \e[1;34m ┊┊┊ \e[0m \e[1m Copy \e[0m the Relative Path to the Clipboard" + echo -e " \e[1;94m Alt - e \e[0m \e[1;34m ┊┊┊ \e[0m \e[1m Open \e[0m in Emacs" + echo -e " \e[1;94m Alt - v \e[0m \e[1;34m ┊┊┊ \e[0m \e[1m Open \e[0m in VSCode" + echo -e " \e[1;94m Ctrl - o \e[0m \e[1;34m ┊┊┊ \e[0m \e[1m Open \e[0m in Default Program" + echo + + echo -e " \e[3m\e[1m• Compatability \e[0m " + echo + echo -e " Match highlighting occurs automatically if \e[1m\$SHELL\e[0m is \e[1m **/fish\e[0m" + echo -e " This uses \e[1mtmpfs\e[0m at \e[1m /dev/shm\e[0m, this should work on \e[3mArch\e[0m, \e[3mFedora\e[0m and \e[3mUbuntu\e[0m, I don't know about \e[3mMacOS\e[0m " + echo +} + + +# *** Read First Argument +readFirstArgument () { + + if [[ "${1:-}" == "-h" ]] || [[ "${1:-}" == "--help" ]] || [[ "${1:-}" == "" ]]; then + Help && exit 0 + fi + +} +# *** Note Recoll Search +NoteRecollSearch () { + + ## Change directory if One was specified, exit if no directory exists + cd "${1}" + + echo "This is the function" + + exit 0 +} + +# * Call Main Function +main "${@}" From de74c92bdc66afa4084b3e3dce0c33ae0bc2fcec Mon Sep 17 00:00:00 2001 From: ryangreenup Date: Wed, 15 Jul 2020 00:34:55 +1000 Subject: [PATCH 09/15] Laid out basic Functions --- bin/NoteRecollSearch.sh | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/bin/NoteRecollSearch.sh b/bin/NoteRecollSearch.sh index 96b3f72..11975eb 100755 --- a/bin/NoteRecollSearch.sh +++ b/bin/NoteRecollSearch.sh @@ -31,9 +31,10 @@ check_for_dependencies () { # **** List of Dependencies declare -a DependArray=( - "rg" - "sk" "mdcat" + "mdcat" + "sk" + "recoll" "xclip" ) @@ -98,6 +99,14 @@ NoteRecollSearch () { echo "This is the function" + ## Display full path + sk -i -c 'recoll -b -t -q "ext:md {}" | cut -c 8-' --bind pgup:preview-page-up,pgdn:preview-page-down --preview "bat --color=always --line-range :500 --terminal-width 80 --theme=Dracula {}" + + + ## Display only file name + ## + sk -i -c 'recoll -b -t -q "ext:md" | cut -c 8- | sd \'^\' \'"\' | sd \'$\' \'"\' | sd \'^\' \'basename \' | bash' --bind pgup:preview-page-up,pgdn:preview-page-down --preview "echo {} | xargs fd | xargs bat --color=always --line-range :500 --terminal-width 80 --theme=Dracula " + exit 0 } From b81d045f7e1a9bb3313dbdcd1a48f596de02ecf5 Mon Sep 17 00:00:00 2001 From: ryangreenup Date: Wed, 15 Jul 2020 00:36:24 +1000 Subject: [PATCH 10/15] bat not mdcat --- README.md | 5 +++++ bin/NoteRecollSearch.sh | 3 +-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index b353d4c..48949ff 100644 --- a/README.md +++ b/README.md @@ -146,6 +146,7 @@ It is assumed that: - [VNote](https://github.com/tamlok/vnote) - [Pandoc](https://github.com/jgm/pandoc) - [MarkText](https://github.com/marktext/marktext) +- mdless and imgcat ## Recommended Aliases @@ -166,3 +167,7 @@ TODO [^wpdtmpfs]: [From Wikipedia][shared_memory] Recent 2.6 Linux kernel builds have started to offer /dev/shm as shared memory in the form of a ramdisk, more specifically as a world-writable directory that is stored in memory with a defined limit in /etc/default/tmpfs. /dev/shm support is completely optional within the kernel config file. [*stow*]: https://www.google.com/search?client=firefox-b-d&q=gnu+stow + +## MDCat vs Bat + +MdCat looks better and supports images, unfourtunately the preview fails when files have footnotes and for this reason bat was used (bat is also in the Arch repos and supports more file types) diff --git a/bin/NoteRecollSearch.sh b/bin/NoteRecollSearch.sh index 11975eb..631388c 100755 --- a/bin/NoteRecollSearch.sh +++ b/bin/NoteRecollSearch.sh @@ -31,8 +31,7 @@ check_for_dependencies () { # **** List of Dependencies declare -a DependArray=( - "mdcat" - "mdcat" + "bat" "sk" "recoll" "xclip" From c3957f92bf186c046e3f69764ccd8ea7c147a001 Mon Sep 17 00:00:00 2001 From: ryangreenup Date: Wed, 15 Jul 2020 00:38:00 +1000 Subject: [PATCH 11/15] Changed Note Find to bat MUST TEST --- bin/NoteFind.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/NoteFind.sh b/bin/NoteFind.sh index ec25bf8..5bae7bc 100755 --- a/bin/NoteFind.sh +++ b/bin/NoteFind.sh @@ -126,7 +126,7 @@ SkimGrepHighlightFish () { ramtmp="$(mktemp -p /dev/shm/)" sk -c "echo {} > "${ramtmp}" ; rg -t markdown -l --ignore-case (cat "${ramtmp}")" \ - --preview "mdcat {} 2> /dev/null | \ + --preview "bat --color=always --line-range :500 --terminal-width 80 --theme=Dracula {} 2> /dev/null | \ rg -t markdown --colors 'match:bg:30,200,30' --colors 'match:fg:21,39,200'\ --colors 'match:style:bold' --colors 'line:style:nobold' \ --no-line-number --ignore-case --pretty --context 20 (cat "${ramtmp}")" \ @@ -147,7 +147,7 @@ SkimGrepHighlightFish () { # **** Skim with Grep SkimGrep () { - sk --ansi -c 'rg -l -t markdown --ignore-case "{}"' --preview "mdcat {}" \ + sk --ansi -c 'rg -l -t markdown --ignore-case "{}"' --preview "bat --color=always --line-range :500 --terminal-width 80 --theme=Dracula {}" \ --bind 'ctrl-f:interactive,pgup:preview-page-up,pgdn:preview-page-down' \ --bind 'ctrl-w:execute-silent(echo {} | xargs realpath | xclip -selection clipboard),alt-w:execute-silent(echo {} | xclip -selection clipboard)' \ --bind 'alt-v:execute-silent(code -a {}),alt-e:execute-silent(emacs {}),ctrl-o:execute-silent(xdg-open {})' \ From c152e2c589903ccabb0371b648e00b6cb6a794e2 Mon Sep 17 00:00:00 2001 From: ryangreenup Date: Wed, 15 Jul 2020 00:46:33 +1000 Subject: [PATCH 12/15] Add Relative Path Option --- bin/NoteRecollSearch.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/bin/NoteRecollSearch.sh b/bin/NoteRecollSearch.sh index 631388c..5c00a6c 100755 --- a/bin/NoteRecollSearch.sh +++ b/bin/NoteRecollSearch.sh @@ -106,6 +106,9 @@ NoteRecollSearch () { ## sk -i -c 'recoll -b -t -q "ext:md" | cut -c 8- | sd \'^\' \'"\' | sd \'$\' \'"\' | sd \'^\' \'basename \' | bash' --bind pgup:preview-page-up,pgdn:preview-page-down --preview "echo {} | xargs fd | xargs bat --color=always --line-range :500 --terminal-width 80 --theme=Dracula " + ## Display Path Relative to Notes Dir + sk -i -c 'recoll -b -t -q "ext:md" | cut -c 8- | cut -d \'/\' -f5- ' --bind pgup:preview-page-up,pgdn:preview-page-down --preview "echo {} | xargs basename | xargs fd | xargs realpath | xargs bat --color=always --line-range :500 --terminal-width 80 --theme=Dracula " + exit 0 } From 44833cff797c405c7558689f431b7ceb50a19109 Mon Sep 17 00:00:00 2001 From: ryangreenup Date: Wed, 15 Jul 2020 00:53:47 +1000 Subject: [PATCH 13/15] Figured out how to Relative Recoll Search --- bin/NoteRecollSearch.sh | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/bin/NoteRecollSearch.sh b/bin/NoteRecollSearch.sh index 5c00a6c..4ef097a 100755 --- a/bin/NoteRecollSearch.sh +++ b/bin/NoteRecollSearch.sh @@ -96,7 +96,9 @@ NoteRecollSearch () { ## Change directory if One was specified, exit if no directory exists cd "${1}" - echo "This is the function" + ## I really really like this one!! + ## Display Path Relative to Notes Dir + sk -i -c 'recoll -b -t -q "ext:md" | cut -c 8- | sd \'^\' \'realpath "\' | sd \'$\' \'" --relative-to "./"\' | bash ' --bind pgup:preview-page-up,pgdn:preview-page-down --preview "bat --color=always --line-range :500 --terminal-width 80 --theme=Dracula {}" ## Display full path sk -i -c 'recoll -b -t -q "ext:md {}" | cut -c 8-' --bind pgup:preview-page-up,pgdn:preview-page-down --preview "bat --color=always --line-range :500 --terminal-width 80 --theme=Dracula {}" @@ -106,9 +108,6 @@ NoteRecollSearch () { ## sk -i -c 'recoll -b -t -q "ext:md" | cut -c 8- | sd \'^\' \'"\' | sd \'$\' \'"\' | sd \'^\' \'basename \' | bash' --bind pgup:preview-page-up,pgdn:preview-page-down --preview "echo {} | xargs fd | xargs bat --color=always --line-range :500 --terminal-width 80 --theme=Dracula " - ## Display Path Relative to Notes Dir - sk -i -c 'recoll -b -t -q "ext:md" | cut -c 8- | cut -d \'/\' -f5- ' --bind pgup:preview-page-up,pgdn:preview-page-down --preview "echo {} | xargs basename | xargs fd | xargs realpath | xargs bat --color=always --line-range :500 --terminal-width 80 --theme=Dracula " - exit 0 } From b23fe878dca89a99300247f0e7bad91f6026a58b Mon Sep 17 00:00:00 2001 From: ryangreenup Date: Wed, 15 Jul 2020 00:55:54 +1000 Subject: [PATCH 14/15] TODO for recoll --- todo.org | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/todo.org b/todo.org index 9ad7b1f..b957db6 100644 --- a/todo.org +++ b/todo.org @@ -52,6 +52,14 @@ Completed this by calling help and exiting if the arguments are empty in cadmus. [[file:bin/cadmus::function NoteFind() {][See here]] * TODO [#A] Search +** recoll should use seperate config +Recoll should be called with regard to a config, the idea being i could run: + ++ =cadmus -c personal= ++ =cadmus -c uni= ++ =cadmus -c work= + +and have different note bases * TODO [#A] tags * TODO [#A] tools * TODO [#A] export From e2670555d6c5dd21facb2e83a2db0ec2d7a77f63 Mon Sep 17 00:00:00 2001 From: ryangreenup Date: Wed, 15 Jul 2020 10:07:47 +1000 Subject: [PATCH 15/15] Added layout for skim recoll --- bin/NoteRecollSearch.sh | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/bin/NoteRecollSearch.sh b/bin/NoteRecollSearch.sh index 4ef097a..78c9f28 100755 --- a/bin/NoteRecollSearch.sh +++ b/bin/NoteRecollSearch.sh @@ -91,22 +91,23 @@ readFirstArgument () { } # *** Note Recoll Search -NoteRecollSearch () { +NoteSearchRecoll () { ## Change directory if One was specified, exit if no directory exists cd "${1}" + ## I really really like this one!! ## Display Path Relative to Notes Dir - sk -i -c 'recoll -b -t -q "ext:md" | cut -c 8- | sd \'^\' \'realpath "\' | sd \'$\' \'" --relative-to "./"\' | bash ' --bind pgup:preview-page-up,pgdn:preview-page-down --preview "bat --color=always --line-range :500 --terminal-width 80 --theme=Dracula {}" + sk -i -c 'recoll -b -t -q "ext:md" | cut -c 8- | sd '^' 'realpath "' | sd '$' '" --relative-to "./"' | bash ' --bind pgup:preview-page-up,pgdn:preview-page-down --preview "bat --color=always --line-range :500 --terminal-width 80 --theme=Dracula {}" - ## Display full path - sk -i -c 'recoll -b -t -q "ext:md {}" | cut -c 8-' --bind pgup:preview-page-up,pgdn:preview-page-down --preview "bat --color=always --line-range :500 --terminal-width 80 --theme=Dracula {}" - - - ## Display only file name - ## - sk -i -c 'recoll -b -t -q "ext:md" | cut -c 8- | sd \'^\' \'"\' | sd \'$\' \'"\' | sd \'^\' \'basename \' | bash' --bind pgup:preview-page-up,pgdn:preview-page-down --preview "echo {} | xargs fd | xargs bat --color=always --line-range :500 --terminal-width 80 --theme=Dracula " +## ## Display full path +## sk -i -c 'recoll -b -t -q "ext:md {}" | cut -c 8-' --bind pgup:preview-page-up,pgdn:preview-page-down --preview "bat --color=always --line-range :500 --terminal-width 80 --theme=Dracula {}" +## +## +## ## Display only file name +## ## +## sk -i -c 'recoll -b -t -q "ext:md" | cut -c 8- | sd \'^\' \'"\' | sd \'$\' \'"\' | sd \'^\' \'basename \' | bash' --bind pgup:preview-page-up,pgdn:preview-page-down --preview "echo {} | xargs fd | xargs bat --color=always --line-range :500 --terminal-width 80 --theme=Dracula " exit 0 }