Skip to content

Instantly share code, notes, and snippets.

@TwistingTwists
Last active April 4, 2020 13:16
Show Gist options
  • Save TwistingTwists/2748e3fe8a3573d10f2a3b554f3c32cb to your computer and use it in GitHub Desktop.
Save TwistingTwists/2748e3fe8a3573d10f2a3b554f3c32cb to your computer and use it in GitHub Desktop.
for pdfgrep functionality from terminal
pres () {
# to include all subfolder for search.
it="$2"
#pdfgrep -n -> for printing page number
case "$it" in
"y") echo "Searching Mains test series too" && find . -name "*.pdf" -print0 | xargs -0 pdfgrep -inH --cache "$1" ;;
"n") echo "Only in monthlies " && pdfgrep -inH "$1" --cache *.pdf ;;
*) find . -name "*.pdf" -print0 | xargs -0 pdfgrep -inH --cache "$1" ;;
esac
}
PRES () {
# to include all subfolder for search.
it="$2"
#pdfgrep -n -> for printing page number
case "$it" in
"y") echo "Searching Mains test series too" && find . -name "*.pdf" -print0 | xargs -0 pdfgrep -nH --cache "$1" ;;
"n") echo "Only in monthlies " && pdfgrep -nH "$1" --cache *.pdf ;;
*) find . -name "*.pdf" -print0 | xargs -0 pdfgrep -nH --cache "$1" ;;
esac
}
op(){
# cd /Users/abhishektripathi/Box/MAINS\ 2019/Prelims2020
for f in "$@"
do
find . -iname "*$f*" -print0 | xargs -0 open
done
# cd -
}
cas (){
# different implemenattion for macos Because files are stored differently
# exclude files with names like `[Raus' focus septemer.pdf`
find . -type f -name "*.pdf" -print0 | xargs -0 pdfgrep -inH --cache "$1"
# find . -type f -regex "^(?![]).*\.pdf" -print0 | xargs -0 pdfgrep -inH --cache "$1"
# https://stackoverflow.com/questions/2116328/regexp-matching-string-not-starting-with-my
# '^(?![).*\.(pdf|jpg|png)' -
# ^(?!) - not starting with `[` for file name of type `[Raus' focus septemer.pdf`
# .(pdf|jpg|png) - for handling multiple type extnesions
# find -regextype posix-extended . -regex '^(?!\[).*\.(pdf|jpg|png)' -print0 | xargs -0 pdfgrep -inH --cache "$1"
}
CAS (){
find . -type f -name "*.pdf" -print0 | xargs -0 pdfgrep -nH --cache "$1"
}
readsofar(){
history -n "$1" | grep -e 'cas "' | grep -ve "history" | tr -s " " | cut -d" " -f2 | uniq
# history | grep -e 'cas "' | tail -n "$1" | grep -ve "history" | sed 's/ */:/g' | cut -d : -f2,3 | sort -u
# history -n 100 | grep -e 'cas "' | grep -ve "history" | tr -s " " | cut -d" " -f2 | uniq
}
export HISTIGNORE=' *'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment