sbib improve and rg bool
This commit is contained in:
47
sbib
47
sbib
@@ -12,13 +12,20 @@ if [ "$1" == "-h" ] ; then
|
||||
# pass a custom citation style and database
|
||||
sbib a citeprocStyle.csl bibdFile.json
|
||||
|
||||
Then press <enter> to open pdf
|
||||
and press <ctrl-c> to copy citation to clipboard
|
||||
|
||||
note:
|
||||
# to convert a bib to json, run
|
||||
# pandoc bibdFile.bib -t csljson -o bibdFile.json
|
||||
|
||||
|
||||
depends:
|
||||
fzf
|
||||
git grep
|
||||
sed tail
|
||||
bat or less
|
||||
pandoc
|
||||
pandoc-citeproc
|
||||
fetch_citation, pandoc, pandoc-citeproc
|
||||
zathura (or other fast pdf viewer)
|
||||
echo
|
||||
wl-copy
|
||||
@@ -32,9 +39,9 @@ if [ "$1" == "-h" ] ; then
|
||||
fi
|
||||
|
||||
#Setup defaults
|
||||
cslFile=${2:-$HOME/projects/bibd/bibd-md.csl}
|
||||
bibdFile=${3:-$HOME/projects/bibd/OMEGA.bib}
|
||||
# bibdFile=${2:-$HOME/projects/bibd/OMEGA.json}
|
||||
cslFile=${2:-$HOME/projects/learn/bibd/bibd-md.csl}
|
||||
bibdFile=${3:-$HOME/projects/learn/bibd/OMEGA.bib}
|
||||
# bibdFile=${2:-$HOME/projects/learn/bibd/OMEGA.json}
|
||||
cd $(dirname $bibdFile)
|
||||
set -e #exit if an error
|
||||
|
||||
@@ -49,28 +56,9 @@ view_bib() {
|
||||
# str=$(git grep -E --line-number $sPattern $bibdFile | fzf --delimiter : --preview 'less {1}' --preview-window=:up:70%:+{2}-5)
|
||||
str=$(git grep -E --line-number $sPattern $bibdFile | fzf --delimiter : --preview 'bat --color=always --style=numbers --line-range=:500 {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
|
||||
fetch_citation citeKey
|
||||
}
|
||||
|
||||
|
||||
@@ -80,9 +68,12 @@ view_json() {
|
||||
# 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} &)"
|
||||
}
|
||||
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} &)" \
|
||||
--bind "ctrl-c:execute-silent(fetch_citation {1})"
|
||||
|
||||
# --bind "ctrl-c:execute(notify-send {1})"
|
||||
}
|
||||
|
||||
|
||||
#set pattern to the null character '\0' for search all, else search only cite keys
|
||||
@@ -93,7 +84,7 @@ else
|
||||
fi
|
||||
|
||||
if [ "$1" == "j" ]; then
|
||||
bibdFile=${3:-$HOME/projects/bibd/OMEGA.json}
|
||||
bibdFile=${3:-$HOME/projects/learn/bibd/OMEGA.json}
|
||||
view_json
|
||||
else
|
||||
view_bib
|
||||
|
||||
Reference in New Issue
Block a user