1
0
mirror of https://github.com/RyanGreenup/cadmus.git synced 2025-04-21 18:21:51 +02:00

Compare commits

..

37 Commits
1.0 ... master

Author SHA1 Message Date
Ryan Greenup
e0c5792ea0 [Fix] I forgot a pipe, now it's really fixed 2021-04-24 21:55:02 +10:00
Ryan Greenup
8f287cd9a6 [FIX] finally fixed search and find skim bug 2021-04-24 21:52:14 +10:00
Ryan Greenup
436c38333e Added Quotes in script 2021-04-05 15:54:26 +10:00
Ryan Greenup
1de6fd252c Merge branch 'master' of https://github.com/RyanGreenup/cadmus 2021-03-05 18:44:40 +11:00
RyanGreenup
a797617a95
fix install script missing quotation mark 2021-03-05 18:43:45 +11:00
Ryan Greenup
3b5e202610 Fix Backlinks 2021-02-12 16:03:44 +11:00
Ryan Greenup
d8c6311130 Merge branch 'master' of https://github.com/RyanGreenup/cadmus 2021-01-27 18:57:28 +11:00
Ryan Greenup
7a566a3a56 Significantly improved webtitle printing time 2021-01-27 18:13:50 +11:00
Ryan Greenup
b6fd03ebb4 Backlinks Script takes argument, not static dir 2021-01-27 17:37:39 +11:00
Ryan Greenup
8a6817a5aa Use xdg-open 2021-01-27 16:11:15 +11:00
Ryan Greenup
d130c69c8b Began writing tool to print unused attachments 2021-01-26 13:49:56 +11:00
Ryan Greenup
141d2060f5 Changed XDG-Open to EDITOR Var
This is because XDG-Open was causing me nothing
but headaches, ideally the EDITOR variable should
go into the config settings.
2021-01-11 10:53:49 +11:00
Ryan Greenup
d81d75913c Added a Py script to extract tags from org-mode, it doesn't work yet 2020-11-16 16:15:02 +11:00
Ryan Greenup
af3cf9359b Added some logic for Rofi Find (See Joplin for some notes on this) 2020-11-16 15:03:26 +11:00
Ryan Greenup
fd3e576e28 Merge changes, notesearch uses bat and finds org
Merge branch 'master' of https://github.com/RyanGreenup/cadmus
2020-11-16 10:42:54 +11:00
Ryan Greenup
6ec665f5ba Added a Changelog 2020-11-16 10:41:55 +11:00
Ryan Greenup
94820060f0 Added a menu for rofi 2020-11-16 10:41:50 +11:00
Ryan Greenup
28e1defe5b Removed Line numbers from bat
By adding org files I would want to change the config directory to also
enapsulate org files, I don't know if changing this directory would be
such that mkdocs breaks, it probably doesn't matter though because I
would sooner use dokuwiki or joplin for that.

It also means that I would need to index the ~/Notes directory and
ignore joplin as well as the wiki/
2020-11-15 16:43:21 +11:00
Ryan Greenup
56d0ce6332 Added Org Files to Recoll Search 2020-11-15 16:26:27 +11:00
Ryan Greenup
b89e0f5399 Add Org, switched back to bat not mdcat rm numbers 2020-11-15 16:14:35 +11:00
Ryan Greenup
ffa1640104 Changed Note Search to MDCat from Bat
(for aesthetics)
2020-10-01 09:12:25 +10:00
Ryan Greenup
93d950db6a Merge branch 'master' of https://github.com/RyanGreenup/cadmus into master 2020-09-21 23:02:26 +10:00
Ryan Greenup
c242fa019b Fixed Calling Help 2020-09-21 19:26:39 +10:00
Ryan Greenup
9bc457f7ca Install Script Makes Directory if it doesn't exist 2020-09-14 23:27:30 +10:00
Ryan Greenup
81e3d203e9 Removed unnecessary extensions 2020-09-14 22:10:03 +10:00
Ryan Greenup
31af8a4a35 Fixed Broken Math in HTML Export 2020-09-14 21:42:13 +10:00
Ryan Greenup
97bbc6a90b Fixed Exporting Files with Relative Directories 2020-09-14 11:49:56 +10:00
Ryan Greenup
7f4ace524b import mediawiki bug 2020-09-06 17:26:05 +10:00
Ryan Greenup
3379e1eb7b Remove broken export stuff 2020-09-06 17:22:11 +10:00
Ryan Greenup
64c3f6845d More export issues 2020-09-06 15:42:11 +10:00
Ryan Greenup
40a36d7f14 Switched to MDCat in Anticipation of Fix 2020-09-06 15:36:46 +10:00
Ryan Greenup
8f0b100157 mathjax issue 2020-09-06 15:31:00 +10:00
Ryan Greenup
2e7029c3ce TODO Export 2020-09-06 15:30:06 +10:00
RyanGreenup
5448b2e747
Merge pull request #15 from erjanmx/fix-readme-typo
Fix readme typo
2020-07-26 09:37:33 +10:00
Erjan Kalybek
4477ffbcdc Fix typo 2020-07-25 18:34:41 +02:00
Ryan Greenup
0c4ade9fb7 idea for config search 2020-07-25 11:59:28 +10:00
Ryan Greenup
668118f759 Update Readme; Plugin for VSCode 2020-07-25 09:23:26 +10:00
14 changed files with 699 additions and 40 deletions

15
CHANGELOG.org Normal file
View File

@ -0,0 +1,15 @@
#+TITLE: Changelog
- Find/Search Now also supports ~org~ files
- Switched from ~mdcat~ back to ~bat~, because
+ ~bat~ works with ~.org~ without needing to use org-ruby or pandoc
+ Still having issues with ~mdcat~ not displaying results ocasionally (is this an issue with footnotes?)
- Added Rofi Menu
+ This doesn't work yet
- Rofi_find doesn't disown the browser for some reason
- Does not return the matched file name
- things typed in to rofi are not remembered after a preview
- Added a tag Py Script
+ This doesn't work yet
- using str-split to seperate filename and tag doesn't work well because
~:~ characters in the heading become a tag seperator.
- I can't use look behind because it is a non-constant length

View File

@ -119,7 +119,7 @@ then select *index configuration* and configure recoll to have `~/Notes/MD` as t
## Design Philosophy
- ****<span style="color:rgb(90,210,90);font-family:Courier New,Courier, monospace,serif;">cadmus</span>**** acts as a menu for scripts to acheive things
- ****<span style="color:rgb(90,210,90);font-family:Courier New,Courier, monospace,serif;">cadmus</span>**** acts as a menu for scripts to achieve things
- The Actual work will be done by subscripts denoted by `description.bash`
- The subscripts will take the note directory as an argument so they are portable and modular
- The Arguments will be shifted and then all passed down to subfunctions
@ -196,6 +196,7 @@ This was a dependency but I switched to java script
- [readability-cli](https://gitlab.com/gardenappl/readability-cli)
- [VNote](https://github.com/tamlok/vnote)
- VSCode
- [vscode-memo](https://github.com/svsool/vscode-memo/blob/master/CHANGELOG.md)
### PATH

15
bin/00TODOConfig.sh Normal file
View File

@ -0,0 +1,15 @@
#!/usr/bin/env bash
set -euo pipefail
conlook () {
if [[ -f ./.config.json ]]; then
CONFIG="./config.json"
return
elif [[ CONFIG == "" ]]
if [[ "$(pwd)" == "/" ]]; then
CONFIG="~/.config/cadmus/config.json"
else
cd ..
fi
conlook
}

View File

@ -21,7 +21,7 @@ main() {
# *** Check for Dependencies
check_for_dependencies () {
for i in ${DependArray[@]}; do
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
@ -55,9 +55,9 @@ Help () {
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 -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
@ -96,7 +96,7 @@ SkimNotes () {
FILE="$(SkimGrep)"
if [[ $FILE != "" ]]; then
realpath $FILE && exit 0
realpath "${FILE}" && exit 0
fi
exit 0
@ -106,8 +106,10 @@ SkimNotes () {
# **** Skim with Grep
SkimGrep () {
sk --ansi -m -c 'rg -l -t markdown --ignore-case "{}"' \
--preview "bat {} 2> /dev/null \
find . -type f \( -name "*.org" -o -name "*.md" \) |\
sk --ansi -m -c 'rg -l -t markdown -t org -t txt --ignore-case "{}"' \
--preview "bat --style snip {} 2> /dev/null \
--color=always --line-range :500 \
--terminal-width 80 \
--theme=TwoDark |\

View File

@ -117,11 +117,13 @@ NoteSearchRecoll () {
# 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 {}"
# Better Theme
RelativePath () {
sk -m -i -c 'recoll -b -t -q "ext:md" {} |\
find . -type f \( -name "*.org" -o -name "*.md" \) |\
sk -m -i -c 'recoll -b -t -q "ext:md OR ext:org" {} |\
cut -c 8- | sed s/^/realpath\ \"/ |\
sed s+\$+\"\ --relative-to\ \"./\"+ | bash' \
--bind pgup:preview-page-up,pgdn:preview-page-down \
--preview "bat --color=always --line-range :500 \
--preview "bat --style grid --color=always --line-range :500 \
--terminal-width 80 --theme=TwoDark {+} \
--italic-text=always \
--decorations=always" \

149
bin/NoteRecollSearch.sh.orig Executable file
View File

@ -0,0 +1,149 @@
#! /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[1m ${script_name}\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/relative/Dir>]"
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• Notes\e[0m "
echo
echo -e " Often path names are too long to see in sk, "
echo -e " although they do provide meaningful context,"
echo -e " by displaying the pathnames relative from some directory"
echo -e " this is somewhat addressed."
echo -e " Absolute Paths are still returned for stability though."
echo
echo -e " Highlighting only works on the first word, I can't think of an easy"
echo -e " way to convert a list of values ("dog" "fox" "jump") and then perform "
echo -e " bat {} | rg -e dog -e fox -e jump " | highlight --syntax bash -O ansi
echo
echo -e " \e[3m\e[1m• Compatability \e[0m "
echo
echo -e " This uses realpath from GNU coreutils, which doesn't"
echo -e " come with MacOS out of the box"
echo
echo -e " This doesn't work: "
echo -e ' rg "$(echo {cq} | rg "$(echo $var | sed s+\ +\|+g )") ' | highlight --syntax bash -O ansi
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 {}"
# Better Theme
RelativePath () {
sk -m -i -c 'recoll -b -t -q "ext:md OR ext:org" {} |\
cut -c 8- | sed s/^/realpath\ \"/ |\
sed s+\$+\"\ --relative-to\ \"./\"+ | bash' \
--bind pgup:preview-page-up,pgdn:preview-page-down \
<<<<<<< HEAD
--preview "bat --style grid --color=always --line-range :500 \
--terminal-width 80 --theme=TwoDark {+} \
--italic-text=always \
--decorations=always" \
=======
--preview "mdcat {+}" \
>>>>>>> ffa1640104ce9c097d1233a7d5745cd95fb9f7fb
--color=fg:#f8f8f2,bg:-1,matched:#6272a4,current_fg:#50fa7b,current_bg:#381070,border:#ff79c6,prompt:#bd93f9,query:#bd93f9,marker:#f1fa8c,header:#f1fa8c
}
RELATIVE_PATH="$(RelativePath)"
echo "${RELATIVE_PATH}" | xargs realpath
## ## 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 "${@}"

View File

@ -18,6 +18,8 @@ set -o nounset
# don't hide errors within pipes
set -o pipefail
# readonly EDITOR="ema"
readonly EDITOR="xdg-open"
# * Main Functions
@ -97,6 +99,7 @@ function mainHelp() {
echo -e " 🔍 \e[1;93m \e[4mf\e[0m\e[1;93mind \e[0m \e[1;34m ┊┊┊ 🎆 \e[0m Find Notes based on FileName"
echo -e " 🔎 \e[1;32m \e[4ms\e[0m\e[1;32mearch \e[0m \e[1;34m ┊┊┊ 🎆 \e[0m Search through Notes using Recoll"
echo -e " 🏷 \e[1;33m \e[4mt\e[0m\e[1;33mags \e[0m \e[1;34m ┊┊┊ 📁\e[0m Use TMSU to work with tags"
echo -e " 📖 \e[1;33m \e[4mr\e[0m\e[1;33mofi \e[0m \e[1;34m ┊┊┊ 📁\e[0m Use ROFI instead of fzf (WIP) "
echo -e " 🔧 \e[1;34m \e[4mto\e[0m\e[1;34mols \e[0m \e[1;34m ┊┊┊ 📁\e[0m Tools for Editing"
echo -e " 📝 \e[1;35m \e[4me\e[0m\e[1;35mxport \e[0m \e[1;34m ┊┊┊ 📁\e[0m Export Notes to Different Formats "
echo -e " ⎋ \e[1;36m \e[4mc\e[0m\e[1;36monvert \e[0m \e[1;34m ┊┊┊ 📁\e[0m Convert Clipboard Contents to Different Formats "
@ -153,6 +156,8 @@ arguments () {
;;
search|s) shift; NoteSearch "${NOTES_DIR}" ${@:-}
;;
rofi|r) shift; RofiMenu ${@:-}
;;
tags|t) shift; CadmusTags ${@:-}
;;
tools|to) shift; CadmusTools "${@:-}"
@ -195,7 +200,7 @@ function NoteFind() {
## the keybindings to emacsclient.
# Using XDG-OPEN
# echo "${FILES}" | sed s/^/xdg-open\ \"/ | sed s/$/\"/ | bash
echo "${FILES}" | sed -e s+^+\"+ -e s+$+\"+ | xargs -n 1 xdg-open
echo "${FILES}" | sed -e s+^+\"+ -e s+$+\"+ | xargs -n 1 "${EDITOR}"
# # Getting the .desktop file and cutting off the Extension
# dex "$(xdg-mime query default text/markdown)" $FILES
@ -216,7 +221,61 @@ function NoteSearch() {
## Only try and open something that is non-empty
if [ "$FILES" != "" ]; then
echo "${FILES}" | sed -e s+^+\"+ -e s+$+\"+ | xargs -n 1 xdg-open
echo "${FILES}" | sed -e s+^+\"+ -e s+$+\"+ | xargs -n 1 "${EDITOR}"
fi
}
# *** RofiMenu
function RofiMenu() {
[[ -z "${1:-}" ]] && RofiHelp && exit 0
while test $# -gt 0
do
case "$1" in
search) shift; "${script_dir}"/rofi_search.sh "${NOTES_DIR}" && exit 0
;;
find) shift; "${script_dir}"/rofi_find.sh "${NOTES_DIR}" && exit 0
;;
--*) >&2 echo "bad option $1"
;;
*) >&2 echo -e "argument \e[1;35m${1}\e[0m has no definition."
;;
esac
shift
done
}
# **** Rofi Help
function RofiHelp() {
echo
echo -e " \e[3m\e[1m Cadmus Rofi\e[0m; Use Rofi and Browser to Search/Find and Preview"
echo -e " \e[1;31m -------------------------\e[0m "
echo
echo -e " \e[3m\e[1m• Notes\e[0m "
echo
echo
echo -e " \e[1;91m \e[1m Command \e[0m\e[0m \e[1;34m┊┊┊ \e[0m Description "
echo -e " ..............\e[1;34m┊┊┊\e[0m........................................... "
echo -e " \e[1;93m find \e[0m \e[1;34m ┊┊┊ 🎆 \e[0m Find Notes based on FileName"
echo -e " \e[1;32m search \e[0m \e[1;34m ┊┊┊ 🎆 \e[0m Create Tags with TMSU"
echo
}
# *** Note Search
function NoteSearch() {
COMMAND="${script_dir}/NoteRecollSearch.sh"
echo "Running "${COMMAND}" "${1}""
FILES="$("${COMMAND}" "${@:-}")"
## Only try and open something that is non-empty
if [ "$FILES" != "" ]; then
echo "${FILES}" | sed -e s+^+\"+ -e s+$+\"+ | xargs -n 1 "${EDITOR}"
fi
}
@ -298,15 +357,18 @@ CadmusTools () {
;;
webtitle) shift; "${script_dir}/tools/PrintWebTitle.sh" "$(CLIP_OUT)" | CLIP_IN
;;
backlinks) shift; "${script_dir}/tools/List-Backlinks.sh" "$(CLIP_OUT)" ${@:-} && exit 0
backlinks) shift; "${script_dir}/tools/List-Backlinks.sh" "$(CLIP_OUT)" "${NOTES_DIR}" ${@:-} && exit 0
;;
link) shift; "${script_dir}/tools/LinkMarkdownNotes.sh" "${NOTES_DIR}" "$(CLIP_OUT)" | CLIP_IN && exit 0
;;
fix) shift; "${script_dir}/tools/fixLink.sh" "${NOTES_DIR}" && exit 0
;;
unused-attachments) shift; node "${script_dir}/tools/print_unused_attachments.js" "${NOTES_DIR}" && exit 0
;;
page-import) shift; CLIP_OUT | xargs curl | pandoc -f html -t markdown_github+tex_math_dollars --atx-headers | CLIP_IN && exit 0
;;
random) shift; find "${NOTES_DIR}" -name '*.md' | shuf -n 1 | xargs xdg-open && exit 0
random) shift; find "${NOTES_DIR}" -name '*.md' | shuf -n 1 | xargs "${EDITOR}" && exit 0
;;
rename) shift; CadmusRename "${NOTES_DIR}" && exit 0
;;
@ -349,17 +411,18 @@ function ToolsHelp() {
echo -e " / ...................................(forward slash)"
echo -e " \\ ..................................(back slash)"
echo
echo -e " \e[1;91m \e[1m Command \e[0m\e[0m \e[1;34m┊┊┊ \e[0m Description "
echo -e " ..................\e[1;34m┊┊┊\e[0m........................................... "
echo -e " \e[1;93m new \e[0m \e[1;34m ┊┊┊ \e[0m Starts an interactive prompt to make a new note"
echo -e " \e[1;93m webtitle \e[0m \e[1;34m ┊┊┊ \e[0m✀ Transforms the Clipboard 📋 to a Link"
echo -e " \e[1;93m backlinks \e[0m \e[1;34m ┊┊┊ \e[0m✀ Takes the Abs Path of a Note from the Clipboard 📋"
echo -e " \e[1;93m \e[0m \e[1;34m ┊┊┊ \e[0m and prints out backlinks (Abs Path)"
echo -e " \e[1;93m fix \e[0m \e[1;34m ┊┊┊ 🎆 \e[0m Fix the relative path in the clipboard 📋 "
echo -e " \e[1;93m link \e[0m \e[1;34m ┊┊┊ 🎆 \e[0m Generate a link to another note from the current in the clipboard"
echo -e " \e[1;32m page-import \e[0m \e[1;34m ┊┊┊ 🎆 \e[0m Transform Clipboard from URL to corresponding Markdown"
echo -e " \e[1;32m random \e[0m \e[1;34m ┊┊┊ 🎆 \e[0m Open a Random Note in the Default program"
echo -e " \e[1;32m rename \e[0m \e[1;34m ┊┊┊ 🎆 \e[0m Choose a note to rename and adjust all links"
echo -e " \e[1;91m \e[1m Command \e[0m\e[0m \e[1;34m ┊┊┊ \e[0m Description "
echo -e " ..................\e[1;34m....┊┊┊\e[0m........................................... "
echo -e " \e[1;93m new \e[0m \e[1;34m ┊┊┊ \e[0m Starts an interactive prompt to make a new note"
echo -e " \e[1;93m webtitle \e[0m \e[1;34m ┊┊┊ \e[0m✀ Transforms the Clipboard 📋 to a Link"
echo -e " \e[1;93m backlinks \e[0m \e[1;34m ┊┊┊ \e[0m✀ Takes the Abs Path of a Note from the Clipboard 📋"
echo -e " \e[1;93m \e[0m \e[1;34m ┊┊┊ \e[0m and prints out backlinks (Abs Path)"
echo -e " \e[1;93m fix \e[0m \e[1;34m ┊┊┊ 🎆 \e[0m Fix the relative path in the clipboard 📋 "
echo -e " \e[1;93m unused-attachments \e[0m \e[1;34m ┊┊┊ 🎆 \e[0m Print unused attachments, not working yet "
echo -e " \e[1;93m link \e[0m \e[1;34m ┊┊┊ 🎆 \e[0m Generate a link to another note from the current in the clipboard"
echo -e " \e[1;32m page-import \e[0m \e[1;34m ┊┊┊ 🎆 \e[0m Transform Clipboard from URL to corresponding Markdown"
echo -e " \e[1;32m random \e[0m \e[1;34m ┊┊┊ 🎆 \e[0m Open a Random Note in the Default program"
echo -e " \e[1;32m rename \e[0m \e[1;34m ┊┊┊ 🎆 \e[0m Choose a note to rename and adjust all links"
echo
}
@ -422,7 +485,7 @@ makeNewNote () {
echo -e "---\n" >> "${FILE}"
echo -e "# "${NAME}"" >> "${FILE}"
bat "${FILE}"
mdcat "${FILE}"
echo -e "Succesfully Created:\n "${FILE}""
nvim + "${FILE}"
@ -492,7 +555,7 @@ CadmusExport () {
;;
html) shift; pandocExport html --mathml --self-contained -c "${script_dir}"'/resources/pandoc.css' && exit 0
;;
html-dir) shift; pandocExport html --katex -c "${script_dir}"'/resources/pandoc.css' && exit 0
html-dir) shift; pandocExport html --mathjax -c "${script_dir}"'/resources/pandoc.css' && exit 0
;;
page-import) shift; CLIP_OUT | xargs curl | pandoc -f html -t markdown_github+tex_math_dollars --atx-headers | CLIP_IN && exit 0
;;
@ -527,12 +590,21 @@ pandocExport () { # $1 is extension; $2+ are options for pandoc
echo -e " \e[1;94m Output to: \e[1;32m "${OUTDIR}"/"${FILEOUT}"\e[0m"
echo
echo -e " \e[1;94m Performing: \e[0m"
echo " pandoc -s "${FILE}" ${@:-} --extract-media="${OUTDIR}/media" -o "${OUTDIR}"/"${FILEOUT} | highlight --syntax bash -O ansi
echo " pandoc -s "${FILE}" --mathjax ${@:-} --extract-media="${OUTDIR}/Media" -o "${OUTDIR}"/"${FILEOUT} | highlight --syntax bash -O ansi
echo
pandoc -s "${FILE}" ${@:-} --extract-media="${OUTDIR}/media" -o "${OUTDIR}"/"${FILEOUT}" || exit 7
xdg-open "${OUTDIR}"/"${FILEOUT}"
## Media must have first letter capitalised for mediawiki
## HTML2Wiki wants zip file
pandoc -s "${FILE}" ${@:-} --extract-media="${OUTDIR}/Media" -o "${OUTDIR}"/"${FILEOUT}" || exit 7
cd "${OUTDIR}"
## Run it a second time so extracted media is relative not absolute
## It seems mathjax only works here, not katex :shrug:
pandoc -f -s --mathjax "${FILEOUT}" ${@:-} --extract-media="Media" -o "${FILEOUT}" || echo "" # This might fail for PDF's, don't exit
## Zip everything up as well
zip -r "$(echo ${FILE} | cut -f 1 -d '.')".zip *
"${EDITOR}" "${OUTDIR}"/"${FILEOUT}"
cd -
}
# **** Help
@ -546,8 +618,7 @@ function ExportHelp () {
echo -e " This does not work for multiple selections (yet) so avoid pressing"
echo -e " TAB to try and export multiple files, it won't work"
echo
echo -e " The links in exports are not relative, I don't know why,"
echo -e " I need to fix this because it's really really inconvenient."
echo -e " The links in exports are made relative, by using a second call to pandoc"
echo
echo -e " \e[1;91m \e[1m Command \e[0m\e[0m \e[1;34m┊┊┊ \e[0m Description "
echo -e " ...............\e[1;34m┊┊┊\e[0m........................................... "
@ -560,6 +631,7 @@ function ExportHelp () {
echo -e " \e[1;32m html \e[0m \e[1;34m ┊┊┊\e[0m Make a self-contained MathML HTML (firefox/safari only)"
echo -e " \e[1;32m html-dir \e[0m \e[1;34m ┊┊┊\e[0m Make a directory of HTML+images (for importing to Mediawiki)"
echo -e " \e[1;32m md \e[0m \e[1;34m ┊┊┊\e[0m Export markdown and images to directory"
echo -e " \e[1;32m org \e[0m \e[1;34m ┊┊┊\e[0m Export as org-mode with images to directory"
echo
}
@ -755,14 +827,13 @@ subHelp () {
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
"${script_dir}/NoteFind.sh"
echo
echo
echo -e "\e[1;35m -------------------------\e[0m "
echo -e " \e[1;94m\e[3m\e[1m Cadmus Search\e[0m"
echo -e "\e[1;35m -------------------------\e[0m "
NoteRecollSearch.sh -h
"${script_dir}/NoteRecollSearch.sh"
echo
echo

205
bin/rofi_find.sh Executable file
View File

@ -0,0 +1,205 @@
#! /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 "${@}"
rofi_over_Notes "${@}"
}
# ** 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=(
"rofi"
"rg"
)
# *** 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
}
# *** Read First Argument
readFirstArgument () {
if [[ "${1:-}" == "-h" ]] || [[ "${1:-}" == "--help" ]] || [[ "${1:-}" == "" ]]; then
Help && exit 0
fi
}
# *** Skim and Grep, the important stuff
#
rofi_over_Notes () {
## Change directory if One was specified, exit if no directory exists
cd "${1}"
FILE="$(RofiFind)"
if [[ $FILE != "" ]]; then
realpath $FILE && exit 0
fi
exit 0
}
# **** Skim with Grep
RofiFind () {
## Change directory if One was specified, exit if no directory exists
# I took this bit from https://github.com/davatorium/rofi/issues/997
# Not totally sure how it works but it does :shrug
## Set Variables
local selected
local string
selected="${1:-}"
TEMP_DIR="/tmp/cadmus_rofi_preview"
mkdir -p "${TEMP_DIR}"
# schemes="$(fd '\.org$')" # TODO Only look at org-mode files (hmmmm)
schemes="$(find ./ -name '*\.org' -or -name '*\.md')"
lines=$(printf '%s\n' "${schemes}" | wc -l)
menu=$(printf '%s\n' "${schemes}" | rofi -matching fuzzy -location 1 -kb-row-up "" -kb-row-down "" -kb-custom-1 "Up" -kb-custom-2 "Down" -format 'd:s' -dmenu -selected-row $selected)
exit_code=$?
selected="${menu%:*}"
string="${menu##*:}"
case "${exit_code}" in
"1") exit 0;;
"0") PRINT_OUT "${string}" & disown;;
"10")
if [[ $selected == "1" ]]; then
foo_selected="${lines}"
call="3"
else
foo_selected="$(echo -e $(( ${selected} - 1 )))";
call=$(echo $(( ${selected} - 2 )))
fi
foo="$(printf '%s' "${schemes}" | sed -n "${foo_selected}"p)";
PRINT_OUT "${foo}" & disown;;
"11")
if [[ "${selected}" -ge "${lines}" ]]; then
foo_selected="1"
call="0"
else
foo_selected="$(echo -e $(( ${selected} + 1 )))";
call="${selected}"
fi
foo="$(printf '%s' "${schemes}" | sed -n "${foo_selected}"p)";
PRINT_OUT "${foo}" & disown
esac
RofiFind "${call}"
exit 0
}
# **** Convert the File with Pandoc and Show in Browser
PRINT_OUT () {
FILEPATH="$(realpath ${1})"
FILEPATH_NO_EXT="$(realpath ${1} | cut -f 1 -d '.')"
DIRECTORY="$(dirname ${FILEPATH}})"
NAME="$(basename ${@} | cut -f 1 -d '.')"
BROWSER="chromium"
# Simpler calls
# pandoc -f org -t html "${FILEPATH}" --quiet | cat
function pandoc_browser() {
#pandoc -f org -t html "${FILEPATH}" -A /home/ryan/Templates/CSS/gitOrgWrapped.css --mathjax -s --quiet -o "/dev/shm/${NAME}.html" && \
pandoc -t html "${FILEPATH}" --extract-media="${TEMP_DIR}/media_${NAME}" -A /home/ryan/Templates/CSS/gitOrgWrapped.css --katex -s --quiet -o "${TEMP_DIR}/${NAME}.html" && \
"${BROWSER}" "${TEMP_DIR}/${NAME}.html" > /dev/null & disown # Chromium is faster than firefox
}
## By caching the export in /dev/shm/ chrome will just go back to the last tab (quicker)
## and pandoc won't reconvert unnecessarily (quicker)
## Given that most of the time is spent looking and reading this makes a lot of sense
if [ "${FILEPATH}" -nt "${TEMP_DIR}/${NAME}.html" ]; then
# The Live_Reload_JS lets me reload this, otherwise do not disown this process
pandoc_browser & disown
else
"${BROWSER}" "${TEMP_DIR}/${NAME}.html" & disown
fi
# I tried this with org-ruby, no luck though for latex though
# Org-ruby is much faster than pandoc
# /home/ryan/.gem/ruby/2.7.0/bin/org-ruby "${FILEPATH}" -t html > /dev/shm/mpv.html
# cat /home/ryan/Templates/mathjax >> /dev/shm/mpv.html
# cat /home/ryan/Templates/CSS/gitOrgWrapped.css >> /dev/shm/mpv.html
# chromium /dev/shm/mpv.html & disown
}
# * Call Main Function
main "${@}"

73
bin/tags/org_tags.py Normal file
View File

@ -0,0 +1,73 @@
#!/usr/bin/env python3
## This doesn't work yet, the problem is at line 21, it identifies a lot of crap
## as tags if there are ~:~ characters in the heading.
import os
import re
import glob
import sys
import subprocess
# Set Working Directory
try:
os.chdir(sys.argv[1])
# os.chdir((os.getenv('HOME')))
# os.chdir('Notes/Org/')
except:
print("Exiting; Unable to Access Directory " + str(sys.argv[1]))
ripgrep_command = ['rg', '--vimgrep', '-t', 'org', r"^\*+\s.*\s+:.+:"]
grep_results = subprocess.run(ripgrep_command, stdout=subprocess.PIPE).stdout.decode('utf-8')
# TODO Identifies any `:` in a heading as tag seperator, I can't extract
# org-mode tags until I fix this
grep_results = str(grep_results).split('\n')
# Match org-mode files
def printOrgFiles(dir):
os.chdir(dir)
files = os.listdir()
orgFiles = []
for file in files:
pattern = re.compile('.+\.org$')
if re.match(pattern, file) and not re.match(pattern, file):
orgFiles.append(file)
# Search for Tags in org-files
lines = {
'filename': [],
'lineNumber': [],
'title': [],
'tags': []
}
for line in grep_results:
line_list = str(line).split(':')
try:
lines['filename'].append(line_list[0])
lines['lineNumber'].append(line_list[1])
lines['title'].append(line_list[3]) # 2 is column number, we just want first
lines['tags'].append(list(line_list[4:-1])) # make sure that a single tag is still a list for consistency
except:
pass
# print('missing value, skip line')
# print('---')
# print(lines)
# Print the filename, tag and line number
for i in range(len(lines['lineNumber'])):
try:
filename = lines['filename'][i]
lineNumber = lines['lineNumber'][i]
tags = lines['tags'][i]
# print(filename + ',' + lineNumber + ',' + str(tags))
print("tmsu tag '" + filename + "' " + str(tags).replace('[', '').replace(']',''))
except:
pass
# Do nothing in exception for clean STDOUT

View File

@ -1,17 +1,20 @@
#!/usr/bin/env bash
command -v rg >/dev/null 2>&1 || { echo >&2 "I require ripgrep but it's not installed. Aborting."; exit 1; }
command -v sd >/dev/null 2>&1 || { echo >&2 "I require sd (sed replacement) but it's not installed. Aborting."; exit 1; }
command -v xclip >/dev/null 2>&1 || { echo >&2 "I require xclip but it's not installed. Aborting."; exit 1; }
term=$(basename "${1}" | cut -f 1 -d '.')
DIR="${2}"
rg -e "\[.*\]\(.*$term\.md\)" -e "\[\[$term\]\]" -e "\[\[$term.*\]\]" \
~/Notes/MD/notes \
"${DIR}" \
-t markdown -ol
# ~/Notes/MD/notes \
## If you want to preview the Backlinks
## rg -e "\[.*\]\(.*$term\.md\)" -e "\[\[$term\]\]" -e "\[\[$term.*\]\]" \

View File

@ -91,9 +91,8 @@ ${BLUE} $arglink
${NC} It's description is\n"
title=$(wget -qO- $arglink |
perl -l -0777 -ne 'print $1 if /<title.*?>\s*(.*?)\s*<\/title/si' |
recode html..)
title=$(wget -qO- $arglink |\
rg -m 1 -o --pcre2 '(?<=<title>)(.*)(?=</title>)' )
>&2 echo $title

View File

@ -0,0 +1,108 @@
// test this with node print_unused_attachments.js | xargs rg
// It doesn't seem to work.
// //////////////////////////////////////////////////////////
// ////////// Load Libraries ////////////////////////////////
// //////////////////////////////////////////////////////////
const path = require('path');
const fs = require('fs');
// const yamlFront = require('yaml-front-matter');
let debugFlag = false;
let glob = require('glob');
function main() {
change_directory();
attachments = get_file_names()[0];
notes = get_file_names()[1];
unused_attachments = find_unused_attachments(attachments, notes);
print(unused_attachments)
}
function change_directory() {
////////////////////////////////////////////////////////////
/////////// Change Directory ///////////////////////////////
////////////////////////////////////////////////////////////
if (process.argv[2] == undefined) {
const path = "./";
if (debugFlag) {
console.log(`No Path Detected, using this directory ${process.argv[1]}`)
console.log("Remember to use $HOME not ~")
}
} else if (process.argv[2] == "-h" | process.argv[2] == "--help") {
console.log("\nProvide the Directory of MD Notes as the First Argument")
console.log("Otherwise the current directory, ./, will be used.\n")
console.log("No notes will not lead to any warning")
console.log("This is necessary so as to not be dangerous when | bash\n")
} else {
const path = process.argv[2];
process.chdir(path);
if (debugFlag) {
console.log(`Using Specified Directory ${process.argv[2]}`)
}
}
}
function get_file_names() {
// //////////////////////////////////////////////////////////
// ////////////// Get File Names/////////////////////////////
// //////////////////////////////////////////////////////////
let att_extensions = [
"./**/*.png",
"./**/*.jpeg",
"./**/*.jpg",
"./**/*.svg"
]
let note_extensions = [
"./**/*.md",
"./**/*.org",
"./**/*.txt",
"./**/*.html",
"./**/*.tex"
]
var attFilePathList = [];
var noteFilePathList = [];
for (i=0; i < note_extensions.length; i++) {
noteFilePathList.push(glob.sync(note_extensions[i]));
}
for (i=0; i < att_extensions.length; i++) {
attFilePathList.push(glob.sync(att_extensions[i]));
}
noteFilePathList = noteFilePathList.flat();
attFilePathList = attFilePathList.flat();
return [attFilePathList, noteFilePathList];
}
function find_unused_attachments(attachments, notes) {
for (i=0; i < attachments.length;i++) {
att = attachments[i];
for (j = 0; j < notes.length; j++) {
note = fs.readFileSync(notes[j], "utf-8");
att_referencedQ = note.includes(basename(att))
// TODO this probably doesn't work because I need to loop over each line
if (!att_referencedQ) {
print(basename(att))
break
}
}
}
return 0;
}
function basename(string) {
return string.split('\\').pop().split('/').pop(); // https://stackoverflow.com/a/25221100
}
function print(val) {
console.log(val);
}
main()

View File

@ -1,6 +1,7 @@
#!/usr/bin/env bash
INSTALL_DIR="$HOME/.cadmus"
BIN_DIR="$HOME/.local/bin/"
mkdir "${BIN_DIR}" > /dev/null
main () {
me=`basename "$0"`

View File

@ -41,6 +41,21 @@ should I restructure the subfunctions to accept only 1 argument either help or d
+ Less Extensible
* WAIT Switch back to MDCat
When [[https://github.com/lunaryorn/mdcat/issues/155][this issue]] is resolved switch back to MDCat
* TODO Add Dokuwiki Export
just like ~html-dir~ add ~dw-dir~ using this script:
- =~/bin/ImportHtml2Dokuwiki.sh=
* TODO Fix Media Wiki Export
The links in the html-dir export are absolute, a second pass is needed to make them relative, this will be necessary for everything except for self-contained stuff.
Make a seperate function for self contained and relative stuff.
Currently html-dir CANNOT be used to import into mediawiki because even thtough the files get pulled in the links are broken.
calling ~pandoc ./file.html --extract-media='./media' -o ./file.html~ is necessary to import a zip file into mediawiki.
* HOLD [#A] NoteFind.sh
** KeyBindings