commit d325de0b931957f769dd4680eb7ed49d7dcbe0b7
parent b3a69fba9e7a86b4a4b30777cff62462943ae1df
Author: Oscar Benedito <oscar@oscarbenedito.com>
Date:   Tue,  4 May 2021 20:51:23 +0200

Multiple script edits

Diffstat:
M.config/zsh/aliases | 21++++++++++++++++++++-
M.local/bin/configure-monitors | 14+++++++-------
M.local/bin/dwmblocks/dwmb-apt-updates | 4++--
M.local/bin/dwmblocks/dwmb-backups | 2+-
M.local/bin/dwmblocks/dwmb-torrents | 13+++++++------
M.local/bin/wallabag-to-ebook | 41+++++++++++++++++++++++------------------
M.local/share/dwm/autostart.sh | 1+
7 files changed, 61 insertions(+), 35 deletions(-)

diff --git a/.config/zsh/aliases b/.config/zsh/aliases @@ -29,8 +29,9 @@ alias vw="cd $HOME/Documents/wiki && vim index.md" alias bvw="firefox $HOME/Documents/wiki/build/html/index.html" alias c="git --git-dir=$HOME/.local/share/dotfiles --work-tree=$HOME" alias cv="GIT_DIR=$HOME/.local/share/dotfiles GIT_WORK_TREE=$HOME nvim -c Git -c only" -alias up="sudo apt-get update && sudo apt-get -y upgrade; pkill -RTMIN+4 dwmblocks" +alias up="sudo apt update && sudo apt -y upgrade; pkill -RTMIN+4 dwmblocks" # alias up="sudo pacman -Syyu --noconfirm" +alias ca="ncal -b -M -B1 -A1" # frequent files and directories alias cfa="$EDITOR $XDG_CONFIG_HOME/zsh/aliases" @@ -57,6 +58,24 @@ c-populate() { c checkout README.md COPYING } +# unite pdf after double side scanning +unite-pdf() { + if [ -z "$1" ] || [ -z "$2" ]; then + echo "Usage: unite-pdf odd even [output]" + else + [ -z "$3" ] && { 3="$(mktemp)" ; echo "$3" ; } + pdftk "A=$1" "B=$2" shuffle A Bend-1 output "$3" + fi +} + +restart-wifi-daemon() { + while true; do + curl -Is http://oscarbenedito.com > /dev/null || \ + { printf "Restarting wifi..."; nmcli radio wifi off; sleep 5; nmcli radio wifi on; printf " done\n"; } + sleep 30 + done +} + # Backup to external HD alias backup_all='rsync -loptruzvP --delete --exclude "/.*" "$HOME/" "/media/$USER/OSCAR/.backup_$(hostname)/"' diff --git a/.local/bin/configure-monitors b/.local/bin/configure-monitors @@ -16,13 +16,13 @@ elif [ -n "$(xrandr --query | grep "HDMI2 connected")" ]; then else echo "! Xft.dpi: 192" >> "$xr" fi -elif [ -n "$(xrandr --query | grep "HDMI2 connected")" ]; then - xrandr --output eDP1 --off --output HDMI2 --mode 3840x2160 - if grep --quiet "Xft.dpi: 192" "$xr"; then - sed -i "s/^! Xft.dpi: 192/Xft.dpi: 192/g" "$xr" - else - echo "Xft.dpi: 192" >> "$xr" - fi +# elif [ -n "$(xrandr --query | grep "HDMI2 connected")" ]; then +# xrandr --output eDP1 --off --output HDMI2 --mode 3840x2160 +# if grep --quiet "Xft.dpi: 192" "$xr"; then +# sed -i "s/^! Xft.dpi: 192/Xft.dpi: 192/g" "$xr" +# else +# echo "Xft.dpi: 192" >> "$xr" +# fi else xrandr --output eDP1 --auto --output DP2 --off if grep --quiet "Xft.dpi: 192" "$xr"; then diff --git a/.local/bin/dwmblocks/dwmb-apt-updates b/.local/bin/dwmblocks/dwmb-apt-updates @@ -1,5 +1,5 @@ #!/bin/sh -sudo apt-get update > /dev/null 2> /dev/null -UPDATES="$(apt-get upgrade -s |grep -P '^\d+ upgraded'|cut -d" " -f1)" +sudo apt update > /dev/null 2> /dev/null +UPDATES="$(apt upgrade -s |grep -P '^\d+ upgraded'|cut -d" " -f1)" [ "0" != "$UPDATES" ] && echo " $UPDATES" diff --git a/.local/bin/dwmblocks/dwmb-backups b/.local/bin/dwmblocks/dwmb-backups @@ -13,7 +13,7 @@ fi if [ "$(date --date="12 hours ago" +%s)" -ge "$lastdate" ]; then echo "" - restic-daily & + restic-daily > /dev/null & exit 0 else if [ "$lasterr" = "0" ]; then diff --git a/.local/bin/dwmblocks/dwmb-torrents b/.local/bin/dwmblocks/dwmb-torrents @@ -1,11 +1,12 @@ #!/bin/sh -transmission-remote -l | grep % | +transmission-remote -l | grep "%\|n/a" | sed " # The letters are for sorting and will not appear. - s/.*Stopped.*/A /; - s/.*Seeding.*/Z /; - s/.*100%.*/N /; s/.*Idle.*/B /; - s/.*Uploading.*/L /; - s/.*%.*/M /" | + s/.*Queued.*/C /; + s/.*Stopped.*/D /; + s/.*Uploading.*/E /; + s/.*Seeding.*/F /; + s/.*100%.*/G /; + s/.*%.*/A /" | sort -h | uniq -c | awk '{print $3, $1}' | paste -sd ' ' - diff --git a/.local/bin/wallabag-to-ebook b/.local/bin/wallabag-to-ebook @@ -4,6 +4,7 @@ domain="" phpsessid="" rememberme="" ebookpath="" +uuid="" # ebook UUID notify-send -u critical "Wallabag" "Script variables are not set." exit 1 @@ -14,32 +15,36 @@ override_notify() { } # check if ebook exists before starting download -deviceinfo="$(lsblk | grep "1.2G")" -[ -z "$deviceinfo" ] && { override_notify "Ebook not connected." -u critical; exit 1; } -[ "$(echo "$deviceinfo" | wc -l)" != "1" ] && { override_notify "Multiple devices might be ebook, mount manually." -u critical; exit 1; } +[ ! -e "/dev/disk/by-uuid/$uuid" ] && { override_notify "Ebook not connected." -u critical; exit 1; } + +# mount ebook and remove last entry if existent +udisksctl mount -b "/dev/disk/by-uuid/$uuid" || { override_notify "Error mounting ebook." -u critical; exit 1; } +rm -f $ebookpath/unread_articles_????-??-??.epub + +override_notify "Ebook mounted.\nDownloading..." -t 0 # download new epub file outfile=$(mktemp) -curl -s "https://$domain/export/unread.epub" \ +curl -s "https://$domain/export/unread.json" \ -H "cookie: PHPSESSID=$phpsessid; REMEMBERME=$rememberme" \ -o "$outfile" \ - & -pid="$!" - -override_notify "Downloading..." -t 0 - -# mount ebook and remove last entry if existent -udisksctl mount -b "/dev/${deviceinfo%% *}" || { override_notify "Error mounting ebook." -u critical; exit 1; } -rm -f $ebookpath/unread_articles_????-??-??.epub + || { override_notify "Download failed." -u critical; exit 1; } -override_notify "Downloading...\nEbook mounted." -t 0 +# if there new entries, download and transfer epub file +if [ "0" != "$(jq length "$outfile")" ]; then + curl -s "https://$domain/export/unread.epub" \ + -H "cookie: PHPSESSID=$phpsessid; REMEMBERME=$rememberme" \ + -o "$outfile" \ + || { override_notify "Download failed." -u critical; exit 1; } -# wait for download to finish -wait "$pid" + override_notify "Transferring files." -t 0 -override_notify "Transferring files." -t 0 + mv "$outfile" "$ebookpath/unread_articles_$(date +"%Y-%m-%d").epub" +fi -mv "$outfile" "$ebookpath/unread_articles_$(date +"%Y-%m-%d").epub" -udisksctl unmount -b "/dev/${deviceinfo%% *}" || { override_notify "Error unmounting ebook." -u critical; exit 1; } +# if unmount failed check 1 second later, it normally fixes it +udisksctl unmount -b "/dev/disk/by-uuid/$uuid" \ + || { sleep 1; udisksctl unmount -b "/dev/disk/by-uuid/$uuid"; } \ + || { override_notify "Error unmounting ebook." -u critical; exit 1; } override_notify "Finished successfully." -u low diff --git a/.local/share/dwm/autostart.sh b/.local/share/dwm/autostart.sh @@ -22,3 +22,4 @@ $HOME/.local/bin/configure-monitors & xsetroot -name " $(date +"%a %d %b, %H:%M")" & dwmblocks & +nm-applet &