Update some scripts

This commit is contained in:
Thomas Dehaeze 2020-11-03 11:39:35 +01:00
parent b5fa40b136
commit cd9697c18b

View File

@ -876,14 +876,13 @@ Finally, lock the screen using =i3lock=.
curl "$address" curl "$address"
fi fi
#+end_src #+end_src
* =readbib= - Open Bibliography File
* =readbib= - Open Bibliography File
#+begin_src bash :tangle ~/.local/bin/readbib #+begin_src bash :tangle ~/.local/bin/readbib
cd ~/Cloud/pdfs/ && ls | rofi -dmenu -lines 20 | xargs -I {} zathura {} cd ~/Cloud/pdfs/ && ls | rofi -dmenu -lines 20 | xargs -I {} zathura {}
#+end_src #+end_src
* =readnotes= - Open Note File * =readnotes= - Open Note File
#+begin_src bash :tangle ~/.local/bin/readnotes #+begin_src bash :tangle ~/.local/bin/readnotes
cd ~/Cloud/thesis/ressources/notes/pdfs/ && ls *.pdf | rofi -dmenu -lines 20 | xargs -I {} zathura {} cd ~/Cloud/thesis/ressources/notes/pdfs/ && ls *.pdf | rofi -dmenu -lines 20 | xargs -I {} zathura {}
#+end_src #+end_src
@ -921,75 +920,75 @@ Finally, lock the screen using =i3lock=.
* =pdf2png= - Convert a PDF to PNG * =pdf2png= - Convert a PDF to PNG
#+begin_src bash :tangle ~/.local/bin/pdf2png #+begin_src bash :tangle ~/.local/bin/pdf2png
if [[ -f $1 && $1 == *.pdf ]]; then if [[ -f "$1" && "$1" == *.pdf ]]; then
pdftoppm -png $1 > $(echo $1 | cut -f 1 -d '.' | sed 's/$/.png/') pdftoppm -png "$1" > "$(echo "$1" | cut -f 1 -d '.' | sed 's/$/.png/')"
fi fi
#+end_src #+end_src
* =pdf-shrink= - Pdf Shrink
* =pdf-shrink= - Pdf Shrink
#+begin_src bash :tangle ~/.local/bin/pdf-shrink #+begin_src bash :tangle ~/.local/bin/pdf-shrink
shrink () shrink ()
{ {
gs \ gs \
-q -dNOPAUSE -dBATCH -dSAFER \ -q -dNOPAUSE -dBATCH -dSAFER \
-sDEVICE=pdfwrite \ -sDEVICE=pdfwrite \
-dCompatibilityLevel=1.3 \ -dCompatibilityLevel=1.3 \
-dPDFSETTINGS=/screen \ -dPDFSETTINGS=/screen \
-dEmbedAllFonts=true \ -dEmbedAllFonts=true \
-dSubsetFonts=true \ -dSubsetFonts=true \
-dAutoRotatePages=/None \ -dAutoRotatePages=/None \
-dColorImageDownsampleType=/Bicubic \ -dColorImageDownsampleType=/Bicubic \
-dColorImageResolution=$3 \ -dColorImageResolution=$3 \
-dGrayImageDownsampleType=/Bicubic \ -dGrayImageDownsampleType=/Bicubic \
-dGrayImageResolution=$3 \ -dGrayImageResolution=$3 \
-dMonoImageDownsampleType=/Subsample \ -dMonoImageDownsampleType=/Subsample \
-dMonoImageResolution=$3 \ -dMonoImageResolution=$3 \
-sOutputFile="$2" \ -sOutputFile="$2" \
"$1" "$1"
} }
check_smaller () check_smaller ()
{ {
# If $1 and $2 are regular files, we can compare file sizes to # If $1 and $2 are regular files, we can compare file sizes to
# see if we succeeded in shrinking. If not, we copy $1 over $2: # see if we succeeded in shrinking. If not, we copy $1 over $2:
if [ ! -f "$1" -o ! -f "$2" ]; then if [ ! -f "$1" -o ! -f "$2" ]; then
return 0; return 0;
fi fi
ISIZE="$(echo $(wc -c "$1") | cut -f1 -d\ )" ISIZE="$(echo $(wc -c "$1") | cut -f1 -d\ )"
OSIZE="$(echo $(wc -c "$2") | cut -f1 -d\ )" OSIZE="$(echo $(wc -c "$2") | cut -f1 -d\ )"
if [ "$ISIZE" -lt "$OSIZE" ]; then if [ "$ISIZE" -lt "$OSIZE" ]; then
echo "Input smaller than output, doing straight copy" >&2 echo "Input smaller than output, doing straight copy" >&2
cp "$1" "$2" cp "$1" "$2"
fi fi
} }
usage () usage ()
{ {
echo "Reduces PDF filesize by lossy recompressing with Ghostscript." echo "Reduces PDF filesize by lossy recompressing with Ghostscript."
echo "Not guaranteed to succeed, but usually works." echo "Not guaranteed to succeed, but usually works."
echo " Usage: $1 infile [outfile] [resolution_in_dpi]" echo " Usage: $1 infile [outfile] [resolution_in_dpi]"
} }
IFILE="$1" IFILE="$1"
# Need an input file: # Need an input file:
if [ -z "$IFILE" ]; then if [ -z "$IFILE" ]; then
usage "$0" usage "$0"
exit 1 exit 1
fi fi
# Output filename defaults to "-" (stdout) unless given: # Output filename defaults to "-" (stdout) unless given:
if [ ! -z "$2" ]; then if [ ! -z "$2" ]; then
OFILE="$2" OFILE="$2"
else else
OFILE="-" OFILE="-"
fi fi
# Output resolution defaults to 72 unless given: # Output resolution defaults to 72 unless given:
if [ ! -z "$3" ]; then if [ ! -z "$3" ]; then
res="$3" res="$3"
else else
res="90" res="90"
fi fi
shrink "$IFILE" "$OFILE" "$res" || exit $? shrink "$IFILE" "$OFILE" "$res" || exit $?
@ -1021,3 +1020,25 @@ The requirement is to have =pdftk= or =stapler= installed.
fi fi
#+end_src #+end_src
* =rofi-calc= - Simple Calculation using Rofi
#+begin_src bash :tangle ~/.local/bin/rofi-calc
rofi -show calc -mode calc -no-show-match -no-sort
#+end_src
* =pass-gen= - Generate Random Alphanumeric Password
#+begin_src bash :tangle ~/.local/bin/pass-gen
num=$(rofi -dmenu -p "Number of caracters")
pass=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1)
re='^[0-9]+$'
if [[ $num =~ $re ]] ; then
pass=${pass:0:$num}
fi
printf "$pass" | xclip -sel clip && \
dunstify 'Password' 'Generated'
#+end_src