sbib improve and rg bool
This commit is contained in:
@@ -11,9 +11,15 @@ REM=`grep -i "charge_now" $BATTERY/uevent | awk -F= '{ print $2 }'`
|
||||
FULL=`grep -i "charge_full_design" $BATTERY/uevent | awk -F= '{ print $2 }'`
|
||||
PERCENT=`echo $(( $REM * 100 / $FULL ))`
|
||||
|
||||
if [ $PERCENT -le "11" ]; then
|
||||
echo 'battery % is '$PERCENT
|
||||
|
||||
if [ $PERCENT -le "23" ]; then
|
||||
#/usr/bin/i3-nagbar -m "Low battery"
|
||||
#echo 'low battery '$PERCENT
|
||||
notify-send --urgency=critical "Low battery $PERCENT%"
|
||||
fi
|
||||
|
||||
if [ $PERCENT -le "7" ]; then
|
||||
echo "powering down..."
|
||||
systemctl suspend
|
||||
fi
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#!/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
|
||||
|
||||
29
dark
Executable file
29
dark
Executable file
@@ -0,0 +1,29 @@
|
||||
#!/bin/bash
|
||||
#dark: control display color contrast from terminal
|
||||
#usage: dark, dark 1, dark on, dark 0, dark off
|
||||
#James B. Ackman 2022-05-02T22:53:41-07:00
|
||||
|
||||
set -e #exit if an error
|
||||
mode=${1:-"dark"}
|
||||
|
||||
if [[ $1 == "0" || $1 == "off" ]]; then
|
||||
mode=light
|
||||
scheme=base16-atelier-dune-light.sh
|
||||
# scheme=base16-classic-light.sh
|
||||
# scheme=base16-gruvbox-light-hard.sh
|
||||
TaskTheme="light-256"
|
||||
else
|
||||
mode=dark
|
||||
# scheme=base16-atelier-dune.sh
|
||||
# scheme=base16-classic-dark.sh
|
||||
scheme=base16-gruvbox-dark-hard.sh
|
||||
TaskTheme="dark-gray-256"
|
||||
fi
|
||||
|
||||
#if exist base16 shell color scheme, switch to scheme
|
||||
ln -sf ~/.config/base16-shell/scripts/$scheme ~/.base16_theme
|
||||
sh ~/.base16_theme
|
||||
|
||||
#if exist taskwarrior taskrc file, switch the color scheme
|
||||
sed -i -E "s|include /usr/share/doc/task/rc/[a-z1256-]+.theme|include /usr/share/doc/task/rc/$TaskTheme.theme|" ~/.config/task/taskrc
|
||||
|
||||
2
dim
2
dim
@@ -7,7 +7,7 @@
|
||||
|
||||
#check kernel backlight driver names on your machine: `ls -l /sys/class/backlight/*`
|
||||
#then set following var, e.g. acpi_video0 nv_backlight or intel_backlight
|
||||
backlightDriver="intel_backlight"
|
||||
backlightDriver="acpi_video0"
|
||||
set -e #exit if an error
|
||||
percentValue=$1
|
||||
|
||||
|
||||
22
f
22
f
@@ -4,7 +4,8 @@ if [ "$1" == "-h" ] ; then
|
||||
f - fuzzy preview and open text files or pdfs
|
||||
usage:
|
||||
f
|
||||
f p
|
||||
f p #then type <enter> to preview
|
||||
f p #then type <ctrl-s> to save pdf with spdf.sh
|
||||
|
||||
depends:
|
||||
fzf
|
||||
@@ -18,6 +19,8 @@ fi
|
||||
|
||||
set -e #exit if an error
|
||||
|
||||
#todo: simplify.
|
||||
|
||||
if [ "$1" == "p" ]; then
|
||||
|
||||
ls *.pdf | fzf --preview 'pdftotext -l 2 -nopgbrk -q {1} -' \
|
||||
@@ -28,14 +31,21 @@ fi
|
||||
|
||||
if [ -z "$1" ]; then
|
||||
#FZF_DEFAULT_COMMAND=rg -i --files --glob "!.git/*"
|
||||
# fzf --delimiter : --preview 'less {1}' \
|
||||
fzf --delimiter : --preview 'bat --color=always --style=numbers --line-range=:500 {}' \
|
||||
--preview-window=up:70% --bind "enter:execute-silent(gvim {1} &)"
|
||||
fzf --delimiter : --preview 'bat --color always --style=numbers --line-range=:500 {1}' \
|
||||
--preview-window=up:70% --bind "enter:execute(xdg-open {1})"
|
||||
# --preview-window=up:70% --bind "enter:execute($VISUAL {1})"
|
||||
|
||||
# fzf --delimiter : --preview 'bat --color=always --style=numbers --line-range=:500 {}' \
|
||||
|
||||
# --preview-window=up:70% --bind "enter:execute-silent(gvim {1} &)"
|
||||
|
||||
else
|
||||
# rg $1 | fzf --delimiter : --preview 'less {1}' \
|
||||
# todo: replace this with a series elif blocks mapping selective previews and downstream application bindings to a set of desired filetypes
|
||||
ls *.$1 | fzf --delimiter : --preview 'bat --color=always --style=numbers --line-range=:500 {}' \
|
||||
--preview-window=up:70% --bind "enter:execute-silent(gvim {1} &)"
|
||||
#use xdg-mime, filetype info for opening
|
||||
ls *$1 | fzf --delimiter : --preview 'bat --color always --style=numbers --line-range=:500 {1}' \
|
||||
--preview-window=up:70% --bind "enter:execute(xdg-open {1})"
|
||||
|
||||
# --preview-window=up:70% --bind "enter:execute-silent(gvim {1} &)"
|
||||
fi
|
||||
|
||||
|
||||
49
fetch_citation
Executable file
49
fetch_citation
Executable file
@@ -0,0 +1,49 @@
|
||||
#!/bin/bash
|
||||
if [ "$1" == "-h" ] ; then
|
||||
echo "
|
||||
fetch_citation - extract citation for citekey in a bibtex.bib or bibjson.json file
|
||||
|
||||
usage:
|
||||
fetch_citation citeKey
|
||||
|
||||
depends:
|
||||
grep, sed, echo
|
||||
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/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
|
||||
|
||||
#requires one citeKey string as input
|
||||
citeKey=$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
|
||||
@@ -15,6 +15,9 @@ set -e
|
||||
|
||||
appPath="$HOME/projects/dev/reveal.js"
|
||||
portNumber=${2:-8000}
|
||||
fn=$1 #markdown document to render e.g. neuroanatomy1.md
|
||||
basefn=$(basename $fn)
|
||||
fullfn=$(realpath $fn)
|
||||
|
||||
if [[ ! -d $appPath ]]; then
|
||||
echo "reveal.js not found"
|
||||
@@ -23,13 +26,10 @@ else
|
||||
cd $appPath
|
||||
fi
|
||||
|
||||
fn=$1 #markdown document to render e.g. neuroanatomy1.md
|
||||
basefn=$(basename $fn)
|
||||
if [[ ! -e $basefn ]]; then
|
||||
ln -s $fn $basefn
|
||||
ln -s $fullfn $basefn
|
||||
fi
|
||||
|
||||
|
||||
#add markdown filename into html title tag
|
||||
fn2=$(echo $basefn | sed -E 's/[0-9]{2,4}-//g' | sed 's/\.md//') #prep filename
|
||||
sed -i -E "s|(<title>).+(<\/title>)|\1$fn2\2|" index.html #swap in document title
|
||||
|
||||
24
s
Executable file
24
s
Executable file
@@ -0,0 +1,24 @@
|
||||
#! /usr/bin/python
|
||||
# adapted from https://stackoverflow.com/questions/59052703/grep-or-ripgrep-how-to-find-only-files-that-match-multiple-patterns-not-only-o
|
||||
|
||||
import sys
|
||||
import subprocess
|
||||
from itertools import permutations
|
||||
|
||||
usage = """
|
||||
Search with multiple keywords across files within current and subdirs using ripgrep. Provides boolean AND type search.
|
||||
|
||||
Usage: s keyword1 keyword2
|
||||
e.g. s cerebral cetacean sand | f
|
||||
"""
|
||||
|
||||
# Check that the user puts in an argument, else print the usage variable, then quit.
|
||||
if len(sys.argv)< 2:
|
||||
print (usage)
|
||||
sys.exit(0)
|
||||
|
||||
rgarg = '|'.join(('.*'.join(x) for x in permutations(sys.argv[1:])))
|
||||
cmd = ['rg', '-lUi', '--multiline-dotall', rgarg, '.']
|
||||
# print(' '.join(cmd))
|
||||
proc = subprocess.run(cmd, capture_output=True)
|
||||
sys.stdout.write(proc.stdout.decode('utf-8'))
|
||||
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
|
||||
|
||||
13
sdoi.sh
13
sdoi.sh
@@ -24,8 +24,8 @@ set -e #exit if an error
|
||||
doi=$1
|
||||
fn=$2
|
||||
styleSheet=${pubmedStyleSheet:-$HOME/bin/pubmed2bibtex.xsl}
|
||||
bibdFileOut=${bibdFileOut:-$HOME/projects/bibd/OMEGA.bib}
|
||||
pdfPathOut=${pdfPathOut:-$HOME/projects/bibd/papers}
|
||||
bibdFileOut=${bibdFileOut:-$HOME/projects/learn/bibd/OMEGA.bib}
|
||||
pdfPathOut=${pdfPathOut:-$HOME/projects/learn/bibd/papers}
|
||||
relPath=$(basename $pdfPathOut)
|
||||
|
||||
#define functions
|
||||
@@ -45,7 +45,7 @@ import_bib() {
|
||||
fetchBib_pubmed() {
|
||||
#request pubmed xml and transform into bibtex
|
||||
curl -s "https://eutils.ncbi.nlm.nih.gov/entrez/eutils/efetch.fcgi?db=pubmed&id=$uid&retmode=xml" > $tmpBib.xml
|
||||
xsltproc --novalid $styleSheet $tmpBib.xml > $tmpBib
|
||||
xsltproc --novalid $styleSheet $tmpBib.xml >> $tmpBib
|
||||
}
|
||||
|
||||
fetchBib_doiDotOrg() {
|
||||
@@ -69,7 +69,9 @@ extract_name() {
|
||||
|
||||
append_bibfile() {
|
||||
#import bibtex
|
||||
#first grep for a uid (doi) in case its already in db
|
||||
#replace pubmed field with pmid
|
||||
sed -i -E "s|(\W*)pubmed = |\1pmid = |" $tmpBib
|
||||
#grep for a uid (doi) in case its already in db
|
||||
if [[ -z $(rg $doi $bibdFileOut) ]]; then
|
||||
echo "importing $tmpBib"
|
||||
cat $tmpBib >> $bibdFileOut
|
||||
@@ -91,7 +93,7 @@ append_pdf() {
|
||||
|
||||
clean_up() {
|
||||
#clean up
|
||||
rm -f $tmpBib.bib $tmpBib.bib.xml
|
||||
rm -f $tmpBib $tmpBib.xml
|
||||
exit 1
|
||||
}
|
||||
|
||||
@@ -118,5 +120,6 @@ if [ -s "$tmpBib" ]; then
|
||||
import_bib
|
||||
else
|
||||
echo "sorry, doi not found.."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
8
spdf.sh
8
spdf.sh
@@ -1,18 +1,16 @@
|
||||
#!/bin/bash
|
||||
if [ "$1" == "-h" ] ; then
|
||||
echo "
|
||||
spdf - search for a doi within a pdf. If found, use sdoi.sh to query pubmed, and append bibtex entry with the pdf to your local bib database file
|
||||
spdf - search for a doi within a pdf. If found, print the doi and then use sdoi.sh to query pubmed and append a bibtex entry with the pdf to your local bib database file
|
||||
|
||||
usage:
|
||||
spdf.sh file.pdf
|
||||
|
||||
depends:
|
||||
pdftotext - from ghostscript or poppler or texlive ?
|
||||
xsltproc, xmllint - xml programs from libxml
|
||||
pubmed2bibtex.xsl - xml processor stylesheet
|
||||
|
||||
defaults:
|
||||
Set the three required default file locations (xsl file, bib file, pdf directory)
|
||||
See sdoi.sh
|
||||
"
|
||||
exit 0
|
||||
fi
|
||||
@@ -37,6 +35,8 @@ fi
|
||||
if [ -z "$doi" ]; then
|
||||
echo "doi not found"
|
||||
exit 1
|
||||
else
|
||||
echo $doi
|
||||
fi
|
||||
|
||||
sdoi.sh $doi $fn
|
||||
|
||||
Reference in New Issue
Block a user