Split the binaries into two files

This commit is contained in:
Thomas Dehaeze 2020-05-26 08:33:31 +02:00
parent e7952e0c89
commit d7db2c747f
2 changed files with 613 additions and 531 deletions

View File

@ -0,0 +1,111 @@
#+TITLE: My own specific binaries
:DRAWER:
#+STARTUP: overview
#+LANGUAGE: en
#+EMAIL: dehaeze.thomas@gmail.com
#+AUTHOR: Dehaeze Thomas
#+HTML_LINK_HOME: ./index.html
#+HTML_LINK_UP: ./index.html
#+HTML_HEAD: <link rel="stylesheet" type="text/css" href="./css/htmlize.css"/>
#+HTML_HEAD: <link rel="stylesheet" type="text/css" href="./css/readtheorg.css"/>
#+HTML_HEAD: <script type="text/javascript" src="./js/jquery.min.js"></script>
#+HTML_HEAD: <script type="text/javascript" src="./js/bootstrap.min.js"></script>
#+HTML_HEAD: <script type="text/javascript" src="./js/jquery.stickytableheaders.min.js"></script>
#+HTML_HEAD: <script type="text/javascript" src="./js/readtheorg.js"></script>
#+PROPERTY: header-args:bash :comments both :mkdirp yes
#+PROPERTY: header-args:bash+ :shebang "#!/usr/bin/env bash"
:END:
* =remote-desktop= - Remote Desktop Connect
#+begin_src bash :tangle ~/.local/bin/remote-desktop
computer=$(echo -e 'RNICE\nPCMEL1\nPCNASS1\nPCMEG01' | dmenu -p 'Computer:' -l 20);
case $computer in
PCMEL1)
rdesktop -a 16 -P -z -x m -r sound:off -g "80%" -u "ESRF\OPPEL" -p $(pass esrf/PCMEL1/OPPEL | sed -n 1p) pcmel1
;;
PCMEG01)
rdesktop -a 16 -P -z -x m -r sound:off -g "80%" -u "ESRF\DEHAEZE" -p $(pass ssl.esrf.fr/dehaeze | sed -n 1p) pcmeg01
;;
PCNASS1)
rdesktop -a 16 -P -z -x m -r sound:off -g "80%" -u "ESRF\DEHAEZE" -p $(pass ssl.esrf.fr/dehaeze | sed -n 1p) pcnass1
;;
RNICE)
echo "Not yet implemented"
;;
,*)
echo "Not existing"
;;
esac
#+end_src
* =print-rnice= - Print on Rnice
#+begin_src bash :tangle ~/.local/bin/print-rnice
nbpage=$(echo -e '1\n2\n4' | dmenu -p 'Number of pages per sheet' -l 20);
sides=$(echo -e 'one-sided\ntwo-sided-long-edge\ntwo-sided-short-edge' | dmenu -p 'Two Sided:' -l 20);
# First copy the file to Rnice
if sshpass -p "$(pass ssl.esrf.fr/dehaeze | sed -n 1p)" scp $1 dehaeze@rnice:~/Downloads/; then
# Then print on Rnice
sshpass -p "$(pass ssl.esrf.fr/dehaeze | sed -n 1p)" ssh dehaeze@rnice "lpr -o media=A4 -o sides=$sides -o number-up=$nbpage -P ctb110c1u ~/Downloads/$1";
# Finally, delete the file
else
echo "Command Failed"
fi
#+end_src
* =tmp14= - Mount/Umount tmp_14_days folder
#+begin_src bash :tangle ~/.local/bin/tmp_14_days
if [ $1 == "mount" ]; then
if sshfs -o allow_other,default_permissions -p 5022 dehaeze@firewall.esrf.fr:/tmp_14_days/ ~/mnt/ESRF; then
dunstify --replace=58249 'ESRF TMP ' 'Successfully mounted'
else
dunstify --replace=58249 --urgency=critical 'ESRF TMP ' 'Error while mounted'
fi
elif [ $1 == "umount" ]; then
if umount /home/thomas/mnt/ESRF/; then
dunstify --replace=58249 'ESRF TMP ' 'Successfully unmounted'
else
dunstify --replace=58249 --urgency=critical 'ESRF TMP ' 'Error while unmounted'
fi
fi
#+end_src
* =nas= - Interact with the NAS
As an alternative, =sshfs= can be used:
#+begin_src bash :tangle no
sshfs -o allow_other,default_permissions nas:/Data ~/mnt/NAS
#+end_src
#+begin_src bash :tangle ~/.local/bin/nas
if [ $1 == "mount" ]; then
if mount /home/thomas/mnt/NAS/; then
dunstify --replace=58249 'NAS ' 'Successfully mounted'
else
dunstify --replace=58249 --urgency=critical 'NAS ' 'Error while mounted'
fi
elif [ $1 == "umount" ]; then
if umount /home/thomas/mnt/NAS/; then
dunstify --replace=58249 'NAS ' 'Successfully unmounted'
else
dunstify --replace=58249 --urgency=critical 'NAS ' 'Error while unmounted'
fi
fi
#+end_src
* =torrent-add= - Download Torrent
#+begin_src bash :tangle ~/.local/bin/torrent-add
transmission-remote 82.64.103.2:9091 --auth tdehaeze:$(pass nas/transmission | sed -n 1p) -a $1 && \
dunstify 'Torrent' 'Successfully added' || \
dunstify 'Torrent' 'Error'
#+end_src

View File

@ -92,24 +92,6 @@ Script taken from Luke Smith.
pgrep -x dunst >/dev/null && killall dunst && setsid dunst & # Restart dunst to ensure proper location on screen
#+end_src
* TODO =getbib=
#+begin_src bash :tangle ~/.local/bin/getbib
[ -z "$1" ] && echo "Give either a pdf file or a DOI as an argument." && exit
if [ -f "$1" ]; then
# Try to get DOI from pdfinfo or pdftotext output.
doi=$(pdfinfo "$1" | grep -io "doi:.*") ||
doi=$(pdftotext "$1" 2>/dev/null - | grep -io "doi:.*" -m 1) ||
exit 1
else
doi="$1"
fi
# Check crossref.org for the bib citation.
curl -s "http://api.crossref.org/works/$doi/transform/application/x-bibtex" -w "\\n"
#+end_src
* =vpntoggle= - Connect to VPN using NordVPN
#+begin_src bash :tangle ~/.local/bin/vpntoggle
@ -125,52 +107,52 @@ Script taken from Luke Smith.
* =bukurun= - Open link from Buku
#+begin_src bash :tangle ~/.local/bin/bukurun
_rofi () {
_rofi () {
rofi -dmenu -i -no-levenshtein-sort -width 1000 "$@"
}
}
# display settings
display_type=1
max_str_width=80
# display settings
display_type=1
max_str_width=80
# keybindings
switch_view="Alt+Tab"
new_bookmark="Alt+n"
actions="Alt+a"
edit="Alt+e"
delete="Alt+d"
# keybindings
switch_view="Alt+Tab"
new_bookmark="Alt+n"
actions="Alt+a"
edit="Alt+e"
delete="Alt+d"
# colors
help_color="#334433"
# colors
help_color="#334433"
# source global config
if [[ -f /etc/buku_run.config ]]
then
# source global config
if [[ -f /etc/buku_run.config ]]
then
source /etc/buku_run.config
fi
fi
# source local config:
if [[ -z $XDG_CONFIG_DIR ]]
then
# source local config:
if [[ -z $XDG_CONFIG_DIR ]]
then
if [[ -f $HOME/.config/buku_run/config ]]
then
source $HOME/.config/buku_run/config
else
echo "User config file \'~/.config/buku_run/config\' not found. using global config"
fi
else
else
if [[ -f "${XDG_CONFIG_DIR}/buku_run/config" ]]
then
source "${XDG_CONFIG_DIR}/buku_run/config"
else
echo "User config file \'~/.config/buku_run/config\' not found. using global config"
fi
fi
fi
main () {
main () {
HELP="Welcome to Buku. Use <span color='${help_color}'>${new_bookmark}</span> to add a new Bookmark
Use <span color='${help_color}'>${switch_view}</span> to switch View. <span color='${help_color}'>${actions}</span> for actions"
Use <span color='${help_color}'>${switch_view}</span> to switch View. <span color='${help_color}'>${actions}</span> for actions"
if [[ $mode == "bookmarks" ]]; then
content=$(parseBuku)
menu=$(echo "${content}" | _rofi -p '> ' -filter "${filter}" -mesg "${HELP}" -kb-custom-1 "${new_bookmark}" -kb-custom-2 "${switch_view}" -kb-custom-3 "${actions}" -kb-custom-4 "${edit}" -kb-custom-5 "${delete}")
@ -206,9 +188,9 @@ Use <span color='${help_color}'>${switch_view}</span> to switch View. <span colo
filter="${menu}" mode="bookmarks" main
fi
fi
}
}
optionsMenu () {
optionsMenu () {
if [[ $mode == "bookmarks" ]]; then
askmenu=$(echo -e "< Return\n---\n1. Edit\n2. Delete" | _rofi -p '> ' -mesg "Choose Action for bookmark")
val=$?
@ -262,9 +244,9 @@ optionsMenu () {
fi
fi
fi
}
}
deleteMenu () {
deleteMenu () {
id=$(getId "$content" "$menu")
delask=$(echo -e "1. Yes\n2. No" | _rofi -p '> ' -mesg "Really delete bookmark?")
val=$?
@ -278,9 +260,9 @@ deleteMenu () {
optionsMenu
fi
fi
}
}
editMenu () {
editMenu () {
id=$(getId "$content" "$menu")
title="$(getTitleFromId $id)"
bookmark="$(getUrlFromId $id)"
@ -303,9 +285,9 @@ editMenu () {
editTitle
fi
fi
}
}
editTags () {
editTags () {
edittagsmenu=$(echo | _rofi -filter "${tags}" -p '> ' -mesg "Edit Tags and hit Enter")
val=$?
if [[ $val -eq 1 ]]; then
@ -314,9 +296,9 @@ editTags () {
buku -u ${id} --tag "${edittagsmenu}"
fi
mode=bookmarks main
}
}
editBookmark () {
editBookmark () {
bmarkmenu=$(echo "" | _rofi -p "> " -filter "${bookmark}" -mesg "Edit Bookmark and hit Enter")
val=$?
if [[ $val -eq 1 ]]; then
@ -330,9 +312,9 @@ editBookmark () {
fi
fi
mode=bookmarks main
}
}
editTitle () {
editTitle () {
titlemenu=$(echo "" | _rofi -p "> " -filter "${title}" -mesg "Edit Title and hit Enter")
val=$?
if [[ $val -eq 1 ]]; then
@ -341,9 +323,9 @@ editTitle () {
buku -u "${id}" --title "${titlemenu}"
fi
mode=bookmarks main
}
}
addMark () {
addMark () {
inserturl=$(echo -e "$(xclip -o)" | _rofi -p '> ' -mesg "Use URL below or type manually")
val=$?
if [[ $val -eq 1 ]]; then
@ -351,9 +333,9 @@ addMark () {
elif [[ $val -eq 0 ]]; then
addTags
fi
}
}
addTags () {
addTags () {
inserttags=$(buku --np --st | awk '{$NF=""; print $0}' | cut -d ' ' -f2- | _rofi -p '> ' -mesg "Add some tags. Separate tags with ', '")
val=$?
if [[ $val -eq 1 ]]; then
@ -374,15 +356,15 @@ addTags () {
buku -a ${inserturl} ${tags}
fi
fi
}
}
parseBuku () {
parseBuku () {
echo "$(buku --nc -p | gawk -v max="$max_str_width" -v type="$display_type" '
BEGIN {
BEGIN {
RS=""
FS="\n"
}
{
}
{
if ($3 == "")
$3 = " # NOTAG"
id = gensub(/([0-9]+)\.(.*)/, "\\1", "g", $1)
@ -397,11 +379,11 @@ BEGIN {
if (type == 3)
print " \t" url "\t "
print ""
}
' | column -t -s $'\t')"
}
}
' | column -t -s $'\t')"
}
getId () {
getId () {
id=$(echo "${2%% *}")
if [ -z "$id" ]; then
prev=""
@ -416,9 +398,9 @@ getId () {
done
fi
echo $id
}
}
getTitleFromId () {
getTitleFromId () {
echo "$(buku --nc -p $1 | gawk '
BEGIN {
RS=""
@ -428,9 +410,9 @@ getTitleFromId () {
print gensub(/[0-9]+\.\s*(.*)/, "\\1", "g", $1)
}
')"
}
}
getUrlFromId () {
getUrlFromId () {
echo "$(buku --nc -p $1 | gawk '
BEGIN {
RS=""
@ -440,9 +422,9 @@ getUrlFromId () {
print gensub(/\s+> (.*)/, "\\1", "g", $2)
}
')"
}
}
getTagsFromId () {
getTagsFromId () {
echo "$(buku --nc -p $1 | gawk '
BEGIN {
RS=""
@ -452,61 +434,47 @@ getTagsFromId () {
print gensub(/\s+# (.*)/, "\\1", "g", $3)
}
')"
}
}
mode=bookmarks main
mode=bookmarks main
#+end_src
* =i3exit= - Manage lock, suspend, reboot, ...
#+begin_src bash :tangle ~/.local/bin/i3exit
# with openrc use loginctl
case "$1" in
lock)
option=$(echo -e "Lock\nExit\nLogout\nSuspend\nHibernate\nReboot\nShutdown" | rofi -i -dmenu)
case "$option" in
"Lock")
~/.local/bin/lockscreen
;;
logout)
loginctl terminate-session `loginctl session-status | head -n 1 | awk '{print $1}'`
;;
switch_user)
"Exit")
dm-tool switch-to-greeter
;;
suspend)
"Logout")
loginctl terminate-session `loginctl session-status | head -n 1 | awk '{print $1}'`
;;
"Suspend")
systemctl suspend && ~/.local/bin/lockscreen
;;
hibernate)
"Hibernate")
systemctl hibernate && ~/.local/bin/lockscreen
;;
reboot)
"Reboot")
systemctl reboot
;;
shutdown)
"Shutdown")
systemctl poweroff
;;
,*)
echo "== ! i3exit: missing or invalid argument ! =="
echo "Try again with: lock | logout | switch_user | suspend | hibernate | reboot | shutdown"
exit 2
esac
exit 0
#+end_src
* =readbib= - Open Bibliography File
#+begin_src bash :tangle ~/.local/bin/readbib
cd ~/Cloud/thesis/ressources/pdfs/ && ls | rofi -dmenu -lines 20 | xargs -I {} zathura {}
#+end_src
* =readnotes= - Open Note File
#+begin_src bash :tangle ~/.local/bin/readnotes
cd ~/Cloud/thesis/ressources/notes/pdfs/ && ls *.pdf | rofi -dmenu -lines 20 | xargs -I {} zathura {}
#+end_src
* TODO =askpass-rofi= - askpass
- [ ] Should be a script
* =askpass-rofi= - GUI prompt for passwords
Take password prompt from STDIN, print password to STDOUT.
The sed piece just removes the colon from the provided prompt: =rofi -p= already gives us a colon
#+BEGIN_SRC bash :tangle ~/.local/bin/askpass-rofi
@ -547,30 +515,6 @@ The sed piece just removes the colon from the provided prompt: =rofi -p= already
esac
#+end_src
* =remote-desktop= - Remote Desktop Connect
#+begin_src bash :tangle ~/.local/bin/remote-desktop
computer=$(echo -e 'RNICE\nPCMEL1\nPCNASS1\nPCMEG01' | dmenu -p 'Computer:' -l 20);
case $computer in
PCMEL1)
rdesktop -a 16 -P -z -x m -r sound:off -g "80%" -u "ESRF\OPPEL" -p $(pass esrf/PCMEL1/OPPEL | sed -n 1p) pcmel1
;;
PCMEG01)
rdesktop -a 16 -P -z -x m -r sound:off -g "80%" -u "ESRF\DEHAEZE" -p $(pass ssl.esrf.fr/dehaeze | sed -n 1p) pcmeg01
;;
PCNASS1)
rdesktop -a 16 -P -z -x m -r sound:off -g "80%" -u "ESRF\DEHAEZE" -p $(pass ssl.esrf.fr/dehaeze | sed -n 1p) pcnass1
;;
RNICE)
echo "Not yet implemented"
;;
,*)
echo "Not existing"
;;
esac
#+end_src
* =network-toggle= - Toggle Network
#+begin_src bash :tangle ~/.local/bin/network-toggle
@ -586,32 +530,7 @@ The sed piece just removes the colon from the provided prompt: =rofi -p= already
fi
#+end_src
* =print-rnice= - Print on Rnice
#+begin_src bash :tangle ~/.local/bin/print-rnice
nbpage=$(echo -e '1\n2\n4' | dmenu -p 'Number of pages per sheet' -l 20);
sides=$(echo -e 'one-sided\ntwo-sided-long-edge\ntwo-sided-short-edge' | dmenu -p 'Two Sided:' -l 20);
# First copy the file to Rnice
if sshpass -p "$(pass ssl.esrf.fr/dehaeze | sed -n 1p)" scp $1 dehaeze@rnice:~/Downloads/; then
# Then print on Rnice
sshpass -p "$(pass ssl.esrf.fr/dehaeze | sed -n 1p)" ssh dehaeze@rnice "lpr -o media=A4 -o sides=$sides -o number-up=$nbpage -P ctb110c1u ~/Downloads/$1";
# Finally, delete the file
else
echo "Command Failed"
fi
#+end_src
* TODO =mnt_tmp_14_days= - Mount TMP14DAYS
- [ ] Put that as a script?
#+begin_src bash :tangle ~/.local/bin/mnt_tmp_14_days
sudo -A mkdir ~/tmp_14_days;
sudo -A mount -o rw,relatime,vers=3,rsize=1048576,wsize=1048576,namlen=255,hard,proto=tcp,timeo=600,retrans=2,sec=sys,mountaddr=160.103.232.103,mountvers=3,mountport=597,mountproto=tcp,local_lock=none,addr=160.103.232.103 rnice:/hz/tmp_14_days ~/tmp_14_days;
#+end_src
* =make-gif= - Make GIF
http://blog.pkh.me/p/21-high-quality-gif-with-ffmpeg.html
#+begin_src bash :tangle ~/.local/bin/make-gif
palette="/tmp/palette.png"
@ -621,6 +540,7 @@ http://blog.pkh.me/p/21-high-quality-gif-with-ffmpeg.html
ffmpeg -v warning -i $1 -vf "$filters,palettegen" -y $palette
ffmpeg -v warning -i $1 -i $palette -lavfi "$filters [x]; [x][1:v] paletteuse" -y $2
#+end_src
* =yt-audio= - Download-Audio from youtube
#+begin_src bash :tangle ~/.local/bin/yt-audio
@ -642,77 +562,6 @@ else
setsid nohup youtube-dl --add-metadata -ic $1 &> /dev/null &
fi
#+end_src
* =pdf-shrink= Pdf Shrink
#+begin_src bash :tangle ~/.local/bin/pdf-shrink
shrink ()
{
gs \
-q -dNOPAUSE -dBATCH -dSAFER \
-sDEVICE=pdfwrite \
-dCompatibilityLevel=1.3 \
-dPDFSETTINGS=/screen \
-dEmbedAllFonts=true \
-dSubsetFonts=true \
-dAutoRotatePages=/None \
-dColorImageDownsampleType=/Bicubic \
-dColorImageResolution=$3 \
-dGrayImageDownsampleType=/Bicubic \
-dGrayImageResolution=$3 \
-dMonoImageDownsampleType=/Subsample \
-dMonoImageResolution=$3 \
-sOutputFile="$2" \
"$1"
}
check_smaller ()
{
# 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:
if [ ! -f "$1" -o ! -f "$2" ]; then
return 0;
fi
ISIZE="$(echo $(wc -c "$1") | cut -f1 -d\ )"
OSIZE="$(echo $(wc -c "$2") | cut -f1 -d\ )"
if [ "$ISIZE" -lt "$OSIZE" ]; then
echo "Input smaller than output, doing straight copy" >&2
cp "$1" "$2"
fi
}
usage ()
{
echo "Reduces PDF filesize by lossy recompressing with Ghostscript."
echo "Not guaranteed to succeed, but usually works."
echo " Usage: $1 infile [outfile] [resolution_in_dpi]"
}
IFILE="$1"
# Need an input file:
if [ -z "$IFILE" ]; then
usage "$0"
exit 1
fi
# Output filename defaults to "-" (stdout) unless given:
if [ ! -z "$2" ]; then
OFILE="$2"
else
OFILE="-"
fi
# Output resolution defaults to 72 unless given:
if [ ! -z "$3" ]; then
res="$3"
else
res="90"
fi
shrink "$IFILE" "$OFILE" "$res" || exit $?
check_smaller "$IFILE" "$OFILE"
#+end_src
* =setbg= - Set Background
#+begin_src bash :tangle ~/.local/bin/setbg
@ -730,7 +579,7 @@ fi
# Must have xclip installed to even show menu.
xclip -h 2>/dev/null || exit 1
chosen=$(cut -d ';' -f1 ~/.local/data/emoji | rofi -dmenu -i -l 20 | sed "s/ .*//")
chosen=$(cut -d ';' -f1 ~/.local/data/emojis | rofi -dmenu -i -l 20 | sed "s/ .*//")
[ "$chosen" != "" ] || exit
@ -762,29 +611,6 @@ fi
fi
#+end_src
* =nas= - Interact with the NAS
As an alternative, =sshfs= can be used:
#+begin_src bash :tangle no
sshfs -o allow_other,default_permissions nas:/Data ~/mnt/NAS
#+end_src
#+begin_src bash :tangle ~/.local/bin/nas
if [ $1 == "mount" ]; then
if mount /home/thomas/mnt/NAS/; then
dunstify --replace=58249 'NAS ' 'Successfully mounted'
else
dunstify --replace=58249 --urgency=critical 'NAS ' 'Error while mounted'
fi
elif [ $1 == "umount" ]; then
if umount /home/thomas/mnt/NAS/; then
dunstify --replace=58249 'NAS ' 'Successfully unmounted'
else
dunstify --replace=58249 --urgency=critical 'NAS ' 'Error while unmounted'
fi
fi
#+end_src
* =linkhandler= - Open with Default application
Inspired from =linkhandler= https://github.com/LukeSmithxyz/voidrice/
This is used in =newsboat= to handle links
@ -871,40 +697,6 @@ Finally, lock the screen using =i3lock=.
revert
#+end_src
* TODO =quit= - Lock / Exit / Suspend / ...
- [ ] Seems duplicated with [[file:binaries.org::*=i3exit= - Manage lock, suspend, reboot, ...][=i3exit= - Manage lock, suspend, reboot, ...]]
- [ ] Also change the binary name
#+begin_src bash :tangle ~/.local/bin/quit
option=$(echo -e "Lock\nExit\nLogout\nSuspend\nHibernate\nReboot\nShutdown" | rofi -i -dmenu)
case "$option" in
"Lock")
i3exit lock ;;
"Exit")
i3exit switch_user ;;
"Logout")
i3exit logout ;;
"Suspend")
i3exit suspend ;;
"Hibernate")
i3exit hibernate ;;
"Reboot")
i3exit reboot ;;
"Shutdown")
i3exit shutdown ;;
esac
#+end_src
* =torrent-add= - Download Torrent
#+begin_src bash :tangle ~/.local/bin/torrent-add
transmission-remote 82.64.103.2:9091 --auth tdehaeze:$(pass nas/transmission | sed -n 1p) -a $1 && \
dunstify 'Torrent' 'Successfully added' || \
dunstify 'Torrent' 'Error'
#+end_src
* =mopidy-restart= - Restart Mopidy
#+begin_src bash :tangle ~/.local/bin/mopidy-restart
pids=( $(pgrep -f mopidy) )
@ -920,3 +712,182 @@ Finally, lock the screen using =i3lock=.
mopidy --config ~/.config/mopidy/mopidy.conf >/dev/null 2>&1 &
echo "Done"
#+end_src
* =upload= - Upload Script
#+begin_src bash :tangle ~/.local/bin/upload
if [ $TMUX ]; then
tmux split -v -l 1 "curl --progress-bar -F\"file=@$1\" https://0x0.st | xsel -ib;" && tmux select-pane -U
else
curl --progress-bar -F"file=@$1" https://0x0.st | xsel -ib && \
dunstify 'Upload' 'Successful' || \
dunstify --urgency=critical 'Upload' 'Failed'
fi
#+end_src
* =weather= - Display Weather in terminal
#+begin_src bash :tangle ~/.local/bin/weather
if [ -n "$*" ]; then
address="wttr.in/"
address+=$*
else
address="wttr.in/"
fi
if type sxiv > /dev/null 2>&1; then
address+=".png"
wget -qO- "$address" > /tmp/weather.png && \
sxiv -b /tmp/weather.png
elif type feh > /dev/null 2>&1; then
address+=".png"
wget -qO- "$address" | feh -
else
curl "$address"
fi
#+end_src
* =readbib= - Open Bibliography File
#+begin_src bash :tangle ~/.local/bin/readbib
cd ~/Cloud/pdfs/ && ls | rofi -dmenu -lines 20 | xargs -I {} zathura {}
#+end_src
* =readnotes= - Open Note File
#+begin_src bash :tangle ~/.local/bin/readnotes
cd ~/Cloud/thesis/ressources/notes/pdfs/ && ls *.pdf | rofi -dmenu -lines 20 | xargs -I {} zathura {}
#+end_src
* =pdf2bib= - Extract bibtex entry from PDF file
#+begin_src bash :tangle ~/.local/bin/pdf2bib
pdf2doi () {
pdfinfo "$1" | grep -io "doi:.*" | grep -Poi "10.\d+/[^\s]+" || \
pdftotext "$1" 2>/dev/null - | grep -io "doi:.*" -m 1 | grep -Poi "10.\d+/[^\s]+" || \
pdftotext "$1" 2>/dev/null - | grep -Poi "10.\d+/[^\s]+"
}
doi2bib () {
# curl -LHs "Accept: application/x-bibtex" http://dx.doi.org/$1 -w "\\n"
curl -s "http://api.crossref.org/works/$1/transform/application/x-bibtex" -w "\\n"
}
# If a file is specified, try to extract DOI from the file
if [ -f "$1" ]; then
doi=$(pdf2doi "$1")
fi
if hash rofi 2>/dev/null; then
doi=$(echo "$doi" | rofi -i -dmenu -p "DOI")
else
doi=$(echo "$doi" | dmenu -i -p "DOI")
fi
if [ -n "$1" ]; then
doi2bib $doi | xsel -ib && \
dunstify 'BibTeX' 'Copied to Clipboard' || \
dunstify --urgency=critical 'BibTeX' 'Failed'
fi
#+end_src
* =pdf2png= - Convert a PDF to PNG
#+begin_src bash :tangle ~/.local/bin/pdf2png
if [[ -f $1 && $1 == *.pdf ]]; then
pdftoppm -png $1 > $(echo $1 | cut -f 1 -d '.' | sed 's/$/.png/')
fi
#+end_src
* =pdf-shrink= - Pdf Shrink
#+begin_src bash :tangle ~/.local/bin/pdf-shrink
shrink ()
{
gs \
-q -dNOPAUSE -dBATCH -dSAFER \
-sDEVICE=pdfwrite \
-dCompatibilityLevel=1.3 \
-dPDFSETTINGS=/screen \
-dEmbedAllFonts=true \
-dSubsetFonts=true \
-dAutoRotatePages=/None \
-dColorImageDownsampleType=/Bicubic \
-dColorImageResolution=$3 \
-dGrayImageDownsampleType=/Bicubic \
-dGrayImageResolution=$3 \
-dMonoImageDownsampleType=/Subsample \
-dMonoImageResolution=$3 \
-sOutputFile="$2" \
"$1"
}
check_smaller ()
{
# 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:
if [ ! -f "$1" -o ! -f "$2" ]; then
return 0;
fi
ISIZE="$(echo $(wc -c "$1") | cut -f1 -d\ )"
OSIZE="$(echo $(wc -c "$2") | cut -f1 -d\ )"
if [ "$ISIZE" -lt "$OSIZE" ]; then
echo "Input smaller than output, doing straight copy" >&2
cp "$1" "$2"
fi
}
usage ()
{
echo "Reduces PDF filesize by lossy recompressing with Ghostscript."
echo "Not guaranteed to succeed, but usually works."
echo " Usage: $1 infile [outfile] [resolution_in_dpi]"
}
IFILE="$1"
# Need an input file:
if [ -z "$IFILE" ]; then
usage "$0"
exit 1
fi
# Output filename defaults to "-" (stdout) unless given:
if [ ! -z "$2" ]; then
OFILE="$2"
else
OFILE="-"
fi
# Output resolution defaults to 72 unless given:
if [ ! -z "$3" ]; then
res="$3"
else
res="90"
fi
shrink "$IFILE" "$OFILE" "$res" || exit $?
check_smaller "$IFILE" "$OFILE"
#+end_src
* =pdf-delete-annotations= - Delete Annotations from PDFs
From: https://gist.github.com/stefanschmidt/5248592
#+begin_src bash :tangle ~/.local/bin/pdf-delete-annotations
pdftk $1 output /tmp/uncompressed.pdf uncompress
LANG=C sed -n '/^\/Annots/!p' /tmp/uncompressed.pdf > /tmp/stripped.pdf
pdftk /tmp/stripped.pdf output $1 compress
#+end_src
* =pdf-delete-first-page= - Delete first page of PDF
The requirement is to have =pdftk= or =stapler= installed.
#+begin_src bash :tangle ~/.local/bin/pdf-delete-first-page
if [[ -f $1 && $1 == *.pdf ]]; then
# Argument if a file
if type stapler > /dev/null 2>&1; then
stapler del "$1" 1 /tmp/pdftk_out.pdf && mv /tmp/pdftk_out.pdf "$1"
elif type pdftk > /dev/null 2>&1; then
pdftk "$1" cat 2-end output /tmp/pdftk_out.pdf && mv /tmp/pdftk_out.pdf "$1"
else
echo "Neither pdftk nor stapler are installed"
fi
fi
#+end_src