diff --git a/.Rhistory b/.Rhistory new file mode 100644 index 0000000..e69de29 diff --git a/bin/NoteFind.sh b/bin/NoteFind.sh index b43ae6b..38a810b 100755 --- a/bin/NoteFind.sh +++ b/bin/NoteFind.sh @@ -91,7 +91,7 @@ readFirstArgument () { SkimNotes () { ## Change directory if One was specified, exit if no directory exists - + cd "${1}" FILE="$(SkimGrep)" diff --git a/bin/cadmus b/bin/cadmus index 77bf9a4..9217196 100755 --- a/bin/cadmus +++ b/bin/cadmus @@ -1,8 +1,12 @@ #! /usr/bin/env bash -readonly NOTES_DIR="$HOME/Notes/MD/notes" ## TODO Global Variables are bad -readonly SERVER_DIR="/srv/www/html/MD" -readonly RECOLL_CONFIG_DIR="$HOME/.cadmus" -readonly MKDOCS_YML="$HOME/Notes/mkdocs.yml" ## This may be above the notes directory, the + IFS=$'\t\n' # Split on newlines and tabs (but not on spaces) + readonly script_name=$(basename "${0}") + script_dir=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) + readonly script_dir=$(realpath "${script_dir}""/""${script_name}" | xargs dirname) +readonly CONFIG=$(realpath "${script_dir}/../config.json") # one directory above +## readonly SERVER_DIR="/srv/www/html/MD" +## readonly RECOLL_CONFIG_DIR="$HOME/.cadmus" +## readonly MKDOCS_YML="$HOME/Notes/mkdocs.yml" ## This may be above the notes directory, the ## notes directory may not contain all the ## images for want of seperation and mkdocs is ## fidally, so specify the path to mkdocs.yml. @@ -18,7 +22,7 @@ set -o pipefail # * Main Functions main() { - + checkConfig setvars [[ -z "${1:-}" ]] && mainHelp && exit 0 arguments "${@:-}" @@ -26,12 +30,14 @@ main() { function setvars() { - IFS=$'\t\n' # Split on newlines and tabs (but not on spaces) - readonly script_name=$(basename "${0}") - script_dir=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) - readonly script_dir=$(realpath "${script_dir}""/""${script_name}" | xargs dirname) readonly TERMINAL="kitty" readonly TERMINAL_EXEC='kitty -- ' + + + readonly NOTES_DIR="$(cat "${CONFIG}" | jq -r '.notesDir')" + readonly SERVER_DIR="$(cat "${CONFIG}" | jq -r '.serverDir')" + readonly RECOLL_CONFIG_DIR="$(cat "${CONFIG}" | jq -r '.recollConfigDir')" + readonly MKDOCS_YML="$(cat "${CONFIG}" | jq -r '.mkdocsConfigDir')" ## This may be above the notes directory, the } @@ -66,6 +72,33 @@ function mainHelp() { } # ** Main Arguments - Level 0 +# *** Config +checkConfig () { + if [[ -f "${CONFIG}" ]]; then + echo "Config Detected" + else + echo -e "No config File detected at ${CONFIG}" + echo -e "Would you like to generate a config?" + echo + echo -e "Press y to continue or any other key to exit." + echo + read -d '' -s -n1 choice + if [[ "${choice}" == "y" ]]; then + config_json=$("${script_dir}/makeConfig.bash") + if [[ "${config_json}" != "" ]]; then + echo "${config_json}" > "${CONFIG}" + echo -e "This is the Config:\n" + highlight "${CONFIG}" + else + echo "Config not Generated" + exit 1 + fi + else + exit 0 + fi + fi + +} # *** Switch arguments () { diff --git a/bin/makeConfig.bash b/bin/makeConfig.bash new file mode 100755 index 0000000..b05d24a --- /dev/null +++ b/bin/makeConfig.bash @@ -0,0 +1,142 @@ +#! /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() { + + # Use STDERR so as to not clog STDIN + # Is there a better way to do this? + echoerr() { echo -e "$@" 1>&2; } + + + check_for_dependencies + setVars + readFirstArgument "${@}" + AskValues + + if [ "${promptComplete}" != "Completed" ]; then + exit 1 + fi + + MakeConfig "${@}" + +} + +# ** 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=( + "jq" + "cat" + "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[1mMakeConfig.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}" [-h]" + echo -e " "${script_name}" [--help]" + echo + echo -e " Fully Interactive, just follow the prompts" + echo + echo -e " \e[3m By Design: No Options; No Arguments\e[0m" + echo + echo -e " \e[3m\e[1m• Compatability \e[0m " + echo + echo -e " This prints everything to STDERR to that STDOUT only has" + echo -e " The config file in it, I'm not sure if that's an issue " + echo + exit 0 +} + + +# *** Read First Argument +readFirstArgument () { + + if [[ "${1:-}" == "-h" ]] || [[ "${1:-}" == "--help" ]]; then + Help && exit 0 + fi + +} + +# *** +AskValues () { + echoerr "Please Enter the Directory of you Markdown Files" + echoerr "\t (This directory should contain index.md or home.md)" + read NOTES_DIR + NOTES_DIR="$(echo "${NOTES_DIR/\~/$HOME}")" + read -d '' -s -n1 choice +# NOTES_DIR="$(cd /; sk --height 40% -i -c 'fd {}' )" + [[ -d "${NOTES_DIR}" ]] || echoerr -e "\n \e[3m\e[1m \e[1;31m ⚠ WARNING: \e[0m No Such Directory!" + + + echoerr "\nPlease Enter the Directory of the recoll config you want to use" + echoerr "\t Leave it blank to use the default config" + echoerr "\t This is not implemented so don't worry" + read RECOLL_CONFIG_DIR + RECOLL_CONFIG_DIR="$(echo "${RECOLL_CONFIG_DIR/\~/$HOME}")" + [[ -d "${RECOLL_CONFIG_DIR}" ]] || echoerr "\n \e[3m\e[1m \e[1;31m ⚠ WARNING: \e[0m No Such Directory!" + + echoerr "\nPlease Enter the location of your mkdocs yml" + echoerr "\t (If you're not going to use this just leave it blank and press Enter)" + read MKDOCS_YML + MKDOCS_YML="$(echo "${MKDOCS_YML/\~/$HOME}")" + [[ -f "${MKDOCS_YML}" ]] || echoerr -e "\n \e[3m\e[1m \e[1;31m ⚠ WARNING: \e[0m No Such File!" + + echoerr "\nPlease Enter the Directory in which you want mkdocs to build your static site" + echoerr "\t (If you're not going to use this just leave it blank and press Enter)" + read SERVER_DIR + SERVER_DIR="$(echo "${SERVER_DIR/\~/$HOME}")" + [[ -d "${SERVER_DIR}" ]] || echoerr -e "\n \e[3m\e[1m \e[1;31m ⚠ WARNING: \e[0m No Such Directory!" + + promptComplete="Completed" + +} +# *** Make Config +MakeConfig () { + +JSON_STRING=$( jq -n \ + --arg nd "$NOTES_DIR" \ + --arg sd "$SERVER_DIR" \ + --arg rc "$RECOLL_CONFIG_DIR" \ + --arg mk "$MKDOCS_YML" \ + '{notesDir: $nd, serverDir: $sd, recollConfigDir: $rc, mkdocsConfigDir: $mk}' ) + + echo "$JSON_STRING" + + exit 0 +} + +# * Call Main Function +main "${@}" diff --git a/sd b/sd new file mode 100644 index 0000000..e69de29 diff --git a/sed b/sed new file mode 100644 index 0000000..e69de29