From 774f14f273441cf1b8f4a02ef2c44486d9d310cd Mon Sep 17 00:00:00 2001 From: Luca Bilke Date: Tue, 7 Feb 2023 17:19:53 +0100 Subject: [PATCH] shfmt shfmt --- .config/X11/startgraphical | 62 ++++---- .config/X11/xprofile | 8 +- .config/X11/xsession | 124 +++++++-------- .config/X11/xsession.d/20dbus_xdg-runtime | 34 ++--- .config/X11/xsession.d/30x11-resources | 2 +- .config/X11/xsession.d/50atk-adaptor | 24 ++- .config/X11/xsession.d/50qt-a11y | 2 +- .config/X11/xsession.d/60gpg-agent | 4 +- .config/X11/xsession.d/90auto-start | 5 +- .config/nvim/lua/plugins/config/null-ls.lua | 1 + .local/bin/compiler | 77 +++++----- .local/bin/cron/README.md | 9 +- .local/bin/cron/checkup | 5 +- .local/bin/cron/crontog | 2 +- .local/bin/cron/mailsync | 81 +++++----- .local/bin/cron/newsup | 2 +- .local/bin/daemons/remapd | 8 +- .local/bin/daemons/sbd-battery | 2 +- .local/bin/daemons/sbd-music | 4 +- .local/bin/daemons/sbd-playerctl | 2 +- .local/bin/displayselect | 100 ++++++------ .local/bin/dmenuhandler | 29 ++-- .local/bin/dmenumount | 41 ++--- .local/bin/dmenumountcifs | 3 +- .local/bin/dmenurecord | 159 ++++++++++---------- .local/bin/dmenuumount | 25 +-- .local/bin/findup | 10 +- .local/bin/linkhandler | 26 ++-- .local/bin/maimpick | 13 +- .local/bin/opout | 6 +- .local/bin/pamixer-notify | 14 +- .local/bin/pauseallmpv | 2 +- .local/bin/prompt | 2 +- .local/bin/queueandnotify | 4 +- .local/bin/remaps | 42 +++--- .local/bin/remaps-no-change | 3 +- .local/bin/rssadd | 4 +- .local/bin/samedir | 4 +- .local/bin/setbg | 13 +- .local/bin/shortcuts | 2 +- .local/bin/statusbar/sb-aptpackages | 16 +- .local/bin/statusbar/sb-battery | 89 +++++++---- .local/bin/statusbar/sb-cpubars | 21 +-- .local/bin/statusbar/sb-forecast | 12 +- .local/bin/statusbar/sb-internet | 30 ++-- .local/bin/statusbar/sb-music | 20 +-- .local/bin/statusbar/sb-nettraf | 18 +-- .local/bin/statusbar/sb-volume | 6 +- .local/bin/sysact | 21 +-- .local/bin/texclear | 6 +- .local/bin/trash-put | 16 +- .local/bin/trash-restore | 32 ++-- .local/bin/trash/booksplit | 26 ++-- .local/bin/trash/getbib | 4 +- .local/bin/trash/noisereduce | 72 ++++----- .local/bin/trash/otp | 62 ++++---- .local/bin/trash/slider | 92 +++++------ .local/bin/trash/tag | 14 +- .local/bin/vidthumb | 1 - 59 files changed, 797 insertions(+), 721 deletions(-) diff --git a/.config/X11/startgraphical b/.config/X11/startgraphical index 32886f053..4f2e15e0c 100755 --- a/.config/X11/startgraphical +++ b/.config/X11/startgraphical @@ -1,46 +1,46 @@ #!/bin/sh if [ -r "${XDG_CONFIG_HOME:-$HOME/.config}/X11/xserverrc" ]; then - server=${XDG_CONFIG_HOME:-$HOME/.config}/X11/xserverrc + server=${XDG_CONFIG_HOME:-$HOME/.config}/X11/xserverrc elif [ -r "$HOME/.xserverrc" ]; then - server=$HOME/.xserverrc + server=$HOME/.xserverrc else - server=/etc/X11/xinit/xserverrc + server=/etc/X11/xinit/xserverrc fi if [ -r "${XDG_CONFIG_HOME:-$HOME/.config}/X11/xsession" ]; then - client=${XDG_CONFIG_HOME:-$HOME/.config}/X11/xsession + client=${XDG_CONFIG_HOME:-$HOME/.config}/X11/xsession elif [ -r "$HOME/.xsession" ]; then - client="$HOME/.xsession" + client="$HOME/.xsession" else - client=/etc/X11/xinit/xinitrc + client=/etc/X11/xinit/xinitrc fi # Automatically determine an unused $DISPLAY d=0 -while true ; do - [ -e "/tmp/.X$d-lock" ] || [ -S "/tmp/.X11-unix/X$d" ] || break - d=$((d + 1)) +while true; do + [ -e "/tmp/.X$d-lock" ] || [ -S "/tmp/.X11-unix/X$d" ] || break + d=$((d + 1)) done display=":$d" unset d if [ -n "${XAUTHORITY+x}" ]; then - XAUTHORITY=$HOME/.Xauthority - export XAUTHORITY + XAUTHORITY=$HOME/.Xauthority + export XAUTHORITY fi removelist= # check for GNU hostname -if hostname --version > /dev/null 2>&1; then - if ! hostname --version 2>&1 | grep GNU -q; then - hostname=$(hostname -f) - fi +if hostname --version >/dev/null 2>&1; then + if ! hostname --version 2>&1 | grep GNU -q; then + hostname=$(hostname -f) + fi fi if [ -z "$hostname" ]; then - hostname=$(hostname) + hostname=$(hostname) fi authdisplay=${display:-:0} @@ -48,15 +48,15 @@ authdisplay=${display:-:0} mcookie=$(/usr/bin/mcookie) if [ -z "${mcookie+x}" ]; then - echo "Couldn't create cookie" - exit 1 + echo "Couldn't create cookie" + exit 1 fi dummy=0 # create a file with auth information for the server. ':0' is a dummy. xserverauthfile=$(mktemp --tmpdir serverauth.XXXXXXXXXX) trap "rm -f '$xserverauthfile'" HUP INT QUIT ILL TRAP BUS TERM -xauth -q -f "$xserverauthfile" << EOF +xauth -q -f "$xserverauthfile" </dev/null; - if [ -n "${authcookie+x}" ]; then - xauth -q << EOF + authcookie=$(xauth list "$displayname" | sed -n "s/.*$displayname[[:space:]*].*[[:space:]*]//p") 2>/dev/null + if [ -n "${authcookie+x}" ]; then + xauth -q < /dev/null 2>&1; then - deallocvt +if command -v deallocvt >/dev/null 2>&1; then + deallocvt fi exit $retval diff --git a/.config/X11/xprofile b/.config/X11/xprofile index 34c08ebbd..d0d96c9b5 100755 --- a/.config/X11/xprofile +++ b/.config/X11/xprofile @@ -1,11 +1,11 @@ #!/bin/sh export XCURSOR_PATH="${XDG_DATA_HOME:-$HOME/.local/share}/icons" -export _JAVA_AWT_WM_NONREPARENTING=1 # Fix for Java applications in dwm -export QT_QPA_PLATFORMTHEME="gtk2" # Have QT use gtk2 theme. +export _JAVA_AWT_WM_NONREPARENTING=1 # Fix for Java applications in dwm +export QT_QPA_PLATFORMTHEME="gtk2" # Have QT use gtk2 theme. export SUDO_ASKPASS="$HOME/.local/bin/dmenupass" export VIRTUAL_ENV_DISABLE_PROMPT=1 -export MOZ_USE_XINPUT2="1" # Mozilla smooth scrolling/touchpads. -export AWT_TOOLKIT="MToolkit wmname LG3D" #May have to install wmname +export MOZ_USE_XINPUT2="1" # Mozilla smooth scrolling/touchpads. +export AWT_TOOLKIT="MToolkit wmname LG3D" #May have to install wmname export LF_ICONS="\ tw=:\ st=:\ diff --git a/.config/X11/xsession b/.config/X11/xsession index 44ea2bc2e..7ff833dc2 100755 --- a/.config/X11/xsession +++ b/.config/X11/xsession @@ -10,86 +10,86 @@ OPTIONFILE=/etc/X11/Xsession.options [ -r "${XDG_CONFIG_HOME:-$HOME/.config}/X11/xsession.d" ] && SESSIONDIR=${XDG_CONFIG_HOME:-$HOME/.config}/X11/xsession.d || SESSIONDIR=/etc/X11/Xsession.d [ -d "${XDG_DATA_HOME:-$HOME/.local/share}/xorg/" ] && ERRFILE=${XDG_DATA_HOME:-$HOME/.local/share}/xorg/xsession-errors || ERRFILE=$HOME/.xsession-errors -message () { - # pretty-print messages of arbitrary length; use xmessage if it - # is available and $DISPLAY is set - MESSAGE="$PROGNAME: $*" - echo "$MESSAGE" | fold -s -w ${COLUMNS:-80} >&2 - # if [ -n "$DISPLAY" ] && command -v xmessage > /dev/null 2>&1; then - # echo "$MESSAGE" | fold -s -w ${COLUMNS:-80} | xmessage -center -file - - # fi +message() { + # pretty-print messages of arbitrary length; use xmessage if it + # is available and $DISPLAY is set + MESSAGE="$PROGNAME: $*" + echo "$MESSAGE" | fold -s -w ${COLUMNS:-80} >&2 + # if [ -n "$DISPLAY" ] && command -v xmessage > /dev/null 2>&1; then + # echo "$MESSAGE" | fold -s -w ${COLUMNS:-80} | xmessage -center -file - + # fi } -message_nonl () { - # pretty-print messages of arbitrary length (no trailing newline); use - # xmessage if it is available and $DISPLAY is set - MESSAGE="$PROGNAME: $*" - echo -n "$MESSAGE" | fold -s -w ${COLUMNS:-80} >&2; - # if [ -n "$DISPLAY" ] && command -v xmessage > /dev/null 2>&1; then - # echo -n "$MESSAGE" | fold -s -w ${COLUMNS:-80} | xmessage -center -file - - # fi +message_nonl() { + # pretty-print messages of arbitrary length (no trailing newline); use + # xmessage if it is available and $DISPLAY is set + MESSAGE="$PROGNAME: $*" + echo -n "$MESSAGE" | fold -s -w ${COLUMNS:-80} >&2 + # if [ -n "$DISPLAY" ] && command -v xmessage > /dev/null 2>&1; then + # echo -n "$MESSAGE" | fold -s -w ${COLUMNS:-80} | xmessage -center -file - + # fi } -errormsg () { - # exit script with error - message "$*" - exit 1 +errormsg() { + # exit script with error + message "$*" + exit 1 } -internal_errormsg () { - # exit script with error; essentially a "THIS SHOULD NEVER HAPPEN" message - # One big call to message() for the sake of xmessage; if we had two then - # the user would have dismissed the error we want reported before seeing the - # request to report it. - errormsg "$*" \ - "Please report the installed version of the \"x11-common\"" \ - "package and the complete text of this error message to" \ - "." +internal_errormsg() { + # exit script with error; essentially a "THIS SHOULD NEVER HAPPEN" message + # One big call to message() for the sake of xmessage; if we had two then + # the user would have dismissed the error we want reported before seeing the + # request to report it. + errormsg "$*" \ + "Please report the installed version of the \"x11-common\"" \ + "package and the complete text of this error message to" \ + "." } OPTIONS="$( - if [ -r "$OPTIONFILE" ]; then - cat "$OPTIONFILE" - fi - if [ -d /etc/X11/Xsession.options.d ]; then - run-parts --list --regex '\.conf$' /etc/X11/Xsession.options.d | xargs -d '\n' cat - fi + if [ -r "$OPTIONFILE" ]; then + cat "$OPTIONFILE" + fi + if [ -d /etc/X11/Xsession.options.d ]; then + run-parts --list --regex '\.conf$' /etc/X11/Xsession.options.d | xargs -d '\n' cat + fi )" has_option() { - # Ensure that a later no-foo overrides an earlier foo - if [ "$(echo "$OPTIONS" | grep -Eo "^(no-)?$1\>" | tail -n 1)" = "$1" ]; then - return 0 - else - return 1 - fi + # Ensure that a later no-foo overrides an earlier foo + if [ "$(echo "$OPTIONS" | grep -Eo "^(no-)?$1\>" | tail -n 1)" = "$1" ]; then + return 0 + else + return 1 + fi } # attempt to create an error file; abort if we cannot -if (umask 077 && touch "$ERRFILE") 2> /dev/null && [ -w "$ERRFILE" ] && - [ ! -L "$ERRFILE" ]; then - chmod 600 "$ERRFILE" -elif ERRFILE=$(mktemp 2> /dev/null); then - if ! ln -sf "$ERRFILE" "${TMPDIR:=/tmp}/xsession-$USER"; then - message "warning: unable to symlink \"$TMPDIR/xsession-$USER\" to" \ - "\"$ERRFILE\"; look for session log/errors in" \ - "\"$TMPDIR/xsession-$USER\"." - fi +if (umask 077 && touch "$ERRFILE") 2>/dev/null && [ -w "$ERRFILE" ] && + [ ! -L "$ERRFILE" ]; then + chmod 600 "$ERRFILE" +elif ERRFILE=$(mktemp 2>/dev/null); then + if ! ln -sf "$ERRFILE" "${TMPDIR:=/tmp}/xsession-$USER"; then + message "warning: unable to symlink \"$TMPDIR/xsession-$USER\" to" \ + "\"$ERRFILE\"; look for session log/errors in" \ + "\"$TMPDIR/xsession-$USER\"." + fi else - errormsg "unable to create X session log/error file; aborting." + errormsg "unable to create X session log/error file; aborting." fi # truncate ERRFILE if it is too big to avoid disk usage DoS if [ "$(stat -c%s \""$ERRFILE"\")" -gt 500000 ]; then - T=$(mktemp -p "$HOME") - tail -c 500000 "$ERRFILE" > "$T" && mv -f "$T" "$ERRFILE" || rm -f "$T" + T=$(mktemp -p "$HOME") + tail -c 500000 "$ERRFILE" >"$T" && mv -f "$T" "$ERRFILE" || rm -f "$T" fi exec >>"$ERRFILE" 2>&1 # sanity check; is our session script directory present? if [ ! -d "$SESSIONDIR" ]; then - errormsg "no \"$SESSIONDIR\" directory found; aborting." + errormsg "no \"$SESSIONDIR\" directory found; aborting." fi # Attempt to create a file of non-zero length in /tmp; a full filesystem can @@ -99,19 +99,19 @@ fi # determining what went wrong. WRITE_TEST=$(mktemp) if ! echo "*" >>"$WRITE_TEST"; then - message "warning: unable to write to ${WRITE_TEST%/*}; X session may exit" \ - "with an error" + message "warning: unable to write to ${WRITE_TEST%/*}; X session may exit" \ + "with an error" fi rm -f "$WRITE_TEST" SESSIONFILES=$(run-parts --list $SESSIONDIR) if [ -n "$SESSIONFILES" ]; then - set +e - for SESSIONFILE in $SESSIONFILES; do - message "Executing $SESSIONFILE" - . $SESSIONFILE - done - set -e + set +e + for SESSIONFILE in $SESSIONFILES; do + message "Executing $SESSIONFILE" + . $SESSIONFILE + done + set -e fi if [ -f "${XDG_CONFIG_HOME:-$HOME/.config}/X11/xprofile" ]; then diff --git a/.config/X11/xsession.d/20dbus_xdg-runtime b/.config/X11/xsession.d/20dbus_xdg-runtime index 188bc77ea..a724c09c6 100644 --- a/.config/X11/xsession.d/20dbus_xdg-runtime +++ b/.config/X11/xsession.d/20dbus_xdg-runtime @@ -1,23 +1,23 @@ # vim:set ft=sh -if [ -z "$DBUS_SESSION_BUS_ADDRESS" ] && [ -n "$XDG_RUNTIME_DIR" ] && \ - [ "$XDG_RUNTIME_DIR" = "/run/user/`id -u`" ] && \ - [ -S "$XDG_RUNTIME_DIR/bus" ]; then - # We are under systemd-logind or something remarkably similar, and - # a user-session socket has already been set up. - # - # Be nice to non-libdbus, non-sd-bus implementations by using - # that as the session bus address in the environment. The check for - # XDG_RUNTIME_DIR = "/run/user/`id -u`" is because we know that - # form of the address, from systemd-logind, doesn't need escaping, - # whereas arbitrary addresses might. - export DBUS_SESSION_BUS_ADDRESS="unix:path=$XDG_RUNTIME_DIR/bus" +if [ -z "$DBUS_SESSION_BUS_ADDRESS" ] && [ -n "$XDG_RUNTIME_DIR" ] && + [ "$XDG_RUNTIME_DIR" = "/run/user/$(id -u)" ] && + [ -S "$XDG_RUNTIME_DIR/bus" ]; then + # We are under systemd-logind or something remarkably similar, and + # a user-session socket has already been set up. + # + # Be nice to non-libdbus, non-sd-bus implementations by using + # that as the session bus address in the environment. The check for + # XDG_RUNTIME_DIR = "/run/user/`id -u`" is because we know that + # form of the address, from systemd-logind, doesn't need escaping, + # whereas arbitrary addresses might. + export DBUS_SESSION_BUS_ADDRESS="unix:path=$XDG_RUNTIME_DIR/bus" fi if [ -x "/usr/bin/dbus-update-activation-environment" ]; then - # tell dbus-daemon --session (and systemd --user, if running) - # to put a minimal subset of the Xsession's environment in activated - # services' environments - dbus-update-activation-environment --verbose --systemd \ - DBUS_SESSION_BUS_ADDRESS DISPLAY XAUTHORITY + # tell dbus-daemon --session (and systemd --user, if running) + # to put a minimal subset of the Xsession's environment in activated + # services' environments + dbus-update-activation-environment --verbose --systemd \ + DBUS_SESSION_BUS_ADDRESS DISPLAY XAUTHORITY fi diff --git a/.config/X11/xsession.d/30x11-resources b/.config/X11/xsession.d/30x11-resources index 5b7bb17f4..09ceaccb1 100644 --- a/.config/X11/xsession.d/30x11-resources +++ b/.config/X11/xsession.d/30x11-resources @@ -1,5 +1,5 @@ # vim:set ft=sh if has_option allow-user-resources && [ -f "$USRRESOURCES" ]; then - xrdb -merge $USRRESOURCES + xrdb -merge $USRRESOURCES fi diff --git a/.config/X11/xsession.d/50atk-adaptor b/.config/X11/xsession.d/50atk-adaptor index af3eeea90..9f0879214 100644 --- a/.config/X11/xsession.d/50atk-adaptor +++ b/.config/X11/xsession.d/50atk-adaptor @@ -1,18 +1,16 @@ # vim:set ft=sh -add_module() -{ +add_module() { case :$GTK_MODULES: in - *:$1:*) - ;; - *) - if [ -z "$GTK_MODULES" ] - then - GTK_MODULES=$1 - else - GTK_MODULES=$GTK_MODULES:$1 - fi - ;; + *:$1:*) ;; + + *) + if [ -z "$GTK_MODULES" ]; then + GTK_MODULES=$1 + else + GTK_MODULES=$GTK_MODULES:$1 + fi + ;; esac } @@ -21,5 +19,5 @@ add_module atk-bridge export GTK_MODULES if [ -x "/usr/bin/dbus-update-activation-environment" ]; then - dbus-update-activation-environment --verbose --systemd GTK_MODULES + dbus-update-activation-environment --verbose --systemd GTK_MODULES fi diff --git a/.config/X11/xsession.d/50qt-a11y b/.config/X11/xsession.d/50qt-a11y index aae399bfc..25607b0b4 100644 --- a/.config/X11/xsession.d/50qt-a11y +++ b/.config/X11/xsession.d/50qt-a11y @@ -3,5 +3,5 @@ export QT_ACCESSIBILITY=1 if [ -x "/usr/bin/dbus-update-activation-environment" ]; then - dbus-update-activation-environment --verbose --systemd QT_ACCESSIBILITY + dbus-update-activation-environment --verbose --systemd QT_ACCESSIBILITY fi diff --git a/.config/X11/xsession.d/60gpg-agent b/.config/X11/xsession.d/60gpg-agent index 44b6504ef..c98d23a5e 100644 --- a/.config/X11/xsession.d/60gpg-agent +++ b/.config/X11/xsession.d/60gpg-agent @@ -1,7 +1,7 @@ # vim:set ft=sh if [ "${SSH_AUTH_SOCK:-0}" -ne $$ ]; then - export SSH_AUTH_SOCK="$(gpgconf --list-dirs agent-ssh-socket)" + export SSH_AUTH_SOCK="$(gpgconf --list-dirs agent-ssh-socket)" fi export GPG_TTY="$(tty)" -gpg-connect-agent updatestartuptty /bye > /dev/null +gpg-connect-agent updatestartuptty /bye >/dev/null diff --git a/.config/X11/xsession.d/90auto-start b/.config/X11/xsession.d/90auto-start index af24c1e86..ca8c2ce23 100644 --- a/.config/X11/xsession.d/90auto-start +++ b/.config/X11/xsession.d/90auto-start @@ -1,8 +1,7 @@ # vim:set ft=sh -start() -{ - pidof -s $1 || $@ >/dev/null 2>&1 & +start() { + pidof -s $1 || $@ >/dev/null 2>&1 & } start playerctld daemon diff --git a/.config/nvim/lua/plugins/config/null-ls.lua b/.config/nvim/lua/plugins/config/null-ls.lua index 6240db951..cac1e47e2 100644 --- a/.config/nvim/lua/plugins/config/null-ls.lua +++ b/.config/nvim/lua/plugins/config/null-ls.lua @@ -15,6 +15,7 @@ null_ls.setup { debug = false, sources = { formatting.black.with { extra_args = { "--fast" } }, + formatting.shfmt, -- formatting.stylua, -- diagnostics.flake8, }, diff --git a/.local/bin/compiler b/.local/bin/compiler index 3dfeae2a1..cdbafeba2 100755 --- a/.local/bin/compiler +++ b/.local/bin/compiler @@ -15,46 +15,49 @@ ext="${file##*.}" cd "$dir" || exit 1 -textype() { \ +textype() { command="pdflatex" - texroot=$(readlink -f "$(grep -Poi "^ *% *\! *tex root *= *\w+(?:\.\w*)?" "$file" | cut -d "=" -f 2 | tr -d "[:blank:]")") - [ -n "$texroot" ] && base=$texroot && echo "Compiling from TeX root: $texroot" - ( head -n5 "$file" | grep -qi 'xelatex' ) && command="xelatex" + texroot=$(readlink -f "$(grep -Poi "^ *% *\! *tex root *= *\w+(?:\.\w*)?" "$file" | cut -d "=" -f 2 | tr -d "[:blank:]")") + [ -n "$texroot" ] && base=$texroot && echo "Compiling from TeX root: $texroot" + (head -n5 "$file" | grep -qi 'xelatex') && command="xelatex" $command --output-directory="$dir" "$base" && - grep -qi addbibresource "$file" && - biber --input-directory "$dir" "$base" && - $command --output-directory="$dir" "$base" && - $command --output-directory="$dir" "$base" + grep -qi addbibresource "$file" && + biber --input-directory "$dir" "$base" && + $command --output-directory="$dir" "$base" && + $command --output-directory="$dir" "$base" } case "$ext" in - # Try to keep these cases in alphabetical order. - [0-9]) preconv "$file" | refer -PS -e | groff -mandoc -T pdf > "$base".pdf ;; - c) cc "$file" -o "$base" && "$base" ;; - cpp) g++ "$file" -o "$base" && "$base" ;; - cs) mcs "$file" && mono "$base".exe ;; - go) go run "$file" ;; - h) sudo make install ;; - # findup is a script available here: https://unix.stackexchange.com/a/35265 - java) loc=$(findup . -name gradlew); [ "$loc":w != "" ] && exec "$loc" run -q -p "$(dirname $loc)" ;; - m) octave "$file" ;; - md) if [ -x "$(command -v lowdown)" ]; then - lowdown --parse-no-intraemph "$file" -Tms | groff -mpdfmark -ms -kept -T pdf > "$base".pdf - elif [ -x "$(command -v groffdown)" ]; then - groffdown -i "$file" | groff -T pdf > "$base.pdf" - else - pandoc -t ms --highlight-style=kate -s -o "$base".pdf "$file" - fi ; ;; - mom) preconv "$file" | refer -PS -e | groff -mom -kept -T pdf > "$base".pdf ;; - ms) preconv "$file" | refer -PS -e | groff -me -ms -kept -T pdf > "$base".pdf ;; - org) emacs "$file" --batch -u "$USER" -f org-latex-export-to-pdf ;; - py) python "$file" ;; - [rR]md) Rscript -e "rmarkdown::render('$file', quiet=TRUE)" ;; - rs) cargo build ;; - sass) sassc -a "$file" "$base".css ;; - scad) openscad -o "$base".stl "$file" ;; - sent) setsid -f sent "$file" 2>/dev/null ;; - tex) textype "$file" ;; - fnl) fennel --compile "$file" > "$base.lua" ;; - *) sed -n '/^#!/s/^#!//p; q' "$file" | xargs -r -I % "$file" ;; +# Try to keep these cases in alphabetical order. +[0-9]) preconv "$file" | refer -PS -e | groff -mandoc -T pdf >"$base".pdf ;; +c) cc "$file" -o "$base" && "$base" ;; +cpp) g++ "$file" -o "$base" && "$base" ;; +cs) mcs "$file" && mono "$base".exe ;; +go) go run "$file" ;; +h) sudo make install ;; + # findup is a script available here: https://unix.stackexchange.com/a/35265 +java) + loc=$(findup . -name gradlew) + [ "$loc":w != "" ] && exec "$loc" run -q -p "$(dirname $loc)" + ;; +m) octave "$file" ;; +md) if [ -x "$(command -v lowdown)" ]; then + lowdown --parse-no-intraemph "$file" -Tms | groff -mpdfmark -ms -kept -T pdf >"$base".pdf +elif [ -x "$(command -v groffdown)" ]; then + groffdown -i "$file" | groff -T pdf >"$base.pdf" +else + pandoc -t ms --highlight-style=kate -s -o "$base".pdf "$file" +fi ;; +mom) preconv "$file" | refer -PS -e | groff -mom -kept -T pdf >"$base".pdf ;; +ms) preconv "$file" | refer -PS -e | groff -me -ms -kept -T pdf >"$base".pdf ;; +org) emacs "$file" --batch -u "$USER" -f org-latex-export-to-pdf ;; +py) python "$file" ;; +[rR]md) Rscript -e "rmarkdown::render('$file', quiet=TRUE)" ;; +rs) cargo build ;; +sass) sassc -a "$file" "$base".css ;; +scad) openscad -o "$base".stl "$file" ;; +sent) setsid -f sent "$file" 2>/dev/null ;; +tex) textype "$file" ;; +fnl) fennel --compile "$file" >"$base.lua" ;; +*) sed -n '/^#!/s/^#!//p; q' "$file" | xargs -r -I % "$file" ;; esac diff --git a/.local/bin/cron/README.md b/.local/bin/cron/README.md index fa0c35407..6525a376d 100644 --- a/.local/bin/cron/README.md +++ b/.local/bin/cron/README.md @@ -4,8 +4,11 @@ These cronjobs have components that require information about your current displ When you add them as cronjobs, I recommend you precede the command with commands as those below: -``` -export DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/$(id -u $USER)/bus; export DISPLAY=:0; . $HOME/.zprofile; then_command_goes_here -``` +$()$( + export DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/$(id -u $USER)/bus + export DISPLAY=:0 + . $HOME/.zprofile + then_command_goes_here +)$() This ensures that notifications will display, xdotool commands will function and environmental variables will work as well. diff --git a/.local/bin/cron/checkup b/.local/bin/cron/checkup index 7dac9dc9e..ac65d6b95 100755 --- a/.local/bin/cron/checkup +++ b/.local/bin/cron/checkup @@ -9,9 +9,8 @@ sudo pacman -Syyuw --noconfirm || notify-send "Error downloading updates. Check your internet connection, if pacman is already running, or run update manually to see errors." pkill -RTMIN+8 "${STATUSBAR:-dwmblocks}" -if pacman -Qu | grep -v "\[ignored\]" -then +if pacman -Qu | grep -v "\[ignored\]"; then notify-send " Repository Sync" "Updates available. Click statusbar icon () for update." else - notify-send " Repository Sync" "Sync complete. No new packages for update." + notify-send " Repository Sync" "Sync complete. No new packages for update." fi diff --git a/.local/bin/cron/crontog b/.local/bin/cron/crontog index af289513b..e82e38a3d 100755 --- a/.local/bin/cron/crontog +++ b/.local/bin/cron/crontog @@ -3,4 +3,4 @@ # Toggles all cronjobs off/on. # Stores disabled crontabs in ~/.consaved until restored. -([ -f "${XDG_CONFIG_HOME:-$HOME/.config}"/cronsaved ] && crontab - < "${XDG_CONFIG_HOME:-$HOME/.config}"/cronsaved && rm "${XDG_CONFIG_HOME:-$HOME/.config}"/cronsaved && notify-send " Cronjobs re-enabled.") || ( crontab -l > "${XDG_CONFIG_HOME:-$HOME/.config}"/cronsaved && crontab -r && notify-send " Cronjobs saved and disabled.") +([ -f "${XDG_CONFIG_HOME:-$HOME/.config}"/cronsaved ] && crontab - <"${XDG_CONFIG_HOME:-$HOME/.config}"/cronsaved && rm "${XDG_CONFIG_HOME:-$HOME/.config}"/cronsaved && notify-send " Cronjobs re-enabled.") || (crontab -l >"${XDG_CONFIG_HOME:-$HOME/.config}"/cronsaved && crontab -r && notify-send " Cronjobs saved and disabled.") diff --git a/.local/bin/cron/mailsync b/.local/bin/cron/mailsync index 2dcf38555..9f13a57b1 100755 --- a/.local/bin/cron/mailsync +++ b/.local/bin/cron/mailsync @@ -12,9 +12,15 @@ # Xorg and MacOS as well. # Run only if user logged in (prevent cron errors) -pgrep -u "${USER:=$LOGNAME}" >/dev/null || { echo "$USER not logged in; sync will not run."; exit ;} +pgrep -u "${USER:=$LOGNAME}" >/dev/null || { + echo "$USER not logged in; sync will not run." + exit +} # Run only if not already running in other instance -pgrep mbsync >/dev/null && { echo "mbsync is already running."; exit ;} +pgrep mbsync >/dev/null && { + echo "mbsync is already running." + exit +} # First, we have to get the right variables for the mbsync file, the pass # archive, notmuch and the GPG home. This is done by searching common profile @@ -25,7 +31,7 @@ pkill -RTMIN+12 dwmblocks eval "$(grep -h -- \ "^\s*\(export \)\?\(MBSYNCRC\|PASSWORD_STORE_DIR\|NOTMUCH_CONFIG\|GNUPGHOME\)=" \ - "$HOME/.profile" "$HOME/.bash_profile" "$HOME/.zprofile" "$HOME/.config/zsh/.zprofile" "$HOME/.zshenv" \ + "$HOME/.profile" "$HOME/.bash_profile" "$HOME/.zprofile" "$HOME/.config/zsh/.zprofile" "$HOME/.zshenv" \ "$HOME/.config/zsh/.zshenv" "$HOME/.bashrc" "$HOME/.zshrc" "$HOME/.config/zsh/.zshrc" \ "$HOME/.pam_environment" 2>/dev/null)" @@ -35,54 +41,53 @@ alias mbsync="mbsync -c $MBSYNCRC" # Settings are different for MacOS (Darwin) systems. case "$(uname)" in - Darwin) - notify() { osascript -e "display notification \"$2 in $1\" with title \"You've got Mail\" subtitle \"Account: $account\"" && sleep 2 ;} - ;; - *) - case "$(readlink -f /sbin/init)" in - *systemd*|*openrc*) export DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/$(id -u)/bus ;; - esac - # remember if a display server is running since `ps` doesn't always contain a display - pgrepoutput="$(pgrep -a X\(org\|wayland\))" - displays="$(echo "$pgrepoutput" | grep -wo "[0-9]*:[0-9]\+" | sort -u)" - notify() { [ -n "$pgrepoutput" ] && for x in ${displays:-0:}; do - export DISPLAY=$x - notify-send --app-name="mutt-wizard" "New mail!" "📬 $2 new mail(s) in \`$1\` account." - done ;} - ;; +Darwin) + notify() { osascript -e "display notification \"$2 in $1\" with title \"You've got Mail\" subtitle \"Account: $account\"" && sleep 2; } + ;; +*) + case "$(readlink -f /sbin/init)" in + *systemd* | *openrc*) export DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/$(id -u)/bus ;; + esac + # remember if a display server is running since `ps` doesn't always contain a display + pgrepoutput="$(pgrep -a X\(org\|wayland\))" + displays="$(echo "$pgrepoutput" | grep -wo "[0-9]*:[0-9]\+" | sort -u)" + notify() { [ -n "$pgrepoutput" ] && for x in ${displays:-0:}; do + export DISPLAY=$x + notify-send --app-name="mutt-wizard" "New mail!" "📬 $2 new mail(s) in \`$1\` account." + done; } + ;; esac # Check account for new mail. Notify if there is new content. syncandnotify() { - acc="$(echo "$account" | sed "s/.*\///")" - if [ -z "$opts" ]; then mbsync "$acc"; else mbsync "$opts" "$acc"; fi - new=$(find\ - "$HOME/.local/share/mail/$acc/INBOX/new/"\ - "$HOME/.local/share/mail/$acc/Inbox/new/"\ - "$HOME/.local/share/mail/$acc/inbox/new/"\ - "$HOME/.local/share/mail/$acc/INBOX/cur/"\ - "$HOME/.local/share/mail/$acc/Inbox/cur/"\ - "$HOME/.local/share/mail/$acc/inbox/cur/"\ - -type f -newer "${XDG_CONFIG_HOME:-$HOME/.config}/mutt/.mailsynclastrun" 2> /dev/null) - newcount=$(echo "$new" | sed '/^\s*$/d' | wc -l) - case 1 in - $((newcount > 0)) ) notify "$acc" "$newcount" ;; - esac + acc="$(echo "$account" | sed "s/.*\///")" + if [ -z "$opts" ]; then mbsync "$acc"; else mbsync "$opts" "$acc"; fi + new=$(find "$HOME/.local/share/mail/$acc/INBOX/new/" \ + "$HOME/.local/share/mail/$acc/Inbox/new/" \ + "$HOME/.local/share/mail/$acc/inbox/new/" \ + "$HOME/.local/share/mail/$acc/INBOX/cur/" \ + "$HOME/.local/share/mail/$acc/Inbox/cur/" \ + "$HOME/.local/share/mail/$acc/inbox/cur/" \ + -type f -newer "${XDG_CONFIG_HOME:-$HOME/.config}/mutt/.mailsynclastrun" 2>/dev/null) + newcount=$(echo "$new" | sed '/^\s*$/d' | wc -l) + case 1 in + $((newcount > 0))) notify "$acc" "$newcount" ;; + esac } # Sync accounts passed as argument or all. if [ "$#" -eq "0" ]; then - accounts="$(awk '/^Channel/ {print $2}' "$MBSYNCRC")" + accounts="$(awk '/^Channel/ {print $2}' "$MBSYNCRC")" else - for arg in "$@"; do - [ "${arg%${arg#?}}" = '-' ] && opts="${opts:+${opts} }${arg}" && shift 1 - done - accounts=$* + for arg in "$@"; do + [ "${arg%${arg#?}}" = '-' ] && opts="${opts:+${opts} }${arg}" && shift 1 + done + accounts=$* fi # Parallelize multiple accounts for account in $accounts; do - syncandnotify & + syncandnotify & done wait diff --git a/.local/bin/cron/newsup b/.local/bin/cron/newsup index f36301c85..225e35430 100755 --- a/.local/bin/cron/newsup +++ b/.local/bin/cron/newsup @@ -7,7 +7,7 @@ pgrep -f newsboat$ && /usr/bin/xdotool key --window "$(/usr/bin/xdotool search --name "^newsboat$")" R && exit -echo " 痢" > /tmp/newsupdate +echo " 痢" >/tmp/newsupdate pkill -RTMIN+6 "${STATUSBAR:-dwmblocks}" /usr/bin/newsboat -x reload rm -f /tmp/newsupdate diff --git a/.local/bin/daemons/remapd b/.local/bin/daemons/remapd index 31bfbffba..e885ad1ea 100755 --- a/.local/bin/daemons/remapd +++ b/.local/bin/daemons/remapd @@ -1,6 +1,6 @@ #!/bin/sh -while : ; do - dmesg -W -f kern | grep "input:" -q - sleep 1 - remaps us:dvorak +while :; do + dmesg -W -f kern | grep "input:" -q + sleep 1 + remaps us:dvorak done diff --git a/.local/bin/daemons/sbd-battery b/.local/bin/daemons/sbd-battery index 222129de2..ed4996de5 100755 --- a/.local/bin/daemons/sbd-battery +++ b/.local/bin/daemons/sbd-battery @@ -2,5 +2,5 @@ # battery status file is sent in as an argument from sb-battery while inotifywait -e modify "$1/status"; do - pkill -RTMIN+3 dwmblocks || break + pkill -RTMIN+3 dwmblocks || break done diff --git a/.local/bin/daemons/sbd-music b/.local/bin/daemons/sbd-music index e7181cda7..a8e5e7b2f 100755 --- a/.local/bin/daemons/sbd-music +++ b/.local/bin/daemons/sbd-music @@ -1,4 +1,4 @@ #!/bin/sh -while : ; do - mpc idle >/dev/null && pkill -RTMIN+11 dwmblocks || break +while :; do + mpc idle >/dev/null && pkill -RTMIN+11 dwmblocks || break done diff --git a/.local/bin/daemons/sbd-playerctl b/.local/bin/daemons/sbd-playerctl index 84887017b..a71abe37b 100755 --- a/.local/bin/daemons/sbd-playerctl +++ b/.local/bin/daemons/sbd-playerctl @@ -1,2 +1,2 @@ #!/bin/sh -playerctl status -F | (while read -r _; do pkill -RTMIN+11 dwmblocks; done;) +playerctl status -F | (while read -r _; do pkill -RTMIN+11 dwmblocks; done) diff --git a/.local/bin/displayselect b/.local/bin/displayselect index 9fd91ee00..e8d9a9d95 100755 --- a/.local/bin/displayselect +++ b/.local/bin/displayselect @@ -6,60 +6,64 @@ twoscreen() { # If multi-monitor is selected and there are two screens. - mirror=$(printf "no\\nyes" | dmenu -i -p "Mirror displays?") - # Mirror displays using native resolution of external display and a scaled - # version for the internal display - if [ "$mirror" = "yes" ]; then - external=$(echo "$screens" | dmenu -i -p "Optimize resolution for:") - internal=$(echo "$screens" | grep -v "$external") + mirror=$(printf "no\\nyes" | dmenu -i -p "Mirror displays?") + # Mirror displays using native resolution of external display and a scaled + # version for the internal display + if [ "$mirror" = "yes" ]; then + external=$(echo "$screens" | dmenu -i -p "Optimize resolution for:") + internal=$(echo "$screens" | grep -v "$external") - res_external=$(xrandr --query | sed -n "/^$external/,/\+/p" | \ - tail -n 1 | awk '{print $1}') - res_internal=$(xrandr --query | sed -n "/^$internal/,/\+/p" | \ - tail -n 1 | awk '{print $1}') + res_external=$(xrandr --query | sed -n "/^$external/,/\+/p" | + tail -n 1 | awk '{print $1}') + res_internal=$(xrandr --query | sed -n "/^$internal/,/\+/p" | + tail -n 1 | awk '{print $1}') - res_ext_x=$(echo "$res_external" | sed 's/x.*//') - res_ext_y=$(echo "$res_external" | sed 's/.*x//') - res_int_x=$(echo "$res_internal" | sed 's/x.*//') - res_int_y=$(echo "$res_internal" | sed 's/.*x//') + res_ext_x=$(echo "$res_external" | sed 's/x.*//') + res_ext_y=$(echo "$res_external" | sed 's/.*x//') + res_int_x=$(echo "$res_internal" | sed 's/x.*//') + res_int_y=$(echo "$res_internal" | sed 's/.*x//') - scale_x=$(echo "$res_ext_x / $res_int_x" | bc -l) - scale_y=$(echo "$res_ext_y / $res_int_y" | bc -l) + scale_x=$(echo "$res_ext_x / $res_int_x" | bc -l) + scale_y=$(echo "$res_ext_y / $res_int_y" | bc -l) - xrandr --output "$external" --auto --scale 1.0x1.0 \ - --output "$internal" --auto --same-as "$external" \ - --scale "$scale_x"x"$scale_y" - else + xrandr --output "$external" --auto --scale 1.0x1.0 \ + --output "$internal" --auto --same-as "$external" \ + --scale "$scale_x"x"$scale_y" + else - primary=$(echo "$screens" | dmenu -i -p "Select primary display:") - secondary=$(echo "$screens" | grep -v "$primary") - direction=$(printf "left\\nright" | dmenu -i -p "What side of $primary should $secondary be on?") - xrandr --output "$primary" --auto --scale 1.0x1.0 --output "$secondary" --"$direction"-of "$primary" --auto --scale 1.0x1.0 - fi + primary=$(echo "$screens" | dmenu -i -p "Select primary display:") + secondary=$(echo "$screens" | grep -v "$primary") + direction=$(printf "left\\nright" | dmenu -i -p "What side of $primary should $secondary be on?") + xrandr --output "$primary" --auto --scale 1.0x1.0 --output "$secondary" --"$direction"-of "$primary" --auto --scale 1.0x1.0 + fi } morescreen() { # If multi-monitor is selected and there are more than two screens. - primary=$(echo "$screens" | dmenu -i -p "Select primary display:") - secondary=$(echo "$screens" | grep -v "$primary" | dmenu -i -p "Select secondary display:") - direction=$(printf "left\\nright" | dmenu -i -p "What side of $primary should $secondary be on?") - tertiary=$(echo "$screens" | grep -v "$primary" | grep -v "$secondary" | dmenu -i -p "Select third display:") - xrandr --output "$primary" --auto --output "$secondary" --"$direction"-of "$primary" --auto --output "$tertiary" --"$(printf "left\\nright" | grep -v "$direction")"-of "$primary" --auto + primary=$(echo "$screens" | dmenu -i -p "Select primary display:") + secondary=$(echo "$screens" | grep -v "$primary" | dmenu -i -p "Select secondary display:") + direction=$(printf "left\\nright" | dmenu -i -p "What side of $primary should $secondary be on?") + tertiary=$(echo "$screens" | grep -v "$primary" | grep -v "$secondary" | dmenu -i -p "Select third display:") + xrandr --output "$primary" --auto --output "$secondary" --"$direction"-of "$primary" --auto --output "$tertiary" --"$(printf "left\\nright" | grep -v "$direction")"-of "$primary" --auto } multimon() { # Multi-monitor handler. - case "$(echo "$screens" | wc -l)" in - 2) twoscreen ;; - *) morescreen ;; - esac ;} + case "$(echo "$screens" | wc -l)" in + 2) twoscreen ;; + *) morescreen ;; + esac +} onescreen() { # If only one output available or chosen. - xrandr --output "$1" --auto --scale 1.0x1.0 $(echo "$allposs" | grep -v "\b$1" | awk '{print "--output", $1, "--off"}' | paste -sd ' ' -)"" + xrandr --output "$1" --auto --scale 1.0x1.0 $(echo "$allposs" | grep -v "\b$1" | awk '{print "--output", $1, "--off"}' | paste -sd ' ' -)"" } postrun() { # Stuff to run to clean up. - setbg # Fix background if screen size/arangement has changed. - remaps -n # Re-remap keys if keyboard added (for laptop bases) - { killall dunst ; setsid -f dunst ;} >/dev/null 2>&1 # Restart dunst to ensure proper location on screen + setbg # Fix background if screen size/arangement has changed. + remaps -n # Re-remap keys if keyboard added (for laptop bases) + { + killall dunst + setsid -f dunst + } >/dev/null 2>&1 # Restart dunst to ensure proper location on screen } # Get all possible displays @@ -70,14 +74,22 @@ screens=$(echo "$allposs" | awk '/ connected/ {print $1}') # If there's only one screen [ "$(echo "$screens" | wc -l)" -lt 2 ] && - { onescreen "$screens"; postrun; notify-send "💻 Only one screen detected." "Using it in its optimal settings..."; exit ;} + { + onescreen "$screens" + postrun + notify-send "💻 Only one screen detected." "Using it in its optimal settings..." + exit + } # Get user choice including multi-monitor and manual selection: chosen=$(printf "%s\\nmulti-monitor\\nmanual selection" "$screens" | dmenu -i -p "Select display arangement:") && -case "$chosen" in - "manual selection") arandr ; exit ;; - "multi-monitor") multimon ;; - *) onescreen "$chosen" ;; -esac + case "$chosen" in + "manual selection") + arandr + exit + ;; + "multi-monitor") multimon ;; + *) onescreen "$chosen" ;; + esac postrun diff --git a/.local/bin/dmenuhandler b/.local/bin/dmenuhandler index 0b3c71385..c19383422 100755 --- a/.local/bin/dmenuhandler +++ b/.local/bin/dmenuhandler @@ -5,17 +5,20 @@ feed="${1:-$(printf "%s" | dmenu -p 'Paste URL or file path')}" case "$(printf "copy url\\nsxiv\\nsetbg\\nPDF\\nbrowser\\nlynx\\nvim\\nmpv\\nmpv loop\\nmpv float\\nqueue download\\nqueue yt-dlp\\nqueue yt-dlp audio" | dmenu -i -p "Open it with?")" in - "copy url") echo "$feed" | xclip -selection clipboard ;; - mpv) setsid -f mpv -quiet "$feed" >/dev/null 2>&1 ;; - "mpv loop") setsid -f mpv -quiet --loop "$feed" >/dev/null 2>&1 ;; - "mpv float") setsid -f "$TERMINAL" -e mpv --geometry=+0-0 --autofit=30% --title="mpvfloat" "$feed" >/dev/null 2>&1 ;; - "queue yt-dlp") qndl "$feed" >/dev/null 2>&1 ;; - "queue yt-dlp audio") qndl "$feed" 'yt-dlp -o "%(title)s.%(ext)s" -f bestaudio --embed-metadata --restrict-filenames' ;; - "queue download") qndl "$feed" 'curl -LO' >/dev/null 2>&1 ;; - PDF) curl -sL "$feed" > "/tmp/$(echo "$feed" | sed "s|.*/||;s/%20/ /g")" && zathura "/tmp/$(echo "$feed" | sed "s|.*/||;s/%20/ /g")" >/dev/null 2>&1 ;; - sxiv) curl -sL "$feed" > "/tmp/$(echo "$feed" | sed "s|.*/||;s/%20/ /g")" && sxiv -a "/tmp/$(echo "$feed" | sed "s|.*/||;s/%20/ /g")" >/dev/null 2>&1 ;; - vim) curl -sL "$feed" > "/tmp/$(echo "$feed" | sed "s|.*/||;s/%20/ /g")" && setsid -f "$TERMINAL" -e "$EDITOR" "/tmp/$(echo "$feed" | sed "s|.*/||;s/%20/ /g")" >/dev/null 2>&1 ;; - setbg) curl -L "$feed" > $XDG_CACHE_HOME/pic ; xwallpaper --zoom $XDG_CACHE_HOME/pic >/dev/null 2>&1 ;; - browser) setsid -f "$BROWSER" "$feed" >/dev/null 2>&1 ;; - lynx) lynx "$feed" >/dev/null 2>&1 ;; +"copy url") echo "$feed" | xclip -selection clipboard ;; +mpv) setsid -f mpv -quiet "$feed" >/dev/null 2>&1 ;; +"mpv loop") setsid -f mpv -quiet --loop "$feed" >/dev/null 2>&1 ;; +"mpv float") setsid -f "$TERMINAL" -e mpv --geometry=+0-0 --autofit=30% --title="mpvfloat" "$feed" >/dev/null 2>&1 ;; +"queue yt-dlp") qndl "$feed" >/dev/null 2>&1 ;; +"queue yt-dlp audio") qndl "$feed" 'yt-dlp -o "%(title)s.%(ext)s" -f bestaudio --embed-metadata --restrict-filenames' ;; +"queue download") qndl "$feed" 'curl -LO' >/dev/null 2>&1 ;; +PDF) curl -sL "$feed" >"/tmp/$(echo "$feed" | sed "s|.*/||;s/%20/ /g")" && zathura "/tmp/$(echo "$feed" | sed "s|.*/||;s/%20/ /g")" >/dev/null 2>&1 ;; +sxiv) curl -sL "$feed" >"/tmp/$(echo "$feed" | sed "s|.*/||;s/%20/ /g")" && sxiv -a "/tmp/$(echo "$feed" | sed "s|.*/||;s/%20/ /g")" >/dev/null 2>&1 ;; +vim) curl -sL "$feed" >"/tmp/$(echo "$feed" | sed "s|.*/||;s/%20/ /g")" && setsid -f "$TERMINAL" -e "$EDITOR" "/tmp/$(echo "$feed" | sed "s|.*/||;s/%20/ /g")" >/dev/null 2>&1 ;; +setbg) + curl -L "$feed" >$XDG_CACHE_HOME/pic + xwallpaper --zoom $XDG_CACHE_HOME/pic >/dev/null 2>&1 + ;; +browser) setsid -f "$BROWSER" "$feed" >/dev/null 2>&1 ;; +lynx) lynx "$feed" >/dev/null 2>&1 ;; esac diff --git a/.local/bin/dmenumount b/.local/bin/dmenumount index 03cc60342..fb43cbdac 100755 --- a/.local/bin/dmenumount +++ b/.local/bin/dmenumount @@ -5,18 +5,18 @@ # be prompted to give a mountpoint from already existsing directories. If you # input a novel directory, it will prompt you to create that directory. -getmount() { \ +getmount() { [ -z "$chosen" ] && exit 1 - # shellcheck disable=SC2086 + # shellcheck disable=SC2086 mp="$(find $1 2>/dev/null | dmenu -i -p "Type in mount point.")" || exit 1 test -z "$mp" && exit 1 if [ ! -d "$mp" ]; then mkdiryn=$(printf "No\\nYes" | dmenu -i -p "$mp does not exist. Create it?") || exit 1 [ "$mkdiryn" = "Yes" ] && (mkdir -p "$mp" || sudo -A mkdir -p "$mp") fi - } +} -mountusb() { \ +mountusb() { chosen="$(echo "$usbdrives" | dmenu -i -p "Mount which drive?")" || exit 1 chosen="$(echo "$chosen" | awk '{print $1}')" sudo -A mount "$chosen" 2>/dev/null && notify-send "禍 USB mounting" "$chosen mounted." && exit 0 @@ -24,30 +24,35 @@ mountusb() { \ getmount "/mnt /media /mount /home -maxdepth 5 -type d $alreadymounted" partitiontype="$(lsblk -no "fstype" "$chosen")" case "$partitiontype" in - "vfat") sudo -A mount -t vfat "$chosen" "$mp" -o rw,umask=0000;; - "exfat") sudo -A mount "$chosen" "$mp" -o uid="$(id -u)",gid="$(id -g)";; - *) sudo -A mount "$chosen" "$mp"; user="$(whoami)"; ug="$(groups | awk '{print $1}')"; sudo -A chown "$user":"$ug" "$mp";; + "vfat") sudo -A mount -t vfat "$chosen" "$mp" -o rw,umask=0000 ;; + "exfat") sudo -A mount "$chosen" "$mp" -o uid="$(id -u)",gid="$(id -g)" ;; + *) + sudo -A mount "$chosen" "$mp" + user="$(whoami)" + ug="$(groups | awk '{print $1}')" + sudo -A chown "$user":"$ug" "$mp" + ;; esac && notify-send "禍 USB mounting" "$chosen mounted to $mp." || - notify-send "禍 Drive failed to mount." "Probably a permissions issue or a drive is already mounted." - } + notify-send "禍 Drive failed to mount." "Probably a permissions issue or a drive is already mounted." +} -mountandroid() { \ +mountandroid() { chosen="$(echo "$anddrives" | dmenu -i -p "Which Android device?")" || exit 1 chosen="$(echo "$chosen" | cut -d : -f 1)" getmount "$HOME -maxdepth 3 -type d" echo "OK" | dmenu -i -p "Tap Allow on your phone if it asks for permission and then press enter" || exit 1 - simple-mtpfs --device "$chosen" "$mp" && - notify-send " Android Mounting" "Android device mounted to $mp." || - notify-send " Android Failed mounting." "Probably a permissions issue or phone is already mounted" - } + simple-mtpfs --device "$chosen" "$mp" && + notify-send " Android Mounting" "Android device mounted to $mp." || + notify-send " Android Failed mounting." "Probably a permissions issue or phone is already mounted" +} -asktype() { \ +asktype() { choice="$(printf "USB\\nAndroid" | dmenu -i -p "Mount a USB drive or Android device?")" || exit 1 case $choice in - USB) mountusb ;; - Android) mountandroid ;; + USB) mountusb ;; + Android) mountandroid ;; esac - } +} anddrives=$(simple-mtpfs -l 2>/dev/null) usbdrives="$(lsblk -rpo "name,type,size,mountpoint" | grep 'part\|rom' | awk '$4==""{printf "%s (%s)\n",$1,$3}')" diff --git a/.local/bin/dmenumountcifs b/.local/bin/dmenumountcifs index 46c2b57a5..99c0e1988 100755 --- a/.local/bin/dmenumountcifs +++ b/.local/bin/dmenumountcifs @@ -13,7 +13,8 @@ share2mnt=//"$srvname".local/"$share" sharemount() { mounted=$(mount -v | grep "$share2mnt") || ([ ! -d /mnt/"$share" ] && sudo mkdir /mnt/"$share") [ -z "$mounted" ] && sudo mount -t cifs "$share2mnt" -o user=nobody,password="",noperm /mnt/"$share" && notify-send "Netshare $share mounted" && exit 0 - notify-send "Netshare $share already mounted"; exit 1 + notify-send "Netshare $share already mounted" + exit 1 } sharemount diff --git a/.local/bin/dmenurecord b/.local/bin/dmenurecord index df7501b95..407fa417d 100755 --- a/.local/bin/dmenurecord +++ b/.local/bin/dmenurecord @@ -9,10 +9,10 @@ # # If there is already a running instance, user will be prompted to end it. -updateicon() { \ - echo "$1" > /tmp/recordingicon +updateicon() { + echo "$1" >/tmp/recordingicon pkill -RTMIN+9 "${STATUSBAR:-dwmblocks}" - } +} killrecording() { recpid="$(cat /tmp/recordingpid)" @@ -25,99 +25,100 @@ killrecording() { sleep 3 kill -9 "$recpid" exit - } +} -screencast() { \ +screencast() { ffmpeg -y \ - -f x11grab \ - -framerate 60 \ - -s "$(xdpyinfo | awk '/dimensions/ {print $2;}')" \ - -i "$DISPLAY" \ - -f alsa -i default \ - -r 30 \ - -c:v h264 -crf 0 -preset ultrafast -c:a aac \ - "$HOME/screencast-$(date '+%y%m%d-%H%M-%S').mp4" & - echo $! > /tmp/recordingpid + -f x11grab \ + -framerate 60 \ + -s "$(xdpyinfo | awk '/dimensions/ {print $2;}')" \ + -i "$DISPLAY" \ + -f alsa -i default \ + -r 30 \ + -c:v h264 -crf 0 -preset ultrafast -c:a aac \ + "$HOME/screencast-$(date '+%y%m%d-%H%M-%S').mp4" & + echo $! >/tmp/recordingpid updateicon "ﲠ" - } +} -video() { ffmpeg \ - -f x11grab \ - -s "$(xdpyinfo | awk '/dimensions/ {print $2;}')" \ - -i "$DISPLAY" \ - -c:v libx264 -qp 0 -r 30 \ - "$HOME/video-$(date '+%y%m%d-%H%M-%S').mkv" & - echo $! > /tmp/recordingpid - updateicon "ﲣ" - } - -webcamhidef() { ffmpeg \ - -f v4l2 \ - -i /dev/video0 \ - -video_size 1920x1080 \ - "$HOME/webcam-$(date '+%y%m%d-%H%M-%S').mkv" & - echo $! > /tmp/recordingpid - updateicon "" - } - -webcam() { ffmpeg \ - -f v4l2 \ - -i /dev/video0 \ - -video_size 640x480 \ - "$HOME/webcam-$(date '+%y%m%d-%H%M-%S').mkv" & - echo $! > /tmp/recordingpid - updateicon "" - } - - -audio() { \ +video() { ffmpeg \ - -f alsa -i default \ - -c:a flac \ - "$HOME/audio-$(date '+%y%m%d-%H%M-%S').flac" & - echo $! > /tmp/recordingpid - updateicon "" - } + -f x11grab \ + -s "$(xdpyinfo | awk '/dimensions/ {print $2;}')" \ + -i "$DISPLAY" \ + -c:v libx264 -qp 0 -r 30 \ + "$HOME/video-$(date '+%y%m%d-%H%M-%S').mkv" & + echo $! >/tmp/recordingpid + updateicon "ﲣ" +} -askrecording() { \ +webcamhidef() { + ffmpeg \ + -f v4l2 \ + -i /dev/video0 \ + -video_size 1920x1080 \ + "$HOME/webcam-$(date '+%y%m%d-%H%M-%S').mkv" & + echo $! >/tmp/recordingpid + updateicon "" +} + +webcam() { + ffmpeg \ + -f v4l2 \ + -i /dev/video0 \ + -video_size 640x480 \ + "$HOME/webcam-$(date '+%y%m%d-%H%M-%S').mkv" & + echo $! >/tmp/recordingpid + updateicon "" +} + +audio() { + ffmpeg \ + -f alsa -i default \ + -c:a flac \ + "$HOME/audio-$(date '+%y%m%d-%H%M-%S').flac" & + echo $! >/tmp/recordingpid + updateicon "" +} + +askrecording() { choice=$(printf "screencast\\nvideo\\nvideo selected\\naudio\\nwebcam\\nwebcam (hi-def)" | dmenu -i -p "Select recording style:") case "$choice" in - screencast) screencast;; - audio) audio;; - video) video;; - *selected) videoselected;; - webcam) webcam;; - "webcam (hi-def)") webcamhidef;; + screencast) screencast ;; + audio) audio ;; + video) video ;; + *selected) videoselected ;; + webcam) webcam ;; + "webcam (hi-def)") webcamhidef ;; esac - } +} -asktoend() { \ +asktoend() { response=$(printf "No\\nYes" | dmenu -i -p "Recording still active. End recording?") && - [ "$response" = "Yes" ] && killrecording - } + [ "$response" = "Yes" ] && killrecording +} -videoselected() -{ - slop -f "%x %y %w %h" > /tmp/slop - read -r X Y W H < /tmp/slop +videoselected() { + slop -f "%x %y %w %h" >/tmp/slop + read -r X Y W H /tmp/recordingpid + -f x11grab \ + -framerate 60 \ + -video_size "$W"x"$H" \ + -i :0.0+"$X,$Y" \ + -c:v libx264 -qp 0 -r 30 \ + "$HOME/box-$(date '+%y%m%d-%H%M-%S').mkv" & + echo $! >/tmp/recordingpid updateicon "ﲣ" } case "$1" in - screencast) screencast;; - audio) audio;; - video) video;; - *selected) videoselected;; - kill) killrecording;; - *) ([ -f /tmp/recordingpid ] && asktoend && exit) || askrecording;; +screencast) screencast ;; +audio) audio ;; +video) video ;; +*selected) videoselected ;; +kill) killrecording ;; +*) ([ -f /tmp/recordingpid ] && asktoend && exit) || askrecording ;; esac diff --git a/.local/bin/dmenuumount b/.local/bin/dmenuumount index 5ffe8a692..20e306a16 100755 --- a/.local/bin/dmenuumount +++ b/.local/bin/dmenuumount @@ -4,22 +4,25 @@ # Provides you with mounted partitions, select one to unmount. # Drives mounted at /, /boot and /home will not be options to unmount. -drives="$(lsblk -nrpo "name,type,size,mountpoint,label" | awk -F':' '{gsub(/ /,":")}$4!~/\/boot|\/efi|\/home$|SWAP/&&length($4)>1{printf "%s (%s) %s\n",$4,$3,$5}'; awk '/simple-mtpfs/ { print "", $2; }' /etc/mtab)" +drives="$( + lsblk -nrpo "name,type,size,mountpoint,label" | awk -F':' '{gsub(/ /,":")}$4!~/\/boot|\/efi|\/home$|SWAP/&&length($4)>1{printf "%s (%s) %s\n",$4,$3,$5}' + awk '/simple-mtpfs/ { print "", $2; }' /etc/mtab +)" chosen="$(echo "$drives" | dmenu -i -p "Unmount which drive?")" || exit 1 case "$chosen" in - *) - chosen="${chosen#📱 }" - sudo -A umount -l "$chosen" - ;; - *) - chosen="${chosen% (*}" - sudo -A umount -l "$chosen" - ;; +*) + chosen="${chosen#📱 }" + sudo -A umount -l "$chosen" + ;; +*) + chosen="${chosen% (*}" + sudo -A umount -l "$chosen" + ;; esac && notify-send "禍 Drive unmounted." "$chosen successfully unmounted." || notify-send "禍 Drive failed to unmount." "Possibly a permissions or I/O issue." - sudo -A umount "$chosen" && notify-send "禍 USB unmounting" "$chosen unmounted." +sudo -A umount "$chosen" && notify-send "禍 USB unmounting" "$chosen unmounted." - sudo -A umount -l "$chosen" && notify-send " Android unmounting" "$chosen unmounted." +sudo -A umount -l "$chosen" && notify-send " Android unmounting" "$chosen unmounted." diff --git a/.local/bin/findup b/.local/bin/findup index 978c7eb97..af2da49c2 100755 --- a/.local/bin/findup +++ b/.local/bin/findup @@ -2,10 +2,8 @@ set -e path="$1" shift 1 -while [[ $path != / ]]; -do - find "$path" -maxdepth 1 -mindepth 1 "$@" - # Note: if you want to ignore symlinks, use "$(realpath -s "$path"/..)" - path="$(readlink -f "$path"/..)" +while [[ $path != / ]]; do + find "$path" -maxdepth 1 -mindepth 1 "$@" + # Note: if you want to ignore symlinks, use "$(realpath -s "$path"/..)" + path="$(readlink -f "$path"/..)" done - diff --git a/.local/bin/linkhandler b/.local/bin/linkhandler index 8a2338e8b..61ee6e903 100755 --- a/.local/bin/linkhandler +++ b/.local/bin/linkhandler @@ -13,15 +13,19 @@ else fi case "$url" in - *mkv|*webm|*mp4|*youtube.com/watch*|*youtube.com/playlist*|*youtube.com/shorts*|*youtu.be*|*hooktube.com*|*bitchute.com*|*videos.lukesmith.xyz*|*odysee.com*) - setsid -f mpv -quiet "$url" >/dev/null 2>&1 ;; - *png|*jpg|*jpe|*jpeg|*gif) - curl -sL "$url" > "/tmp/$(echo "$url" | sed "s/.*\///;s/%20/ /g")" && sxiv -a "/tmp/$(echo "$url" | sed "s/.*\///;s/%20/ /g")" >/dev/null 2>&1 & ;; - *pdf|*cbz|*cbr) - curl -sL "$url" > "/tmp/$(echo "$url" | sed "s/.*\///;s/%20/ /g")" && zathura "/tmp/$(echo "$url" | sed "s/.*\///;s/%20/ /g")" >/dev/null 2>&1 & ;; - *mp3|*flac|*opus|*mp3?source*) - qndl "$url" 'curl -LO' >/dev/null 2>&1 ;; - *) - [ -f "$url" ] && setsid -f "$TERMINAL" -e "$EDITOR" "$url" >/dev/null 2>&1 || setsid -f "$BROWSER" "$url" >/dev/null 2>&1 +*mkv | *webm | *mp4 | *youtube.com/watch* | *youtube.com/playlist* | *youtube.com/shorts* | *youtu.be* | *hooktube.com* | *bitchute.com* | *videos.lukesmith.xyz* | *odysee.com*) + setsid -f mpv -quiet "$url" >/dev/null 2>&1 + ;; +*png | *jpg | *jpe | *jpeg | *gif) + curl -sL "$url" >"/tmp/$(echo "$url" | sed "s/.*\///;s/%20/ /g")" && sxiv -a "/tmp/$(echo "$url" | sed "s/.*\///;s/%20/ /g")" >/dev/null 2>&1 & + ;; +*pdf | *cbz | *cbr) + curl -sL "$url" >"/tmp/$(echo "$url" | sed "s/.*\///;s/%20/ /g")" && zathura "/tmp/$(echo "$url" | sed "s/.*\///;s/%20/ /g")" >/dev/null 2>&1 & + ;; +*mp3 | *flac | *opus | *mp3?source*) + qndl "$url" 'curl -LO' >/dev/null 2>&1 + ;; +*) + [ -f "$url" ] && setsid -f "$TERMINAL" -e "$EDITOR" "$url" >/dev/null 2>&1 || setsid -f "$BROWSER" "$url" >/dev/null 2>&1 + ;; esac - diff --git a/.local/bin/maimpick b/.local/bin/maimpick index 957842e41..bf1972ea7 100755 --- a/.local/bin/maimpick +++ b/.local/bin/maimpick @@ -9,11 +9,10 @@ output="$(date '+%y%m%d-%H%M-%S').png" xclip_cmd="xclip -sel clip -t image/png" case "$(printf "a selected area\\ncurrent window\\nfull screen\\na selected area (copy)\\ncurrent window (copy)\\nfull screen (copy)" | dmenu -l 6 -i -p "Screenshot which area?")" in - "a selected area") maim -s pic-selected-"${output}" ;; - "current window") maim -q -d 0.2 -i "$(xdotool getactivewindow)" pic-window-"${output}" ;; - "full screen") maim -q -d 0.2 pic-full-"${output}" ;; - "a selected area (copy)") maim -s | ${xclip_cmd} ;; - "current window (copy)") maim -q -d 0.2 -i "$(xdotool getactivewindow)" | ${xclip_cmd} ;; - "full screen (copy)") maim -q -d 0.2 | ${xclip_cmd} ;; +"a selected area") maim -s pic-selected-"${output}" ;; +"current window") maim -q -d 0.2 -i "$(xdotool getactivewindow)" pic-window-"${output}" ;; +"full screen") maim -q -d 0.2 pic-full-"${output}" ;; +"a selected area (copy)") maim -s | ${xclip_cmd} ;; +"current window (copy)") maim -q -d 0.2 -i "$(xdotool getactivewindow)" | ${xclip_cmd} ;; +"full screen (copy)") maim -q -d 0.2 | ${xclip_cmd} ;; esac - diff --git a/.local/bin/opout b/.local/bin/opout index faf657535..17e8f787b 100755 --- a/.local/bin/opout +++ b/.local/bin/opout @@ -7,7 +7,7 @@ basename="${1%.*}" case "${*}" in - *.tex|*.m[dse]|*.[rR]md|*.mom|*.[0-9]) setsid -f xdg-open "$basename".pdf >/dev/null 2>&1 ;; - *.html) setsid -f "$BROWSER" "$basename".html >/dev/null 2>&1 ;; - *.sent) setsid -f sent "$1" >/dev/null 2>&1 ;; +*.tex | *.m[dse] | *.[rR]md | *.mom | *.[0-9]) setsid -f xdg-open "$basename".pdf >/dev/null 2>&1 ;; +*.html) setsid -f "$BROWSER" "$basename".html >/dev/null 2>&1 ;; +*.sent) setsid -f sent "$1" >/dev/null 2>&1 ;; esac diff --git a/.local/bin/pamixer-notify b/.local/bin/pamixer-notify index 39bba6618..0b81b2138 100755 --- a/.local/bin/pamixer-notify +++ b/.local/bin/pamixer-notify @@ -1,18 +1,18 @@ -#!/bin/sh +#!/bin/sh # Arbitrary but unique message tag msgTag="volume" # Change the volume using alsa(might differ if you use pulseaudio) -pamixer "$@" > /dev/null +pamixer "$@" >/dev/null # Query amixer for the current volume and whether or not the speaker is muted volume="$(pamixer --get-volume)" if [ "$volume" -gt "100" ]; then - urgency="critical" + urgency="critical" else - urgency="low" + urgency="low" fi if [ "$volume" -gt "70" ]; then @@ -25,10 +25,10 @@ fi mute="$(pamixer --get-mute)" if [ "$volume" = 0 ] || [ "$mute" = "true" ]; then - notify-send -a "changeVolume" -i "audio-volume-muted" -u $urgency -h string:x-dunst-stack-tag:$msgTag "Volume muted" + notify-send -a "changeVolume" -i "audio-volume-muted" -u $urgency -h string:x-dunst-stack-tag:$msgTag "Volume muted" else - notify-send -a "changeVolume" -i "$icon" -u $urgency -h string:x-dunst-stack-tag:$msgTag \ - -h int:value:"$volume" "Volume: ${volume}%" + notify-send -a "changeVolume" -i "$icon" -u $urgency -h string:x-dunst-stack-tag:$msgTag \ + -h int:value:"$volume" "Volume: ${volume}%" fi # Play the volume changed sound diff --git a/.local/bin/pauseallmpv b/.local/bin/pauseallmpv index d69a41461..442cdb365 100755 --- a/.local/bin/pauseallmpv +++ b/.local/bin/pauseallmpv @@ -6,5 +6,5 @@ # (with other things) by default and is used in some other places. for i in $(ls /tmp/mpvSockets/*); do - echo '{ "command": ["set_property", "pause", true] }' | socat - "$i"; + echo '{ "command": ["set_property", "pause", true] }' | socat - "$i" done diff --git a/.local/bin/prompt b/.local/bin/prompt index 666434fbe..ada2c47c5 100755 --- a/.local/bin/prompt +++ b/.local/bin/prompt @@ -5,4 +5,4 @@ # For example: # `./prompt "Do you want to shutdown?" "shutdown -h now"` -[ "$(printf "No\\nYes" | dmenu -i -p "$1" -nb darkred -sb red -sf white -nf gray )" = "Yes" ] && $2 +[ "$(printf "No\\nYes" | dmenu -i -p "$1" -nb darkred -sb red -sf white -nf gray)" = "Yes" ] && $2 diff --git a/.local/bin/queueandnotify b/.local/bin/queueandnotify index 1c3025c65..03dea9c2d 100755 --- a/.local/bin/queueandnotify +++ b/.local/bin/queueandnotify @@ -9,6 +9,6 @@ while read -r line; do [ -z "$line" ] && continue url="${line%%[ ]*}" qndl "$url" "curl -LO" -done < "$queuefile" +done <"$queuefile" -echo > "$queuefile" +echo >"$queuefile" diff --git a/.local/bin/remaps b/.local/bin/remaps index d2ebd9338..d58ebca97 100755 --- a/.local/bin/remaps +++ b/.local/bin/remaps @@ -1,35 +1,35 @@ #!/bin/sh index() { - echo "$groups" | cut -d ' ' -f "$1" + echo "$groups" | cut -d ' ' -f "$1" } if [ "$1" = "-n" ]; then - newgroup="$(setxkbmap -query | grep -oP '(layout|variant):\s*\K\w+' | sed ':a;N;s/\n/:/')" -elif [ "$1" = "" ]; -then - groups="us:dvorak de:nodeadkeys" - current="$(setxkbmap -query | grep -oP '(layout|variant):\s*\K\w+' | sed ':a;N;s/\n/:/')" - i=1 - while [ ! "$found" ]; do - group=$(index $i) - if [ "$group" = "$current" ]; then - newgroup=$(index $((i+1))) - [ -z "$newgroup" ] && newgroup=$(index 1) - found=true - elif [ -z "$group" ]; then - newgroup=$(index 1) - found=true - fi - i=$((i+1)) - done + newgroup="$(setxkbmap -query | grep -oP '(layout|variant):\s*\K\w+' | sed ':a;N;s/\n/:/')" +elif [ "$1" = "" ]; then + groups="us:dvorak de:nodeadkeys" + current="$(setxkbmap -query | grep -oP '(layout|variant):\s*\K\w+' | sed ':a;N;s/\n/:/')" + i=1 + while [ ! "$found" ]; do + group=$(index $i) + if [ "$group" = "$current" ]; then + newgroup=$(index $((i + 1))) + [ -z "$newgroup" ] && newgroup=$(index 1) + found=true + elif [ -z "$group" ]; then + newgroup=$(index 1) + found=true + fi + i=$((i + 1)) + done else - newgroup="$1" + newgroup="$1" fi setxkbmap -layout "$(echo "$newgroup" | cut -d ':' -f1)" -variant "$(echo "$newgroup" | cut -d ':' -f2)" -option caps:super -option terminate:ctrl_alt_bksp 1>/dev/null 2>&1 || echo "Unkown keyboard layout" xset r rate 300 50 -killall xcape 2>/dev/null ; xcape -e 'Super_L=Escape' +killall xcape 2>/dev/null +xcape -e 'Super_L=Escape' xset -q | grep "Caps Lock:\s*on" && xdotool key Caps_Lock sleep 0.03 pkill -RTMIN+15 dwmblocks diff --git a/.local/bin/remaps-no-change b/.local/bin/remaps-no-change index 05f3ad82b..f7f19b527 100755 --- a/.local/bin/remaps-no-change +++ b/.local/bin/remaps-no-change @@ -4,7 +4,8 @@ current="$(setxkbmap -query | grep -oP '(layout|variant):\s*\K\w+' | sed ':a;N;s setxkbmap -layout "$(echo "$current" | cut -d ':' -f1)" -variant "$(echo "$current" | cut -d ':' -f2)" -option caps:super -option terminate:ctrl_alt_bksp xset r rate 300 50 -killall xcape 2>/dev/null ; xcape -e 'Super_L=Escape' +killall xcape 2>/dev/null +xcape -e 'Super_L=Escape' xset -q | grep "Caps Lock:\s*on" && xdotool key Caps_Lock sleep 0.03 pkill -RTMIN+15 dwmblocks diff --git a/.local/bin/rssadd b/.local/bin/rssadd index 910fca31b..6fa871888 100755 --- a/.local/bin/rssadd +++ b/.local/bin/rssadd @@ -1,6 +1,6 @@ #!/bin/sh -if echo "$1" | grep -q "https*://\S\+\.[A-Za-z]\+\S*" ; then +if echo "$1" | grep -q "https*://\S\+\.[A-Za-z]\+\S*"; then url="$1" else url="$(grep -Eom1 '<[^>]+(rel="self"|application/[a-z]+\+xml)[^>]+>' "$1" | @@ -14,5 +14,5 @@ RSSFILE="${XDG_CONFIG_HOME:-$HOME/.config}/newsboat/urls" if awk '{print $1}' "$RSSFILE" | grep "^$url$" >/dev/null; then notify-send "You already have this RSS feed." else - echo "$url" >> "$RSSFILE" && notify-send "RSS feed added." + echo "$url" >>"$RSSFILE" && notify-send "RSS feed added." fi diff --git a/.local/bin/samedir b/.local/bin/samedir index a0ff84c2d..c02cc5751 100755 --- a/.local/bin/samedir +++ b/.local/bin/samedir @@ -10,8 +10,8 @@ for PID in $PIDlist; do cwd=$(readlink /proc/"$PID"/cwd) # zsh and lf won't be ignored even if it shows ~ or / case "$cmdline" in - 'lf -server') continue ;; - "${SHELL##*/}"|'lf'|'lf '*) break ;; + 'lf -server') continue ;; + "${SHELL##*/}" | 'lf' | 'lf '*) break ;; esac # git (and its sub-processes) will show the root of a repository instead of the actual cwd, so they're ignored [ "$process_group_leader" = 'git' ] || [ ! -d "$cwd" ] && continue diff --git a/.local/bin/setbg b/.local/bin/setbg index 43026f7fa..83070327d 100755 --- a/.local/bin/setbg +++ b/.local/bin/setbg @@ -8,10 +8,13 @@ bgloc="${XDG_DATA_HOME:-$HOME/.local/share/}/bg" trueloc="$(readlink -f "$1")" && -case "$(file --mime-type -b "$trueloc")" in - image/* ) ln -sf "$(readlink -f "$1")" "$bgloc" && notify-send -i "$bgloc" "Changing wallpaper..." ;; - inode/directory ) ln -sf "$(find "$trueloc" -iregex '.*.\(jpg\|jpeg\|png\|gif\)' -type f | shuf -n 1)" "$bgloc" && notify-send -i "$bgloc" "Random Wallpaper chosen." ;; - *) notify-send "Error" "Not a valid image." ; exit 1;; -esac + case "$(file --mime-type -b "$trueloc")" in + image/*) ln -sf "$(readlink -f "$1")" "$bgloc" && notify-send -i "$bgloc" "Changing wallpaper..." ;; + inode/directory) ln -sf "$(find "$trueloc" -iregex '.*.\(jpg\|jpeg\|png\|gif\)' -type f | shuf -n 1)" "$bgloc" && notify-send -i "$bgloc" "Random Wallpaper chosen." ;; + *) + notify-send "Error" "Not a valid image." + exit 1 + ;; + esac xwallpaper --zoom "$bgloc" diff --git a/.local/bin/shortcuts b/.local/bin/shortcuts index e5323cdd7..be4d2d6c5 100755 --- a/.local/bin/shortcuts +++ b/.local/bin/shortcuts @@ -12,7 +12,7 @@ lf_shortcuts="${XDG_CONFIG_HOME:-$HOME/.config}/lf/shortcutrc" # Remove, prepare files rm -f "$shell_shortcuts" "$lf_files" "$lf_dirs" "$lf_shortcuts" "$zsh_named_dirs" 2>/dev/null -printf "# vim: filetype=sh\\nalias " > "$shell_shortcuts" +printf "# vim: filetype=sh\\nalias " >"$shell_shortcuts" # Format the `directories` file in the correct syntax and sent it to all three configs. eval "echo \"$(cat "$bmdirs")\"" | awk "!/^\s*#/ && !/^\s*\$/ {gsub(\"\\\s*#.*$\",\"\"); diff --git a/.local/bin/statusbar/sb-aptpackages b/.local/bin/statusbar/sb-aptpackages index 6b8b5820d..1e63a8ceb 100755 --- a/.local/bin/statusbar/sb-aptpackages +++ b/.local/bin/statusbar/sb-aptpackages @@ -1,15 +1,15 @@ #!/bin/sh -vals=$(aptitude full-upgrade --simulate --assume-yes |\ - grep -m1 '^[0-9]\+ packages upgraded,' |\ - tr -cd '0-9 ' |\ - tr ' ' '\n' |\ - grep '[0-9]\+' |\ - xargs echo) +vals=$(aptitude full-upgrade --simulate --assume-yes | + grep -m1 '^[0-9]\+ packages upgraded,' | + tr -cd '0-9 ' | + tr ' ' '\n' | + grep '[0-9]\+' | + xargs echo) print=" " for i in $vals; do - [ $i != 0 ] && icon="\033[11m\033[10m" - print="$print$i/" + [ $i != 0 ] && icon="\033[11m\033[10m" + print="$print$i/" done [ -n "$icon" ] && printf "$icon " && echo $print | sed 's/\/$//' diff --git a/.local/bin/statusbar/sb-battery b/.local/bin/statusbar/sb-battery index b0fcb186e..1ad0ace63 100755 --- a/.local/bin/statusbar/sb-battery +++ b/.local/bin/statusbar/sb-battery @@ -6,41 +6,64 @@ green="\033[32m" white="\033[37m" reset="\033[0m" for battery in /sys/class/power_supply/BAT?*; do - pidof -x sbd-battery >/dev/null 2>&1 || sbd-battery "$battery" >/dev/null 2>&1 & + pidof -x sbd-battery >/dev/null 2>&1 || sbd-battery "$battery" >/dev/null 2>&1 & [ -n "${capacity+x}" ] && printf " " capacity="$(cat "$battery/capacity" 2>&1)" case "$(cat "$battery/status" 2>&1)" in - "Full") icon=""; color="$green" ;; - "Charging") icon=""; color="$cyan" ;; - "Not charging") icon=""; color="$white" ;; - "Unknown") icon=""; color="$orange" ;; - "Discharging") - if [ "$capacity" -le 10 ]; then - icon=""; color="$red" - elif [ "$capacity" -le 20 ]; then - icon=""; color="$red" - elif [ "$capacity" -le 30 ]; then - icon=""; color="$white" - elif [ "$capacity" -le 40 ]; then - icon=""; color="$white" - elif [ "$capacity" -le 50 ]; then - icon=""; color="$white" - elif [ "$capacity" -le 60 ]; then - icon=""; color="$white" - elif [ "$capacity" -le 70 ]; then - icon=""; color="$white" - elif [ "$capacity" -le 80 ]; then - icon=""; color="$white" - elif [ "$capacity" -le 90 ]; then - icon=""; color="$white" - elif [ "$capacity" -le 95 ]; then - icon=""; color="$white" - else - icon=""; color="$white" - fi - - ;; - *) exit 1 ;; + "Full") + icon="" + color="$green" + ;; + "Charging") + icon="" + color="$cyan" + ;; + "Not charging") + icon="" + color="$white" + ;; + "Unknown") + icon="" + color="$orange" + ;; + "Discharging") + if [ "$capacity" -le 10 ]; then + icon="" + color="$red" + elif [ "$capacity" -le 20 ]; then + icon="" + color="$red" + elif [ "$capacity" -le 30 ]; then + icon="" + color="$white" + elif [ "$capacity" -le 40 ]; then + icon="" + color="$white" + elif [ "$capacity" -le 50 ]; then + icon="" + color="$white" + elif [ "$capacity" -le 60 ]; then + icon="" + color="$white" + elif [ "$capacity" -le 70 ]; then + icon="" + color="$white" + elif [ "$capacity" -le 80 ]; then + icon="" + color="$white" + elif [ "$capacity" -le 90 ]; then + icon="" + color="$white" + elif [ "$capacity" -le 95 ]; then + icon="" + color="$white" + else + icon="" + color="$white" + fi + + ;; + *) exit 1 ;; esac - printf "$color%s$reset %d" "$icon" "$capacity"; + printf "$color%s$reset %d" "$icon" "$capacity" done && printf "\\n" diff --git a/.local/bin/statusbar/sb-cpubars b/.local/bin/statusbar/sb-cpubars index ac45f74c7..54c2676b5 100755 --- a/.local/bin/statusbar/sb-cpubars +++ b/.local/bin/statusbar/sb-cpubars @@ -1,7 +1,7 @@ #!/bin/sh cache=/tmp/cpubarscache stats=$(awk '/cpu[0-9]+/ {printf "%d %d %d\n", substr($1,4), ($2 + $3 + $4 + $5), $5 }' /proc/stat) -[ ! -f $cache ] && echo "$stats" > "$cache" +[ ! -f $cache ] && echo "$stats" >"$cache" old=$(cat "$cache") printf "\033[11m﬙\033[10m " echo "$stats" | while read -r row; do @@ -12,14 +12,15 @@ echo "$stats" | while read -r row; do case "$(echo "$old" | awk '{if ($1 == id) printf "%d\n", (1 - (idle - $3) / (total - $2))*100 /12.5}' \ id="$id" total="$total" idle="$idle")" in - "0") printf "\033[32m▁";; - "1") printf "\033[32m▂";; - "2") printf "\033[32m▃";; - "3") printf "\033[33m▄";; - "4") printf "\033[33m▅";; - "5") printf "\033[33m▆";; - "6"|"7"|"8") printf "\033[31m▇";; + "0") printf "\033[32m▁" ;; + "1") printf "\033[32m▂" ;; + "2") printf "\033[32m▃" ;; + "3") printf "\033[33m▄" ;; + "4") printf "\033[33m▅" ;; + "5") printf "\033[33m▆" ;; + "6" | "7" | "8") printf "\033[31m▇" ;; esac -done; printf "\033[0m\n" -echo "$stats" > "$cache" +done +printf "\033[0m\n" +echo "$stats" >"$cache" diff --git a/.local/bin/statusbar/sb-forecast b/.local/bin/statusbar/sb-forecast index 87726a852..f698e076f 100755 --- a/.local/bin/statusbar/sb-forecast +++ b/.local/bin/statusbar/sb-forecast @@ -12,7 +12,7 @@ url="wttr.in/Karlsruhe" opt="?F" emojiopt="?format=1" convertemoji() { -sed -i ' + sed -i ' s/☀️// s/☁️// s/⛅️// @@ -26,11 +26,11 @@ s/🌩// s/🌫// ' "$emojifile" } -getforecast() { curl -sf "$url$opt" > "$weatherfile" && curl -sf "$url$emojiopt" > "$emojifile" || exit 1 ;} -showweather() { - emoji="$(printf "\033[12m%s\033[10m" "$(cut -d ' ' -f 1 "$emojifile")")" - sed '16q;d' "$weatherfile" | grep -wo "[0-9]*%" | sort -rn | sed "s/^/$emoji /g;1q" | tr -d '\n' - sed '13q;d' "$weatherfile" | grep -o "m\\([-+]\\)*[0-9]\\+" | sed 's/+//g' | sort -n -t 'm' -k 2n | sed -e 1b -e '$!d' | tr '\n|m' ' ' | awk '{print " \033[34m\033[0m " $1 "°","\033[31m\033[0m " $2 "°"}'; +getforecast() { curl -sf "$url$opt" >"$weatherfile" && curl -sf "$url$emojiopt" >"$emojifile" || exit 1; } +showweather() { + emoji="$(printf "\033[12m%s\033[10m" "$(cut -d ' ' -f 1 "$emojifile")")" + sed '16q;d' "$weatherfile" | grep -wo "[0-9]*%" | sort -rn | sed "s/^/$emoji /g;1q" | tr -d '\n' + sed '13q;d' "$weatherfile" | grep -o "m\\([-+]\\)*[0-9]\\+" | sed 's/+//g' | sort -n -t 'm' -k 2n | sed -e 1b -e '$!d' | tr '\n|m' ' ' | awk '{print " \033[34m\033[0m " $1 "°","\033[31m\033[0m " $2 "°"}' } getforecast && convertemoji showweather diff --git a/.local/bin/statusbar/sb-internet b/.local/bin/statusbar/sb-internet index 7a5abf6f5..f1838fe31 100755 --- a/.local/bin/statusbar/sb-internet +++ b/.local/bin/statusbar/sb-internet @@ -2,27 +2,27 @@ shift="" if ls /sys/class/net/w*/operstate 1>/dev/null 2>&1; then - for w in /sys/class/net/w*/; do - percent="$(cat /proc/net/wireless | grep "$(basename "$(dirname $w/operstate)")" | tr -s ' ' | cut -d ' ' -f3 | tr -dc "[:digit:]")" - grep -vxq '0x1003' "$w/flags" && wifi_icon="" || wifi_icon="$(sed "s/up/直/;s/down/睊/" $w/operstate | tr -d "[:space:]")" - printf "$shift\033[11m%s\033[10m %s" "$wifi_icon" "$percent" - shift=" " - done + for w in /sys/class/net/w*/; do + percent="$(cat /proc/net/wireless | grep "$(basename "$(dirname $w/operstate)")" | tr -s ' ' | cut -d ' ' -f3 | tr -dc "[:digit:]")" + grep -vxq '0x1003' "$w/flags" && wifi_icon="" || wifi_icon="$(sed "s/up/直/;s/down/睊/" $w/operstate | tr -d "[:space:]")" + printf "$shift\033[11m%s\033[10m %s" "$wifi_icon" "$percent" + shift=" " + done fi if ls /sys/class/net/e*/operstate 1>/dev/null 2>&1; then - for e in /sys/class/net/e*/operstate; do - if_icon="$(sed "s/down//;s/up//" $e)" - printf "$shift\033[11m%s\033[10m" "$if_icon" - shift=" " - done + for e in /sys/class/net/e*/operstate; do + if_icon="$(sed "s/down//;s/up//" $e)" + printf "$shift\033[11m%s\033[10m" "$if_icon" + shift=" " + done fi if ls /sys/class/net/tun*/operstate 1>/dev/null 2>&1; then - for _ in /sys/class/net/tun*/operstate; do - printf "$shift\033[11m%s\033[10m" "嬨" - shift=" " - done + for _ in /sys/class/net/tun*/operstate; do + printf "$shift\033[11m%s\033[10m" "嬨" + shift=" " + done fi printf "\n" diff --git a/.local/bin/statusbar/sb-music b/.local/bin/statusbar/sb-music index 788566838..db90d7d68 100755 --- a/.local/bin/statusbar/sb-music +++ b/.local/bin/statusbar/sb-music @@ -1,15 +1,15 @@ #!/bin/sh filter() { - if mpc 1>/dev/null 2>&1 && [ "$(mpc | wc -l)" -eq 3 ]; then - song=$(mpc current -f "%artist% - %title%" | xargs -0 ) - [ ${#song} -gt 35 ] && song="$(printf %.35s "$song")…" - mpc | awk 'NR==2' | grep -q playing && icon="" || icon="" - echo "$icon $song" - elif mpc 1>/dev/null 2>&1 && [ "$(mpc | wc -l)" -eq 1 ]; then - echo "ﱙ" - else - exit 1 - fi + if mpc 1>/dev/null 2>&1 && [ "$(mpc | wc -l)" -eq 3 ]; then + song=$(mpc current -f "%artist% - %title%" | xargs -0) + [ ${#song} -gt 35 ] && song="$(printf %.35s "$song")…" + mpc | awk 'NR==2' | grep -q playing && icon="" || icon="" + echo "$icon $song" + elif mpc 1>/dev/null 2>&1 && [ "$(mpc | wc -l)" -eq 1 ]; then + echo "ﱙ" + else + exit 1 + fi } pidof -x sbd-music >/dev/null 2>&1 || sbd-music >/dev/null 2>&1 & filter diff --git a/.local/bin/statusbar/sb-nettraf b/.local/bin/statusbar/sb-nettraf index ad206c0bf..687c4ec2b 100755 --- a/.local/bin/statusbar/sb-nettraf +++ b/.local/bin/statusbar/sb-nettraf @@ -1,14 +1,14 @@ #!/bin/sh update() { - sum=0 - for arg; do - read -r i < "$arg" - sum=$(( sum + i )) - done - cache=/tmp/${1##*/} - [ -f "$cache" ] && read -r old < "$cache" || old=0 - printf %d\\n "$sum" > "$cache" - printf %d\\n $(( sum - old )) + sum=0 + for arg; do + read -r i <"$arg" + sum=$((sum + i)) + done + cache=/tmp/${1##*/} + [ -f "$cache" ] && read -r old <"$cache" || old=0 + printf %d\\n "$sum" >"$cache" + printf %d\\n $((sum - old)) } rx=$(update /sys/class/net/[ew]*/statistics/rx_bytes) tx=$(update /sys/class/net/[ew]*/statistics/tx_bytes) diff --git a/.local/bin/statusbar/sb-volume b/.local/bin/statusbar/sb-volume index dda445403..5bc77fc18 100755 --- a/.local/bin/statusbar/sb-volume +++ b/.local/bin/statusbar/sb-volume @@ -9,9 +9,9 @@ elif [ "$vol" -gt "30" ]; then icon="" elif [ "$vol" -gt "0" ]; then icon="" -elif [ "$vol" -eq "0" ]; then - icon="" +elif [ "$vol" -eq "0" ]; then + icon="" else - printf "\033[11m\033[10m " && exit + printf "\033[11m\033[10m " && exit fi printf "\033[11m%s\033[10m %s\n" "$icon" "$vol" diff --git a/.local/bin/sysact b/.local/bin/sysact index 7c23e1e47..564b127ee 100755 --- a/.local/bin/sysact +++ b/.local/bin/sysact @@ -1,18 +1,21 @@ #!/bin/sh # A dmenu wrapper script for system functions. case "$(readlink -f /sbin/init)" in - *systemd*) ctl='systemctl' ;; - *) ctl='loginctl' ;; +*systemd*) ctl='systemctl' ;; +*) ctl='loginctl' ;; esac case "$(printf " lock\nﴚ leave dwm\n累 renew dwm\nﭦ hibernate\n sleep\nﰇ reboot\n襤 shutdown\n display off" | dmenu -i -p 'Action: ')" in - ' lock') xset s activate & gpg-connect-agent --no-autostart reloadagent /bye;; - 'ﴚ leave dwm') kill -TERM "$(pgrep -u "$USER" "\bdwm$")" ;; - '累 renew dwm') kill -HUP "$(pgrep -u "$USER" "\bdwm$")" ;; +' lock') + xset s activate & + gpg-connect-agent --no-autostart reloadagent /bye + ;; +'ﴚ leave dwm') kill -TERM "$(pgrep -u "$USER" "\bdwm$")" ;; +'累 renew dwm') kill -HUP "$(pgrep -u "$USER" "\bdwm$")" ;; # 'ﭦ hibernate') slock $ctl hibernate -i ;; # ' sleep') slock $ctl suspend -i ;; - 'ﰇ reboot') $ctl reboot ;; - '襤 shutdown') $ctl poweroff ;; - ' display off') xset dpms force off ;; - *) exit 1 ;; +'ﰇ reboot') $ctl reboot ;; +'襤 shutdown') $ctl poweroff ;; +' display off') xset dpms force off ;; +*) exit 1 ;; esac diff --git a/.local/bin/texclear b/.local/bin/texclear index aa494bccb..8eed19401 100755 --- a/.local/bin/texclear +++ b/.local/bin/texclear @@ -4,12 +4,12 @@ # I have vim run this file whenever I exit a .tex file. case "$1" in - *.tex) +*.tex) file=$(readlink -f "$1") dir=$(dirname "$file") base="${file%.*}" - find "$dir" -maxdepth 1 -type f -regextype gnu-awk -regex "^$base\\.(4tc|xref|tmp|pyc|pyg|pyo|fls|vrb|fdb_latexmk|bak|swp|aux|log|synctex\\(busy\\)|lof|lot|maf|idx|mtc|mtc0|nav|out|snm|toc|bcf|run\\.xml|synctex\\.gz|blg|bbl)" -delete + find "$dir" -maxdepth 1 -type f -regextype gnu-awk -regex "^$base\\.(4tc|xref|tmp|pyc|pyg|pyo|fls|vrb|fdb_latexmk|bak|swp|aux|log|synctex\\(busy\\)|lof|lot|maf|idx|mtc|mtc0|nav|out|snm|toc|bcf|run\\.xml|synctex\\.gz|blg|bbl)" -delete rm -rdf "$dir/_minted-$(basename -- "$base")" ;; - *) printf "Give .tex file as argument.\\n" ;; +*) printf "Give .tex file as argument.\\n" ;; esac diff --git a/.local/bin/trash-put b/.local/bin/trash-put index 5bce53be8..65328ee7b 100755 --- a/.local/bin/trash-put +++ b/.local/bin/trash-put @@ -2,25 +2,25 @@ set -e [ -e "$1" ] || exit 1 getfsroot() { - printf "%s" "$(df "$1" --output=target | tail -1)" + printf "%s" "$(df "$1" --output=target | tail -1)" } filepath="$(realpath "$1")" filename="$(basename "$1")" fsroot="$(getfsroot "$1")" -[ "$fsroot" = "$(getfsroot "${XDG_DATA_HOME:-$HOME/.local/share}")" ] \ - && basedir="${XDG_DATA_HOME:-$HOME/.local/share}/Trash" \ - || basedir="${fsroot}/.Trash" +[ "$fsroot" = "$(getfsroot "${XDG_DATA_HOME:-$HOME/.local/share}")" ] && + basedir="${XDG_DATA_HOME:-$HOME/.local/share}/Trash" || + basedir="${fsroot}/.Trash" infodir="$basedir/info" filedir="$basedir/files" mkdir -p "$infodir" 1>/dev/null 2>&1 mkdir -p "$filedir" 1>/dev/null 2>&1 find "$filedir" -regex ".*$filename.*" | grep -oP '(?<=.\.~)\d+(?=~$)' | sort -n | tail -1 | ( -ext=$(($(cat /dev/stdin)+1)) -filedest="$filedir/$filename.~$ext~" -command mv -f "$filepath" "$filedest" -cat < "$infodir/$(basename "$filedest")" + ext=$(($(cat /dev/stdin) + 1)) + filedest="$filedir/$filename.~$ext~" + command mv -f "$filepath" "$filedest" + cat <"$infodir/$(basename "$filedest")" [Trash Info] Path=$filepath DeletionDate=$(date +%Y%m%dT%T) diff --git a/.local/bin/trash-restore b/.local/bin/trash-restore index b850c40ed..d44dacab5 100755 --- a/.local/bin/trash-restore +++ b/.local/bin/trash-restore @@ -1,28 +1,28 @@ #!/bin/sh set -e getfsroot() { - printf "%s" "$(df "$1" --output=target | tail -1)" + printf "%s" "$(df "$1" --output=target | tail -1)" } list() { - # 1st arg is trash files directory - # 2nd arg is directory to match trash files for - [ ! "$(ls -A "$1")" ] && exit 1 - for file in "$1"/* ; do - [ "$(head -1 "$file")" = "[Trash Info]" ] && \ - fpath=$(grep Path "$file" | cut -d '=' -f2) && \ - echo "$fpath" | grep -qP "^$2/[^/]+$" && \ - printf "%s %s %s\n" \ - "$(basename "$file")" \ - "$fpath" \ - "$(date -d "$(grep Date "$file" | cut -d '=' -f2)" +'%x %X')" - done + # 1st arg is trash files directory + # 2nd arg is directory to match trash files for + [ ! "$(ls -A "$1")" ] && exit 1 + for file in "$1"/*; do + [ "$(head -1 "$file")" = "[Trash Info]" ] && + fpath=$(grep Path "$file" | cut -d '=' -f2) && + echo "$fpath" | grep -qP "^$2/[^/]+$" && + printf "%s %s %s\n" \ + "$(basename "$file")" \ + "$fpath" \ + "$(date -d "$(grep Date "$file" | cut -d '=' -f2)" +'%x %X')" + done } [ -n "$1" ] && dir="$(realpath "$1")" || dir="$(getfsroot "$PWD")" fsroot="$(getfsroot "$dir")" -[ "$fsroot" = "$(getfsroot "${XDG_DATA_HOME:-$HOME/.local/share}")" ] \ - && basedir="${XDG_DATA_HOME:-$HOME/.local/share}/Trash" \ - || basedir="${fsroot}/.Trash" +[ "$fsroot" = "$(getfsroot "${XDG_DATA_HOME:-$HOME/.local/share}")" ] && + basedir="${XDG_DATA_HOME:-$HOME/.local/share}/Trash" || + basedir="${fsroot}/.Trash" sel="$(list "$basedir/info" "$dir" | fzf)" file="$basedir/files/$(echo "$sel" | cut -d ' ' -f1)" diff --git a/.local/bin/trash/booksplit b/.local/bin/trash/booksplit index 7730ac231..1955ec5d8 100755 --- a/.local/bin/trash/booksplit +++ b/.local/bin/trash/booksplit @@ -4,11 +4,14 @@ [ ! -f "$2" ] && printf "The first file should be the audio, the second should be the timecodes.\\n" && exit -echo "Enter the album/book title:"; read -r booktitle +echo "Enter the album/book title:" +read -r booktitle -echo "Enter the artist/author:"; read -r author +echo "Enter the artist/author:" +read -r author -echo "Enter the publication year:"; read -r year +echo "Enter the publication year:" +read -r year inputaudio="$1" @@ -22,25 +25,24 @@ ext="opus" #ext="${1#*.}" # Get the total number of tracks from the number of lines. -total="$(wc -l < "$2")" +total="$(wc -l <"$2")" -while read -r x; -do +while read -r x; do end="$(echo "$x" | cut -d' ' -f1)" [ -n "$start" ] && - echo "From $start to $end; $track $title" + echo "From $start to $end; $track $title" file="$escbook/$(printf "%.2d" "$track")-$esctitle.$ext" [ -n "$start" ] && echo "Splitting \"$title\"..." && - ffmpeg -nostdin -y -loglevel -8 -i "$inputaudio" -ss "$start" -to "$end" -vn -c copy "$file" && - echo "Tagging \"$title\"..." && tag -a "$author" -A "$booktitle" -t "$title" -n "$track" -N "$total" -d "$year" "$file" + ffmpeg -nostdin -y -loglevel -8 -i "$inputaudio" -ss "$start" -to "$end" -vn -c copy "$file" && + echo "Tagging \"$title\"..." && tag -a "$author" -A "$booktitle" -t "$title" -n "$track" -N "$total" -d "$year" "$file" title="$(echo "$x" | cut -d' ' -f 2-)" esctitle="$(echo "$title" | iconv -cf UTF-8 -t ASCII//TRANSLIT | tr -d '[:punct:]' | tr '[:upper:]' '[:lower:]' | tr ' ' '-' | sed "s/-\+/-/g;s/\(^-\|-\$\)//g")" - track="$((track+1))" + track="$((track + 1))" start="$end" -done < "$2" +done <"$2" # The last track must be done outside the loop. echo "From $start to the end: $title" file="$escbook/$(printf "%.2d" "$track")-$esctitle.$ext" echo "Splitting \"$title\"..." && ffmpeg -nostdin -y -loglevel -8 -i "$inputaudio" -ss "$start" -vn -c copy "$file" && - echo "Tagging \"$title\"..." && tag -a "$author" -A "$booktitle" -t "$title" -n "$track" -N "$total" -d "$year" "$file" \ No newline at end of file + echo "Tagging \"$title\"..." && tag -a "$author" -A "$booktitle" -t "$title" -n "$track" -N "$total" -d "$year" "$file" diff --git a/.local/bin/trash/getbib b/.local/bin/trash/getbib index 8675aae85..235bf4d8e 100755 --- a/.local/bin/trash/getbib +++ b/.local/bin/trash/getbib @@ -4,8 +4,8 @@ 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 + doi=$(pdftotext "$1" - 2>/dev/null | grep -io "doi:.*" -m 1) || + exit 1 else doi="$1" fi diff --git a/.local/bin/trash/noisereduce b/.local/bin/trash/noisereduce index c344760ee..1d03e7687 100755 --- a/.local/bin/trash/noisereduce +++ b/.local/bin/trash/noisereduce @@ -1,59 +1,59 @@ #!/usr/bin/sh -usage () -{ - printf "Usage : noisereduce \n" - exit +usage() { + printf "Usage : noisereduce \n" + exit } # Tests for requirements -ifinstalled ffmpeg || { echo >&2 "We require 'ffmpeg' but it's not installed."; exit 1; } -ifinstalled sox || { echo >&2 "We require 'ffmpeg' but it's not installed."; exit 1; } +ifinstalled ffmpeg || { + echo >&2 "We require 'ffmpeg' but it's not installed." + exit 1 +} +ifinstalled sox || { + echo >&2 "We require 'ffmpeg' but it's not installed." + exit 1 +} -if [ "$#" -ne 2 ] -then - usage +if [ "$#" -ne 2 ]; then + usage fi -if [ ! -e "$1" ] -then - printf "File not found: %s\n" "$1" - exit +if [ ! -e "$1" ]; then + printf "File not found: %s\n" "$1" + exit fi -if [ -e "$2" ] -then - printf "File %s already exists, overwrite? [y/N]\n: " "$2" - read -r yn - case $yn in - [Yy]* ) ;; - * ) exit;; - esac +if [ -e "$2" ]; then + printf "File %s already exists, overwrite? [y/N]\n: " "$2" + read -r yn + case $yn in + [Yy]*) ;; + *) exit ;; + esac fi inBasename=$(basename "$1") inExt="${inBasename##*.}" isVideoStr=$(ffprobe -v warning -show_streams "$1" | grep codec_type=video) -if [ -n "$isVideoStr" ] -then - isVideo=1 - printf "Detected %s as a video file\n" "$inBasename" +if [ -n "$isVideoStr" ]; then + isVideo=1 + printf "Detected %s as a video file\n" "$inBasename" else - isVideo=0 - printf "Detected %s as an audio file\n" "$inBasename" + isVideo=0 + printf "Detected %s as an audio file\n" "$inBasename" fi printf "Sample noise start time [00:00:00]: " read -r sampleStart -if [ -z "$sampleStart" ] ; then sampleStart="00:00:00"; fi +if [ -z "$sampleStart" ]; then sampleStart="00:00:00"; fi printf "Sample noise end time [00:00:00.900]: " read -r sampleEnd -if [ -z "$sampleEnd" ] ; then sampleEnd="00:00:00.900"; fi +if [ -z "$sampleEnd" ]; then sampleEnd="00:00:00.900"; fi printf "Noise reduction amount [0.21]: " read -r sensitivity -if [ -z "$sensitivity" ] ; then sensitivity="0.21"; fi - +if [ -z "$sensitivity" ]; then sensitivity="0.21"; fi tmpVidFile="/tmp/noiseclean_tmpvid.$inExt" tmpAudFile="/tmp/noiseclean_tmpaud.wav" @@ -64,18 +64,18 @@ tmpAudCleanFile="/tmp/noiseclean_tmpaud-clean.wav" printf "Cleaning noise on %s...\n" "$1" if [ $isVideo -eq "1" ]; then - ffmpeg -v warning -y -i "$1" -qscale:v 0 -vcodec copy -an "$tmpVidFile" - ffmpeg -v warning -y -i "$1" -qscale:a 0 "$tmpAudFile" + ffmpeg -v warning -y -i "$1" -qscale:v 0 -vcodec copy -an "$tmpVidFile" + ffmpeg -v warning -y -i "$1" -qscale:a 0 "$tmpAudFile" else - cp "$1" "$tmpAudFile" + cp "$1" "$tmpAudFile" fi ffmpeg -v warning -y -i "$1" -vn -ss "$sampleStart" -t "$sampleEnd" "$noiseAudFile" sox "$noiseAudFile" -n noiseprof "$noiseProfFile" sox "$tmpAudFile" "$tmpAudCleanFile" noisered "$noiseProfFile" "$sensitivity" if [ $isVideo -eq "1" ]; then - ffmpeg -v warning -y -i "$tmpAudCleanFile" -i "$tmpVidFile" -vcodec copy -qscale:v 0 -qscale:a 0 "$2" + ffmpeg -v warning -y -i "$tmpAudCleanFile" -i "$tmpVidFile" -vcodec copy -qscale:v 0 -qscale:a 0 "$2" else - cp "$tmpAudCleanFile" "$2" + cp "$tmpAudCleanFile" "$2" fi printf "Done" diff --git a/.local/bin/trash/otp b/.local/bin/trash/otp index 3b313638f..f59f515c7 100755 --- a/.local/bin/trash/otp +++ b/.local/bin/trash/otp @@ -13,41 +13,45 @@ ifinstalled pass pass-otp dir="${PASSWORD_STORE_DIR}" -choice="$({ echo "🆕add" ; echo "🕙sync-time" ; ls ${dir}/*-otp.gpg ;} | sed "s/.*\///;s/-otp.gpg//" | dmenu -p "Pick a 2FA:")" +choice="$({ + echo "🆕add" + echo "🕙sync-time" + ls ${dir}/*-otp.gpg +} | sed "s/.*\///;s/-otp.gpg//" | dmenu -p "Pick a 2FA:")" case $choice in - 🆕add ) - ifinstalled maim zbar xclip || exit 1 +🆕add) + ifinstalled maim zbar xclip || exit 1 - temp="$dir/temp.png" - otp="otp-test-script" - trap 'shred -fu $temp; pass rm $otp' HUP INT QUIT TERM PWR EXIT + temp="$dir/temp.png" + otp="otp-test-script" + trap 'shred -fu $temp; pass rm $otp' HUP INT QUIT TERM PWR EXIT - notify-send "Scan the image." "Scan the OTP QR code." + notify-send "Scan the image." "Scan the OTP QR code." - maim -s "$temp" || exit 1 - info="$(zbarimg -q "$temp")" - info="${info#QR-Code:}" - issuer="$(echo "$info" | grep -o "issuer=[A-z0-9]\+")" - name="${issuer#issuer=}" + maim -s "$temp" || exit 1 + info="$(zbarimg -q "$temp")" + info="${info#QR-Code:}" + issuer="$(echo "$info" | grep -o "issuer=[A-z0-9]\+")" + name="${issuer#issuer=}" - if echo "$info" | pass otp insert "$otp"; then - while true ; do - export name="$(prinf | dmenu -p "Give this One Time Password a one-word name:")" - echo "$name" | grep -q -- "^[A-z0-9-]\+$" && break - done - pass mv "$otp" "$name-otp" - notify-send "Successfully added." "$name-otp has been created." - else - notify-send "No OTP data found." "Try to scan the image again more precisely." - fi + if echo "$info" | pass otp insert "$otp"; then + while true; do + export name="$(prinf | dmenu -p "Give this One Time Password a one-word name:")" + echo "$name" | grep -q -- "^[A-z0-9-]\+$" && break + done + pass mv "$otp" "$name-otp" + notify-send "Successfully added." "$name-otp has been created." + else + notify-send "No OTP data found." "Try to scan the image again more precisely." + fi - ;; - 🕙sync-time ) - ifinstalled ntp || exit 1 - notify-send -u low "🕙 Synchronizing Time..." "Synching time with remote NTP servers..." - updatedata="$(sudo ntpdate pool.ntp.org)" && + ;; +🕙sync-time) + ifinstalled ntp || exit 1 + notify-send -u low "🕙 Synchronizing Time..." "Synching time with remote NTP servers..." + updatedata="$(sudo ntpdate pool.ntp.org)" && notify-send -u low "🕙 Synchronizing Time..." "Done. Time changed by ${updatedata#*offset }" - ;; - *) pass otp -c ${choice}-otp ;; + ;; +*) pass otp -c ${choice}-otp ;; esac diff --git a/.local/bin/trash/slider b/.local/bin/trash/slider index 674781a40..58a4ab23d 100755 --- a/.local/bin/trash/slider +++ b/.local/bin/trash/slider @@ -20,14 +20,18 @@ while getopts "hvrpi:c:a:o:d:f:t:e:x:" o; do case "${o}" in r) redo="$OPTARG" ;; s) ppt="$OPTARG" ;; e) endtime="$OPTARG" ;; - x) res="$OPTARG" + x) + res="$OPTARG" echo "$res" | grep -qv "^[0-9]\+x[0-9]\+$" && echo "Resolution must be dimensions separated by a 'x': 1280x720, etc." && - exit 1 ;; - p) echo "Purge old build files in $cache? [y/N]" + exit 1 + ;; + p) + echo "Purge old build files in $cache? [y/N]" read -r confirm echo "$confirm" | grep -iq "^y$" && rm -rf "$cache" && echo "Done." - exit ;; + exit + ;; v) verbose=True ;; *) echo "$(basename "$0") usage: -i input timecode list (required) @@ -42,14 +46,14 @@ while getopts "hvrpi:c:a:o:d:f:t:e:x:" o; do case "${o}" in -d tmp directory -r rerun imagemagick commands even if done previously (in case files or background has changed) -p purge old build files instead of running - -v be verbose" && exit 1 + -v be verbose" && exit 1 ;; -esac done + esac done # Check that the input file looks like it should. -{ head -n 1 "$file" 2>/dev/null | grep -q "^00:00:00 " ;} || { +{ head -n 1 "$file" 2>/dev/null | grep -q "^00:00:00 "; } || { echo "Give an input file with -i." && - echo "The file should look as this example: + echo "The file should look as this example: 00:00:00 first_image.jpg 00:00:03 otherdirectory/next_image.jpg @@ -57,17 +61,20 @@ esac done etc... Timecodes and filenames must be separated by Tabs." && - exit 1 - } + exit 1 +} if [ -n "${audio+x}" ]; then # Check that the audio file looks like an actual audio file. case "$(file --dereference --brief --mime-type -- "$audio")" in - audio/*) ;; - *) echo "That doesn't look like an audio file."; exit 1 ;; + audio/*) ;; + *) + echo "That doesn't look like an audio file." + exit 1 + ;; esac totseconds="$(date '+%s' -d $(ffmpeg -i "$audio" 2>&1 | awk '/Duration/ {print $2}' | sed s/,//))" - endtime="$((totseconds-seconds))" + endtime="$((totseconds - seconds))" fi prepdir="${prepdir:-$cache/$file}" @@ -78,43 +85,42 @@ prepfile="$prepdir/$file.prep" mkdir -p "$prepdir" { -while read -r x; -do - # Get the time from the first column. - time="${x%% *}" - seconds="$(date '+%s' -d "$time")" - # Duration is not used on the first looped item. - duration="$((seconds - prevseconds))" + while read -r x; do + # Get the time from the first column. + time="${x%% *}" + seconds="$(date '+%s' -d "$time")" + # Duration is not used on the first looped item. + duration="$((seconds - prevseconds))" - # Get the filename/text content from the rest. - content="${x#* }" - base="$(basename "$content")" - base="${base%.*}.jpg" + # Get the filename/text content from the rest. + content="${x#* }" + base="$(basename "$content")" + base="${base%.*}.jpg" - if [ -f "$content" ]; then - # If images have already been made in a previous run, do not recreate - # them unless -r was given. - { [ ! -f "$prepdir/$base" ] || [ -n "${redo+x}" ] ;} && - convert -size "${res:-1920x1080}" canvas:"${bgc:-black}" -gravity center "$content" -resize 1920x1080 -composite "$prepdir/$base" - else - { [ ! -f "$prepdir/$base" ] || [ -n "${redo+x}" ] ;} && - convert -size "${res:-1920x1080}" -background "${bgc:-black}" -fill "${fgc:-white}" -font "${font:-Sans}" -pointsize "${ppt:-150}" -gravity center label:"$content" "$prepdir/$base" - fi + if [ -f "$content" ]; then + # If images have already been made in a previous run, do not recreate + # them unless -r was given. + { [ ! -f "$prepdir/$base" ] || [ -n "${redo+x}" ]; } && + convert -size "${res:-1920x1080}" canvas:"${bgc:-black}" -gravity center "$content" -resize 1920x1080 -composite "$prepdir/$base" + else + { [ ! -f "$prepdir/$base" ] || [ -n "${redo+x}" ]; } && + convert -size "${res:-1920x1080}" -background "${bgc:-black}" -fill "${fgc:-white}" -font "${font:-Sans}" -pointsize "${ppt:-150}" -gravity center label:"$content" "$prepdir/$base" + fi - # If the first line, do not write yet. - [ "$time" = "00:00:00" ] || echo "file '$prevbase' + # If the first line, do not write yet. + [ "$time" = "00:00:00" ] || echo "file '$prevbase' duration $duration" - # Keep the information required for the next file. - prevbase="$base" - prevtime="$time" - prevseconds="$(date '+%s' -d "$prevtime")" -done < "$file" -# Do last file which must be given twice as follows -echo "file '$base' + # Keep the information required for the next file. + prevbase="$base" + prevtime="$time" + prevseconds="$(date '+%s' -d "$prevtime")" + done <"$file" + # Do last file which must be given twice as follows + echo "file '$base' duration ${endtime:-5} file '$base'" -} > "$prepfile" +} >"$prepfile" if [ -n "${audio+x}" ]; then ffmpeg -hide_banner -y -f concat -safe 0 -i "$prepfile" -i "$audio" -c:a aac -vsync vfr -c:v libx264 -pix_fmt yuv420p "$outfile" else diff --git a/.local/bin/trash/tag b/.local/bin/trash/tag index 8462b99ae..06071a6a6 100755 --- a/.local/bin/trash/tag +++ b/.local/bin/trash/tag @@ -11,7 +11,7 @@ Options: -d: year of publication -g: genre -c: comment -You will be prompted for title, artist, album and track if not given." && exit 1 ;} +You will be prompted for title, artist, album and track if not given." && exit 1; } while getopts "a:t:A:n:N:d:g:c:f:" o; do case "${o}" in a) artist="${OPTARG}" ;; @@ -24,7 +24,7 @@ while getopts "a:t:A:n:N:d:g:c:f:" o; do case "${o}" in c) comment="${OPTARG}" ;; f) file="${OPTARG}" ;; *) printf "Invalid option: -%s\\n" "$OPTARG" && err ;; -esac done + esac done shift $((OPTIND - 1)) @@ -38,7 +38,7 @@ file="$1" [ -z "$track" ] && echo "Enter a track number." && read -r track case "$file" in - *.ogg) echo "Title=$title +*.ogg) echo "Title=$title Artist=$artist Album=$album Track=$track @@ -46,7 +46,7 @@ Total=$total Date=$date Genre=$genre Comment=$comment" | vorbiscomment -w "$file" ;; - *.opus) echo "Title=$title +*.opus) echo "Title=$title Artist=$artist Album=$album Track=$track @@ -54,8 +54,8 @@ Total=$total Date=$date Genre=$genre Comment=$comment" | opustags -i -S "$file" ;; - *.mp3) eyeD3 -Q --remove-all -a "$artist" -A "$album" -t "$title" -n "$track" -N "$total" -Y "$date" "$file" ;; - *.flac) echo "TITLE=$title +*.mp3) eyeD3 -Q --remove-all -a "$artist" -A "$album" -t "$title" -n "$track" -N "$total" -Y "$date" "$file" ;; +*.flac) echo "TITLE=$title ARTIST=$artist ALBUM=$album TRACKNUMBER=$track @@ -63,5 +63,5 @@ TOTALTRACKS=$total DATE=$date GENRE=$genre DESCRIPTION=$comment" | metaflac --remove-all-tags --import-tags-from=- "$file" ;; - *) echo "File type not implemented yet." ;; +*) echo "File type not implemented yet." ;; esac diff --git a/.local/bin/vidthumb b/.local/bin/vidthumb index 72143d0b0..3c5165711 100755 --- a/.local/bin/vidthumb +++ b/.local/bin/vidthumb @@ -35,4 +35,3 @@ json="$(jq -r --arg "$movie" "$thumbnail" ". + {\"$movie\": \"$thumbnail\"}" <"$ echo "$json" >"$index" echo "$cache/$thumbnail" -