new things

This commit is contained in:
ackman678
2021-03-30 00:37:43 -07:00
parent 14f1c48838
commit 6e92164bc3
8 changed files with 235 additions and 16 deletions

30
bibview Executable file
View File

@@ -0,0 +1,30 @@
#!/bin/bash
if [ "$1" == "-h" ] ; then
echo "
bibview - search for citekey in a bibjson.json and preview pdf
usage:
bibview
depends:
fzf
zathura (or other fast pdf viewer)
defaults:
Set the required default file locations (csl file, bib file)
"
exit 0
fi
#Setup defaults
bibdFile=${2:-$HOME/projects/bibd/OMEGA.json}
#pandoc-citeproc --bib2json ~/projects/bibd/OMEGA.bib > OMEGA.json
cd $(dirname $bibdFile)
set -e #exit if an error
# export citeKey=$1
# doiStr=$(jq -r '.[] | select(.id==env.citeKey).DOI' $bibdFile)
# urlStr=$(jq -r '.[] | select(.id==env.citeKey).URL' $bibdFile)
#actually this is the good one, opens pdfs quickly
jq -r '.[] | [.id, .title, .abstract, .keyword, .DOI, .PMID, .author[]?.family, .issued[]?[0]?[0], .["container-title"], .URL] | join(" ")' $bibdFile | fzf --preview 'echo {}' --preview-window=:up:70%:wrap --bind "enter:execute-silent(zathura {-1} &)"

33
cp2figs.sh Executable file
View File

@@ -0,0 +1,33 @@
#!/bin/bash
#!/bin/bash
if [ "$1" == "-h" ] ; then
echo "
cp2figs.sh - copy and convert image to figure assets folder and put html figure string containing relative link to the asset on system clipboard
- converts to a smaller asset size for html presentation
- default figure assets set as HOME/figures
Usage: cp2figs.sh img.jpg
cp2figs.sh img.jpg ~/myproject/assets
"
exit 0
fi
set -e
# fn=$(basename $1)
fn=$1
#default image location
# blobFolder=$HOME/figures
blobFolder=${2:-$HOME/figures}
#TODO: add xorg-x11 vs wayland logic here
# wayland: use "wl-copy"
#xorg-x11: use "xclip -selection clipboard"
origHash=$(md5sum $fn | cut -d ' ' -f 1 | cut -c -7)
newName=$blobFolder/$(basename -s .jpg $fn)_$origHash.jpg
cp $fn $newName
convert -resize 1280x1280 -quality 90 $newName $newName
echo "<figure><img src=\""$(basename $blobFolder)/$(basename $newName)"\" width=\"500px\"><figcaption></figcaption></figure>" | wl-copy

43
f Executable file
View File

@@ -0,0 +1,43 @@
#!/bin/bash
if [ "$1" == "-h" ] ; then
echo "
f - fuzzy preview and open text files or pdfs
usage:
f
f p
depends:
fzf
grep, git-grep, or ripgrep
zathura (or other fast pdf viewer)
pdf2bib.sh - handles saving to your bib db
"
exit 0
fi
#Setup defaults
# cslFile=${2:-$HOME/projects/bibd/bibd-md.csl}
# bibdFile=${3:-$HOME/projects/bibd/OMEGA.bib}
# cd $(dirname $bibdFile)
set -e #exit if an error
inFlag=${1:-"-i --files"}
if [ "$1" == "p" ]; then
ls *.pdf | fzf --preview 'pdftotext -l 2 -nopgbrk -q {1} -' \
--preview-window=up:70% --bind "enter:execute-silent(zathura {} &)" \
--bind "ctrl-s:execute(pdf2bib.sh {})+reload(ls *.pdf)"
exit 1
fi
if [ -z "$1" ]; then
#FZF_DEFAULT_COMMAND=rg -i --files --glob "!.git/*"
fzf --delimiter : --preview 'less {1}' \
--preview-window=up:70% --bind "enter:execute-silent(gvim {1} &)"
else
rg $1 | fzf --delimiter : --preview 'less {1}' \
--preview-window=up:70% --bind "enter:execute-silent(gvim {1} &)"
fi

View File

@@ -31,13 +31,25 @@ echo "using $bibdFileOut"
#try to extract doi from pdf and retrieve a pubmed id #try to extract doi from pdf and retrieve a pubmed id
#for 'DOI:' syntax #for 'DOI:' syntax
doi=$(pdftotext -q -f 1 -l 1 $fn - | grep -i doi: --max-count=1 | tr [:upper:] [:lower:] | sed -E "s#doi:(.+)#\1#") # doi=$(pdftotext -q -f 1 -l 1 $fn - | grep -i "doi:" --max-count=1 | tr [:upper:] [:lower:] | sed -E "s#doi:(.+)#\1#")
doi=$(pdftotext -q -f 1 -l 1 $fn - | grep -iE "doi:? ?/?10\." --max-count=1 | tr [:upper:] [:lower:] | sed -E "s#.*doi:? ?/?(10.+)#\1#")
#for 'https://doi.org' syntax #for 'https://doi.org' syntax
if [ -z "$doi" ]; then if [ -z "$doi" ]; then
doi=$(pdftotext -q -f 1 -l 1 $fn - | grep -i "doi.org/" --max-count=1 | tr [:upper:] [:lower:] | sed -E "s#.+doi\.org\/(.+)#\1#") doi=$(pdftotext -q -f 1 -l 1 $fn - | grep -iE "doi\.org/10\." --max-count=1 | tr [:upper:] [:lower:] | sed -E "s#.+doi\.org/(10.+)#\1#")
fi fi
# for 'https://doi.org' syntax
# if [ -z "$doi" ]; then
# doi=$(pdftotext -q -f 1 -l 1 $fn - | grep -i "doi.org/" --max-count=1 | tr [:upper:] [:lower:] | sed -E "s#.+doi\.org\/(.+)#\1#")
# fi
#
# if [ -z "$doi" ]; then
# doi=$(pdftotext -q -f 1 -l 1 $fn - | grep -iE "doi ?" --max-count=1 | tr [:upper:] [:lower:] | sed -E "s#doi ?(.+)#\1#")
# fi
if [ -z "$doi" ]; then if [ -z "$doi" ]; then
echo "doi not found" echo "doi not found"
exit 1 exit 1

31
pdfsplit Executable file
View File

@@ -0,0 +1,31 @@
#!/bin/bash
if [ "$1" == "-h" ] ; then
echo "
pdfsplit - extract a range of pdf pages with ghostscript
usage:
pdfsplit firstPage lastPage inputFile.pdf
output file will be named inputfile_pXX-pYY.pdf
depends:
gs - ghostscript
"
exit 0
fi
# the following is from a stackoverflow answer
# function pdfsplit()
# {
# this function uses 3 arguments:
# $1 is the first page of the range to extract
# $2 is the last page of the range to extract
# $3 is the input file
gs -sDEVICE=pdfwrite -dNOPAUSE -dBATCH -dSAFER \
-dFirstPage=${1} \
-dLastPage=${2} \
-sOutputFile=${3%.pdf}_p${1}-p${2}.pdf \
${3}
# }

View File

@@ -5,7 +5,7 @@ if [ "$1" == "-h" ] ; then
Useful for serving markdown text files locally with reveal.js Useful for serving markdown text files locally with reveal.js
Usage: reveal.sh neuroanatomy1.md Usage: reveal.sh neuroanatomy1.md
reveal.sh neuroanatomy1.md 8001
" "
echo "$(tput setaf 6)$EDITOR $(tput setaf 7)is currently set as editor" echo "$(tput setaf 6)$EDITOR $(tput setaf 7)is currently set as editor"
exit 0 exit 0
@@ -13,8 +13,9 @@ fi
set -e set -e
# appPath="$HOME/projects/dev/reveal.js"
appPath="$HOME/projects/dev/reveal.js" appPath="$HOME/projects/archive/external/reveal.js"
portNumber=${2:-8000}
if [[ ! -d $appPath ]]; then if [[ ! -d $appPath ]]; then
echo "reveal.js not found" echo "reveal.js not found"
@@ -30,5 +31,5 @@ fi
#add markdown filename to reveal placeholder start file #add markdown filename to reveal placeholder start file
sed -i -E "s|(<section data-markdown=\")[A-Za-z0-9\.-]*(\" )|\1$fn\2|" index.html sed -i -E "s|(<section data-markdown=\")[A-Za-z0-9\.-]*(\" )|\1$fn\2|" index.html
npm start npm start -- --port=$portNumber
# npm start

68
sbib Executable file
View File

@@ -0,0 +1,68 @@
#!/bin/bash
if [ "$1" == "-h" ] ; then
echo "
sbib - search for citekey in a bibtex.bib (or maybe eventually bibjson.json) file and return a bibliography entry in markdown or possibly other format
usage:
sbib
# use 'a' flag to search all
sbib a
# pass a custom citation style and database
sbib a citeprocStyle.csl bibdFile.json
depends:
fzf
git grep
pandoc
pandoc-citeproc
wl-copy
defaults:
Set the required default file locations (csl file, bib file)
"
exit 0
fi
#Setup defaults
cslFile=${2:-$HOME/projects/bibd/bibd-md.csl}
bibdFile=${3:-$HOME/projects/bibd/OMEGA.bib}
cd $(dirname $bibdFile)
set -e #exit if an error
#set pattern to the null character '\0' for search all, else search only cite keys
if [ "$1" == "a" ]; then
sPattern='\0'
else
sPattern="@[a-zA-Z_-]+\{"
fi
# Use fzf to search citation
# Initial scroll offset is set to the line number of each line
# of git grep output *minus* 5 lines (-5)
# str=$(cat $fn | fzf)
# str=$(git grep -E --line-number $sPattern $bibdFile | fzf --delimiter : --preview 'nl {1} --body-numbering=a' --preview-window=:up:70%:+{2}-5)
str=$(git grep -E --line-number $sPattern $bibdFile | fzf --delimiter : --preview 'less {1}' --preview-window=:up:70%:+{2}-5)
# extract citation key from the fzf string
citeKey=$(echo $str | sed -E "s|$(basename $bibdFile):[0-9]+:@[a-zA-Z]+\{(.+),|\1|")
#method1
#todo: use json with jq
# outCitation=$(pandoc -f latex <(echo "\cite{$citeKey}") -t plain -o - --bibliography $bibdFile --citeproc --csl $cslFile | tail -n +3)
#method2
#need to use a temporary bib file as input to pandoc because parsing a large bib file is too slow, but json input would be faster
#and because pandoc expects a file input for bibliography
tmpName=$(mktemp --suffix=.bib)
str3=$(grep -A 30 $citeKey $bibdFile)
echo $str3 | sed -E "s|(.+\} ?\}).+|\1|" > $tmpName
outCitation=$(pandoc -f latex <(echo "\cite{$citeKey}") -t plain -o - --bibliography $tmpName --citeproc --csl $cslFile | tail -n +3)
rm $tmpName
#tail -n +61 $fn | sed -E "s#(.+\}\})#\1#"
# fzf --preview="head {}" --preview-window=up:30%
# fzf --preview="file {}" --preview-window=down:1
echo $outCitation
echo $outCitation | wl-copy

19
woola
View File

@@ -8,7 +8,7 @@ if [ "$1" == "-h" ] ; then
By default this app will serve files from the current directory by default using woola. By default this app will serve files from the current directory by default using woola.
Takes an optional flags listed below. For example '--build' to build website files instead of serving. Takes an optional flag of those listed below. For example '--build' to build website files instead of serving.
Optional arguments passed to woola/lib/index.js: Optional arguments passed to woola/lib/index.js:
.option('-b, --build', 'Build and write html to path {site.options.dstPath}') .option('-b, --build', 'Build and write html to path {site.options.dstPath}')
@@ -24,7 +24,7 @@ if [ "$1" == "-h" ] ; then
.option('-x, --x', 'Don\'t open browser on run.') .option('-x, --x', 'Don\'t open browser on run.')
.option('-v, --verbose', 'verbose output') .option('-v, --verbose', 'verbose output')
Installation: place in home directory and make this file executable chmod: u=rwX,go= woola Installation: place in home bin directory and make this file executable chmod: u=rwX,go= woola
" "
exit 0 exit 0
fi fi
@@ -34,8 +34,7 @@ set -e
#helper startup script for woola #helper startup script for woola
appPath="$HOME/projects/dev/woola" appPath="$HOME/projects/dev/woola"
configFile=$HOME/.config/woola/config.js configFile=$HOME/.config/woola/config.js
# optFlag=${1:-serve} optFlag=$@
optFlag=$1
if [[ -e $configFile ]] && [[ ! -e config.js ]]; then if [[ -e $configFile ]] && [[ ! -e config.js ]]; then
ln -s $configFile config.js ln -s $configFile config.js
@@ -58,9 +57,11 @@ fi
# node $appPath/lib/index.js # node $appPath/lib/index.js
# fi # fi
if [[ "$optFlag" ]]; then # if [[ "$optFlag" ]]; then
node $appPath/lib/index $optFlag # node $appPath/lib/index $optFlag
else # else
node $appPath/lib/index.js # node $appPath/lib/index.js
fi # fi
node $appPath/lib/index $optFlag