1
0
mirror of https://github.com/RyanGreenup/cadmus.git synced 2025-02-19 20:27:49 +01:00

[TOOLS] Copied in relevant tools

This commit is contained in:
Ryan Greenup 2020-07-16 09:03:23 +10:00
parent 99fd7d6499
commit cf221791ad
3 changed files with 146 additions and 0 deletions

73
bin/tools/LinkMarkdownNotes.sh Executable file
View File

@ -0,0 +1,73 @@
#!/usr/bin/env bash
if [ "$1" == "-h" ] || [ "$1" == "--help" ]; then
echo "
The input file is taken from the clipboard,
choose the output file and a relative MD link
will be generated"
exit 0
elif [[ $1 != '' ]]; then
NOTES_DIR=$1
else
NOTE_DIR='./'
fi
main() {
command -v xclip >/dev/null 2>&1 || { echo >&2 "I require but it's not installed. It'll be in the repos, so, ~pacman -Syu xclip, aborting ."; exit 1; }
OUTPUTFILE=$(getNote_onlyShowFileName)
INPUTFILE=$(xclip -o -selection clipboard)
REL_PATH=$(realpath --relative-to $(dirname $INPUTFILE) $OUTPUTFILE)
## echo $REL_PATH | xclip -selection clipboard
##
echo $(MarkdownLink)
## TODO The Relative Path is in-FUCKING-correct
}
MarkdownLink() {
name=$(basename $REL_PATH | cut -f 1 -d '.')
echo "[$name](./$REL_PATH)"
}
getNote() {
fd \.md | sk \
--preview "mdcat {}" \
--bind pgup:preview-page-up,pgdn:preview-page-down
}
## This version only displays the file name, which is better for small
## displays
##
## (although you loose context with regard to the directories which I
## treat as notebooks)
##
## This relies on the fact that each note has a unique name
## If you've symlinked notes into two places you're a bad person
## and it's your own fault that this has got you into hot water.
##
getNote_onlyShowFileName() {
# command -v sk >/dev/null 2>&1 || { echo >&2 "I require skim but it's not installed. install it from https://github.com/lotabout/skim, aborting ."; exit 1; }
command -v fzf >/dev/null 2>&1 || { echo >&2 "I require but it's not installed. install it from https://github.com/junegunn/fzf, aborting ."; exit 1; }
command -v fd >/dev/null 2>&1 || { echo >&2 "I require but it's not installed. install it with ~cargo install fd~, aborting ."; exit 1; }
fd \.md | sd '^' 'basename "' | sd '$' '"' | bash | \
fzf --preview "fd {} | xargs mdcat" \
--bind pgup:preview-page-up,pgdn:preview-page-down | \
xargs fd | xargs realpath
}
main

69
bin/tools/fixLink.sh Executable file
View File

@ -0,0 +1,69 @@
#!/bin/bash
# Don't forget to adjust the permissions with:
#chmod +x ~/somecrazyfolder/script1
## Program
### Description
# This will use fzf to find filenames that might correspond to a path from a broken link in the clipboard.
# so let's say that ~[](~/broken/path/to/rsico.png)~ is a broken link, I can use ~yi(~ to copy that to the clipboard in vim and run the following bash scipt to return the correct link:
# Requires:
# * gnu coreutils (specifically realpath)
# * fzf
# * xclip
## WARNING, IF YOU USED `SPC F Y` FROM EMACS THIS WILL NOT WORK!!!
## I DON'T KNOW WHY, I THINK IT'S BECAUSE OF Newline Characters at the end maybe?
### Code
#' You have to strip out the `~` characters, they are incompatible with `realpath`
#' fzf returns /home/username/path/to/file so it doesn't matter
brokenPath=$(xclip -o -selection clipboard)
#find ~/Dropbox/ -name $(echo $(basename $brokenPath)) | fzf | xclip -selection clipboard
## NewFile=$(find ~/Dropbox/ -name $(echo $(basename $brokenPath)) | fzf)
NewFile=$(find ~/Notes/ -name $(echo $(basename $brokenPath)) | fzf)
echo $NewFile | xclip -selection clipboard
echo "
Put the path of the source file in the clipboard and Press any Key to Continue
(This doesn't work with a path taken from Emacs:buffer-file-name
I'd recommend using VSCode for this script)
"
# this will just continue after a key stroke
read -d'' -s -n1
echo "
Using:
"
sourceFile=$(xclip -o -selection clipboard)
echo "
SOURCE_FILE.......$sourceFile
NEW_ATTACHMENT....$NewFile
"
sourcePath=$(dirname $sourceFile)
relativePath=$(realpath --relative-to="$sourcePath" $NewFile)
relPathWithDot="./"$relativePath
echo $relPathWithDot | xclip -selection clipboard
echo "
Success! Relative path is in clipboard
"
exit 0
## vim:fdm=expr:fdl=0
## vim:fde=getline(v\:lnum)=~'^##'?'>'.(matchend(getline(v\:lnum),'##*')-2)\:'='

View File

@ -80,6 +80,10 @@ rg --pcre2 '(?<=[---\n[\s\S]ags:).*[,\s|:\s][a-z]+' -t markdown -o | sd -s ':' '
Should this do grep or recoll?
Probably grep just in case recoll ever brakes.
** TODO [#B] Link should really use NoteFind or NoteSearch
As opposed to using its own implementation.
** TODO [#C] If fixLink used skim not fzf I could remove a dependency
* TODO [#A] export
* TODO [#A] convert
* TODO [#A] misc