From 8c11125e044c41867ad0e77045dd66ef769854db Mon Sep 17 00:00:00 2001 From: Ryan Greenup Date: Mon, 20 Jul 2020 00:15:53 +1000 Subject: [PATCH] [FEAT]: Global Preview with QR Code --- bin/cadmus | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/bin/cadmus b/bin/cadmus index 2e47c7c..77bf9a4 100755 --- a/bin/cadmus +++ b/bin/cadmus @@ -55,7 +55,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 " @@ -94,6 +94,8 @@ arguments () { ;; preview) 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" @@ -294,7 +296,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)" @@ -526,6 +528,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 () {