mirror of
https://github.com/RyanGreenup/cadmus.git
synced 2025-08-30 09:10:16 +02:00
Merge branch 'master' of https://github.com/RyanGreenup/cadmus
This commit is contained in:
261
bin/NoteFind.sh
261
bin/NoteFind.sh
@@ -10,147 +10,14 @@ 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
|
||||
# *** Skim and Grep, the important stuff
|
||||
SkimAndGrep () {
|
||||
|
||||
## Change directory if One was specified, exit if no directory exists
|
||||
|
||||
if [ "${1:-}" != "" ]; then
|
||||
cd "${1}" || exit 4
|
||||
fi
|
||||
|
||||
|
||||
## If using fish, cleverness can be utilised to highlight matches.
|
||||
## fish only, not zsh or bash
|
||||
|
||||
if [[ "$(basename $SHELL)" == "fish" ]]; then
|
||||
SkimGrepHighlightFish | xargs realpath && exit 0
|
||||
else
|
||||
SkimGrep | xargs realpath && exit 0
|
||||
fi
|
||||
|
||||
|
||||
exit 0
|
||||
|
||||
}
|
||||
|
||||
# **** Skim with Highlight of Grep for Fish
|
||||
SkimGrepHighlightFish () {
|
||||
|
||||
ramtmp="$(mktemp -p /dev/shm/)"
|
||||
sk -c "echo {} > "${ramtmp}" ; rg -t markdown -l --ignore-case (cat "${ramtmp}")" \
|
||||
--preview "mdcat {} 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}")" \
|
||||
--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-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)' \
|
||||
## TODO This should be emacsclient
|
||||
## TODO This should be emacsclient
|
||||
## Add -i to make it interactive from the start
|
||||
## 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 () {
|
||||
|
||||
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)'
|
||||
|
||||
}
|
||||
|
||||
# *** Interpret arguments
|
||||
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 <path/to/notes] [-h]"
|
||||
echo -e " "${script_name}" [--dir <path/to/notes/] [--help]"
|
||||
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 Highligting 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
|
||||
}
|
||||
|
||||
|
||||
# *** Check for Dependencies
|
||||
check_for_dependencies () {
|
||||
|
||||
@@ -171,5 +38,125 @@ declare -a DependArray=(
|
||||
)
|
||||
|
||||
|
||||
## * Call Main Function
|
||||
# *** 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}" [<path/to/notes>]"
|
||||
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
|
||||
|
||||
}
|
||||
# *** Skim and Grep, the important stuff
|
||||
SkimNotes () {
|
||||
|
||||
## Change directory if One was specified, exit if no directory exists
|
||||
|
||||
cd "${1}"
|
||||
|
||||
## If using fish, cleverness can be utilised to highlight matches.
|
||||
## fish only, not zsh or bash
|
||||
|
||||
if [[ "$(basename $SHELL)" == "fish" ]]; then
|
||||
FILE="$(SkimGrepHighlightFish)"
|
||||
if [[ $FILE != "" ]]; then
|
||||
realpath $FILE && exit 0
|
||||
else
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
FILE="$(SkimGrep)"
|
||||
if [[ $FILE != "" ]]; then
|
||||
realpath $FILE && exit 0
|
||||
else
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
|
||||
exit 0
|
||||
|
||||
}
|
||||
|
||||
# **** Skim with Highlight of Grep for Fish
|
||||
SkimGrepHighlightFish () {
|
||||
|
||||
ramtmp="$(mktemp -p /dev/shm/)"
|
||||
sk -c "echo {} > "${ramtmp}" ; rg -t markdown -l --ignore-case (cat "${ramtmp}")" \
|
||||
--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}")" \
|
||||
--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 {})' \
|
||||
--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)' \
|
||||
## TODO This should be emacsclient
|
||||
## TODO This should be emacsclient
|
||||
## Add -i to make it interactive from the start
|
||||
## C-q toggles interactive
|
||||
## C-y Copies Full path to clipboard
|
||||
}
|
||||
|
||||
|
||||
# **** Skim with Grep
|
||||
SkimGrep () {
|
||||
|
||||
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 {})' \
|
||||
--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)' \
|
||||
|
||||
}
|
||||
|
||||
|
||||
# * Call Main Function
|
||||
main "${@}"
|
||||
|
116
bin/NoteRecollSearch.sh
Executable file
116
bin/NoteRecollSearch.sh
Executable file
@@ -0,0 +1,116 @@
|
||||
#! /usr/bin/env bash
|
||||
#
|
||||
# Author: Ryan Greenup <ryan.greenup@protonmail.com>
|
||||
|
||||
# * 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=(
|
||||
"bat"
|
||||
"sk"
|
||||
"recoll"
|
||||
"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}" [<path/to/notes>]"
|
||||
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
|
||||
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 {}"
|
||||
|
||||
## ## 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
|
||||
}
|
||||
|
||||
# * Call Main Function
|
||||
main "${@}"
|
74
bin/cadmus
74
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 <ryan.greenup@protonmail.com>
|
||||
# abort on nonzero exitstatus
|
||||
set -o errexit
|
||||
@@ -9,7 +9,7 @@ set -o nounset
|
||||
set -o pipefail
|
||||
|
||||
|
||||
## * Main Functions
|
||||
# * Main Functions
|
||||
|
||||
main() {
|
||||
|
||||
@@ -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
|
||||
@@ -61,7 +62,7 @@ function mainHelp() {
|
||||
}
|
||||
|
||||
# ** Main Arguments - Level 0
|
||||
#
|
||||
# *** Switch
|
||||
arguments () {
|
||||
|
||||
while test $# -gt 0
|
||||
@@ -71,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"
|
||||
;;
|
||||
@@ -89,6 +90,8 @@ arguments () {
|
||||
;;
|
||||
preview) echo "begin preview"
|
||||
;;
|
||||
help) subHelp && exit 0
|
||||
;;
|
||||
--*) >&2 echo "bad option $1"
|
||||
;;
|
||||
*) >&2 echo -e "argument \e[1;35m${1}\e[0m has no definition."
|
||||
@@ -101,56 +104,27 @@ 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
|
||||
# *** 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 "${@}"
|
||||
|
||||
|
||||
|
||||
##########################################################################
|
||||
# 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 #
|
||||
# } #
|
||||
##########################################################################
|
||||
|
135
bin/template.sh
135
bin/template.sh
@@ -9,76 +9,15 @@ set -o pipefail # don't hide errors within pipes
|
||||
|
||||
# * Main Function
|
||||
main() {
|
||||
setVars
|
||||
|
||||
check_for_dependencies
|
||||
arguments "${@}"
|
||||
SkimAndGrep
|
||||
setVars
|
||||
readFirstArgument "${@}"
|
||||
NoteSearchRecoll "${@}"
|
||||
|
||||
}
|
||||
|
||||
# ** Helper Functions
|
||||
# *** Skim and Grep, the important stuff
|
||||
ActualWork () {
|
||||
|
||||
echo "I am a Template"
|
||||
|
||||
}
|
||||
|
||||
#
|
||||
#
|
||||
# *** 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)
|
||||
}
|
||||
|
||||
# *** Interpret arguments
|
||||
arguments () {
|
||||
while test $# -gt 0
|
||||
do
|
||||
case "$1" in
|
||||
--help) Help
|
||||
;;
|
||||
-h) Help
|
||||
;;
|
||||
--*) echo "bad option $1 in "${script_name}""
|
||||
;;
|
||||
*) echo -e "argument \e[1;35m${1}\e[0m has no definition."
|
||||
;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
}
|
||||
|
||||
# *** 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[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 " 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
|
||||
exit 0
|
||||
}
|
||||
|
||||
|
||||
# *** Check for Dependencies
|
||||
check_for_dependencies () {
|
||||
|
||||
@@ -99,5 +38,69 @@ declare -a DependArray=(
|
||||
)
|
||||
|
||||
|
||||
## * Call Main Function
|
||||
# *** 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}" [<path/to/notes>]"
|
||||
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
|
||||
exit 0
|
||||
}
|
||||
|
||||
|
||||
# *** 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 "${@}"
|
||||
|
184
bin/template.sh.orig
Executable file
184
bin/template.sh.orig
Executable file
@@ -0,0 +1,184 @@
|
||||
#! /usr/bin/env bash
|
||||
#
|
||||
# Author: Ryan Greenup <ryan.greenup@protonmail.com>
|
||||
|
||||
# * 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() {
|
||||
<<<<<<< HEAD
|
||||
setVars
|
||||
check_for_dependencies
|
||||
arguments "${@}"
|
||||
SkimAndGrep
|
||||
=======
|
||||
|
||||
check_for_dependencies
|
||||
setVars
|
||||
readFirstArgument "${@}"
|
||||
NoteSearchRecoll "${@}"
|
||||
>>>>>>> e2670555d6c5dd21facb2e83a2db0ec2d7a77f63
|
||||
|
||||
}
|
||||
|
||||
# ** Helper Functions
|
||||
<<<<<<< HEAD
|
||||
# *** Skim and Grep, the important stuff
|
||||
ActualWork () {
|
||||
|
||||
echo "I am a Template"
|
||||
|
||||
}
|
||||
|
||||
#
|
||||
#
|
||||
=======
|
||||
# *** 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"
|
||||
)
|
||||
|
||||
|
||||
>>>>>>> e2670555d6c5dd21facb2e83a2db0ec2d7a77f63
|
||||
# *** 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)
|
||||
}
|
||||
|
||||
<<<<<<< HEAD
|
||||
# *** Interpret arguments
|
||||
arguments () {
|
||||
while test $# -gt 0
|
||||
do
|
||||
case "$1" in
|
||||
--help) Help
|
||||
;;
|
||||
-h) Help
|
||||
;;
|
||||
--*) echo "bad option $1 in "${script_name}""
|
||||
;;
|
||||
*) echo -e "argument \e[1;35m${1}\e[0m has no definition."
|
||||
;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
}
|
||||
|
||||
# *** Print Help
|
||||
|
||||
=======
|
||||
# **** Print Help
|
||||
>>>>>>> e2670555d6c5dd21facb2e83a2db0ec2d7a77f63
|
||||
Help () {
|
||||
|
||||
|
||||
echo
|
||||
<<<<<<< HEAD
|
||||
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[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}" [<path/to/notes>]"
|
||||
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
|
||||
>>>>>>> e2670555d6c5dd21facb2e83a2db0ec2d7a77f63
|
||||
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
|
||||
<<<<<<< HEAD
|
||||
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
|
||||
exit 0
|
||||
}
|
||||
|
||||
|
||||
# *** 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"
|
||||
)
|
||||
|
||||
|
||||
## * Call Main Function
|
||||
=======
|
||||
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
|
||||
>>>>>>> e2670555d6c5dd21facb2e83a2db0ec2d7a77f63
|
||||
main "${@}"
|
Reference in New Issue
Block a user