1
0
mirror of https://github.com/RyanGreenup/cadmus.git synced 2025-08-30 17:19:47 +02:00

Merge branch 'master' into feature/shorter-alternatives

This commit is contained in:
RyanGreenup
2020-07-20 19:51:43 +10:00
committed by GitHub
13 changed files with 445 additions and 319 deletions

View File

@@ -91,7 +91,7 @@ readFirstArgument () {
SkimNotes () {
## Change directory if One was specified, exit if no directory exists
cd "${1}"
FILE="$(SkimGrep)"

View File

@@ -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
}
@@ -55,7 +61,7 @@ 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;93m preview \e[0m \e[1;34m ┊┊┊ 🎆\e[0m Preview with \e[1;34m \e[4m\e[3mMarkServ\e[0m\e[0m (use chrome for this)"
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 (use 'preview!' for global)"
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 "
@@ -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 () {
@@ -90,8 +123,14 @@ arguments () {
;;
publish|pub) shift; CadmusPublish "${@:-}"
;;
publish) shift; CadmusPublish "${@:-}"
;;
preview|p) shift; cd "${NOTES_DIR}" && markserv || echo -e " \n \e[1;34m maybe fix this with:\n\tsudo fuser 35729/tcp -k \n \tor\n\tkillall markserv \e[0m\n"
;;
preview!) shift; previewGlobal
;;
help) subHelp && exit 0
;;
--*) >&2 echo "bad option $1"
;;
*) >&2 echo -e "argument \e[1;35m${1}\e[0m has no definition."
@@ -290,7 +329,7 @@ makeNewNote () {
echo -e "Please Choose Relevant Tags (Use Tab for Multi Select)"
echo -e "\n\t(Press any key to continue)"
read -d '' -s -n1 choice
## Choose Tags
TAGS="$(node "${script_dir}"/tags/yaml-parse.js "${NOTES_DIR}" 2>/dev/null | sort -u| sk -m)"
@@ -522,6 +561,28 @@ CadmusConvert () {
}
# *** Preview Global
previewGlobal() {
MARKSERVPORT="28754"
cd "${NOTES_DIR}"
printQR
markserv -p "${MARKSERVPORT}" -a 0.0.0.0 || echo -e " \n \e[1;34m maybe fix this with:\n\tsudo fuser 35729/tcp -k \n \tor\n\tkillall markserv \e[0m\n"
}
# **** Print QR
printQR () {
command -v qrencode >/dev/null 2>&1 || { echo -e >&2 "I require qrencode but it's not installed.\nNo QR Code can be printed."; return; }
command -v ip >/dev/null 2>&1 || { echo -e >&2 "I requre ip but it's not installed.\nNo QR Code can be printed."; return; }
CURRENTIP="$(ip route get 1 | sed -n 's/^.*src \([0-9.]*\) .*$/\1/p')"
qrencode -t UTF8 "http://${CURRENTIP}:${MARKSERVPORT}"
}
# **** Help
function ConvertHelp () {

142
bin/makeConfig.bash Executable file
View File

@@ -0,0 +1,142 @@
#! /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() {
# 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 "${@}"