detox --inline is just a utility which makes the file names shell friendly (removes special characters and spaces), but that is optional. Also, technically the newnamefn is what does all of the job, and below is just a loop to iterate on all files that are given as input like script file1 "file2" file3, where file2 had some special characters, so enclosed in "" quotes. you can also translate it to python, then you would not even require sed and grep (you can just get output in json-esque format). I have a small keybinding in my file manager, which renames all selected files, so I do not have to spend any amount of my mind
you can make it work in any os (maybe use some llm for it), you just have to install pdf2bib
I have a script which fetches bib entries for pdfs, and then renames it to my prefered format (names of author (no more than 2) - name of paper).
in case you are interested
#!/usr/bin/env sh newnamefn(){ bib="$(pdf2bib "$1")" name="$(echo "$bib" | grep "title = " | cut -d'{' -f 2 | cut -d'{' -f 1 )" authors=$(echo "$bib" | grep "author = " | cut -d'{' -f 2 | cut -d'{' -f 1 | sed -z 's/\ and\ /\n/g' | head -n 2 | tr '\n' ' ') echo "$authors-$name" | detox --inline } for i in "$@" ; do newname="$(newnamefn "$i")" mv "$i" "${i%/*}/$newname".pdf done
detox --inline is just a utility which makes the file names shell friendly (removes special characters and spaces), but that is optional. Also, technically the
newnamefn
is what does all of the job, and below is just a loop to iterate on all files that are given as input likescript file1 "file2" file3
, where file2 had some special characters, so enclosed in""
quotes. you can also translate it to python, then you would not even require sed and grep (you can just get output in json-esque format). I have a small keybinding in my file manager, which renames all selected files, so I do not have to spend any amount of my mindyou can make it work in any os (maybe use some llm for it), you just have to install
pdf2bib