summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
author--global <ik.boikov.public@protonmail.com>2021-07-14 23:02:24 +0200
committer--global <ik.boikov.public@protonmail.com>2021-07-14 23:02:24 +0200
commitfd850fb2ed9870edcb1df205e08e8ccb25fb6760 (patch)
tree641b5af724d86a0a383b2c580dd838b03c1cc42c /scripts
parent72000d2f0c23a685f4c4d458158712340f6b9a68 (diff)
more nnn plugins, more luke's scripts
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/.local/bin/borg-backup16
-rwxr-xr-xscripts/.local/bin/displayselect83
-rwxr-xr-xscripts/.local/bin/ext45
-rwxr-xr-xscripts/.local/bin/getbib14
-rwxr-xr-xscripts/.local/bin/linkhandler23
-rwxr-xr-xscripts/.local/bin/maimpick14
-rwxr-xr-xscripts/.local/bin/opout13
-rwxr-xr-xscripts/.local/bin/prompt8
-rwxr-xr-xscripts/.local/bin/remaps13
-rwxr-xr-xscripts/.local/bin/rotdir12
-rwxr-xr-xscripts/.local/bin/samedir8
-rwxr-xr-xscripts/.local/bin/setbg24
-rwxr-xr-xscripts/.local/bin/texclear15
13 files changed, 283 insertions, 5 deletions
diff --git a/scripts/.local/bin/borg-backup b/scripts/.local/bin/borg-backup
index 751b78d..2ba7774 100755
--- a/scripts/.local/bin/borg-backup
+++ b/scripts/.local/bin/borg-backup
@@ -1,9 +1,10 @@
#!/bin/sh
# Setting this, so the repo does not need to be given on the commandline:
-export BORG_REPO=ssh://pi@192.168.3.1/media/nas/borgbackup
+#export BORG_REPO=ssh://pi@192.168.3.1/media/nas/borgbackup
+export BORG_REPO=/media/wdblue-old/borgbackup
# See the section "Passphrase notes" for more infos.
#export BORG_PASSPHRASE='XYZl0ngandsecurepa_55_phrasea&&123'
-export BORG_PASSCOMMAND="cat $HOME/.borg-backup-passphrase"
+#export BORG_PASSCOMMAND="cat $HOME/.config/borg/keys/media_wdblue_old_borgbackup"
# some helpers and error handling:
info() { printf "\n%s %s\n\n" "$( date )" "$*" >&2; }
trap 'echo $( date ) Backup interrupted >&2; exit 2' INT TERM
@@ -28,9 +29,14 @@ borg create \
--exclude='*log*' \
--exclude='*old*' \
--exclude='*bak*' \
- \
- ::'{hostname}-{now}' \
- TODO-ADD-SOME-PATHS
+ \
+ ::'{hostname}-{now}' \
+ /media/wdblue/dox \
+ /media/wdblue/dox-arch \
+ /media/wdblue/vid/gachi \
+ /media/wdblue/pix \
+ /media/wdblue/tracks \
+ /media/wdblue/sync \
backup_exit=$?
diff --git a/scripts/.local/bin/displayselect b/scripts/.local/bin/displayselect
new file mode 100755
index 0000000..f9e8062
--- /dev/null
+++ b/scripts/.local/bin/displayselect
@@ -0,0 +1,83 @@
+#!/bin/sh
+
+# A UI for detecting and selecting all displays. Probes xrandr for connected
+# displays and lets user select one to use. User may also select "manual
+# selection" which opens arandr.
+
+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")
+
+ 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//')
+
+ 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
+
+ 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
+ }
+
+multimon() { # Multi-monitor handler.
+ 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 ' ' -)
+ }
+
+postrun() { # Stuff to run to clean up.
+ setbg # Fix background if screen size/arangement has changed.
+ remaps # 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
+allposs=$(xrandr -q | grep "connected")
+
+# Get all connected screens.
+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 ;}
+
+# 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
+
+postrun
diff --git a/scripts/.local/bin/ext b/scripts/.local/bin/ext
new file mode 100755
index 0000000..927fb5b
--- /dev/null
+++ b/scripts/.local/bin/ext
@@ -0,0 +1,45 @@
+#!/bin/sh
+
+# A general, all-purpose extraction script. Not all extraction programs here
+# are installed by LARBS automatically.
+#
+# Default behavior: Extract archive into new directory
+# Behavior with `-c` option: Extract contents into current directory
+
+while getopts "hc" o; do case "${o}" in
+ c) extracthere="True" ;;
+ *) printf "Options:\\n -c: Extract archive into current directory rather than a new one.\\n" && exit 1 ;;
+esac done
+
+if [ -z "$extracthere" ]; then
+ archive="$(readlink -f "$*")" &&
+ directory="$(echo "$archive" | sed 's/\.[^\/.]*$//')" &&
+ mkdir -p "$directory" &&
+ cd "$directory" || exit 1
+else
+ archive="$(readlink -f "$(echo "$*" | cut -d' ' -f2)" 2>/dev/null)"
+fi
+
+[ -z "$archive" ] && printf "Give archive to extract as argument.\\n" && exit 1
+
+if [ -f "$archive" ] ; then
+ case "$archive" in
+ *.tar.bz2|*.tbz2) tar xvjf "$archive" ;;
+ *.tar.xz) tar -xf "$archive" ;;
+ *.tar.gz|*.tgz) tar xvzf "$archive" ;;
+ *.tar.zst) tar -I zstd -xf "$archive" ;;
+ *.lzma) unlzma "$archive" ;;
+ *.bz2) bunzip2 "$archive" ;;
+ *.rar) unrar x -ad "$archive" ;;
+ *.gz) gunzip "$archive" ;;
+ *.tar) tar xvf "$archive" ;;
+ *.zip) unzip "$archive" ;;
+ *.Z) uncompress "$archive" ;;
+ *.7z) 7z x "$archive" ;;
+ *.xz) unxz "$archive" ;;
+ *.exe) cabextract "$archive" ;;
+ *) printf "extract: '%s' - unknown archive method\\n" "$archive" ;;
+ esac
+else
+ printf "File \"%s\" not found.\\n" "$archive"
+fi
diff --git a/scripts/.local/bin/getbib b/scripts/.local/bin/getbib
new file mode 100755
index 0000000..ed441c5
--- /dev/null
+++ b/scripts/.local/bin/getbib
@@ -0,0 +1,14 @@
+#!/bin/sh
+[ -z "$1" ] && echo "Give either a pdf file or a DOI as an argument." && exit
+
+if [ -f "$1" ]; then
+ # Try to get DOI from pdfinfo or pdftotext output.
+ doi=$(pdfinfo "$1" | grep -io "doi:.*") ||
+ doi=$(pdftotext "$1" 2>/dev/null - | grep -io "doi:.*" -m 1) ||
+ exit 1
+else
+ doi="$1"
+fi
+
+# Check crossref.org for the bib citation.
+curl -s "http://api.crossref.org/works/$doi/transform/application/x-bibtex" -w "\\n"
diff --git a/scripts/.local/bin/linkhandler b/scripts/.local/bin/linkhandler
new file mode 100755
index 0000000..04934e5
--- /dev/null
+++ b/scripts/.local/bin/linkhandler
@@ -0,0 +1,23 @@
+#!/bin/sh
+
+# Feed script a url or file location.
+# If an image, it will view in sxiv,
+# if a video or gif, it will view in mpv
+# if a music file or pdf, it will download,
+# otherwise it opens link in browser.
+
+# If no url given. Opens browser. For using script as $BROWSER.
+[ -z "$1" ] && { "$BROWSER"; exit; }
+
+case "$1" in
+ *mkv|*webm|*mp4|*youtube.com/watch*|*youtube.com/playlist*|*youtu.be*|*hooktube.com*|*bitchute.com*|*videos.lukesmith.xyz*)
+ setsid -f mpv -quiet "$1" >/dev/null 2>&1 ;;
+ *png|*jpg|*jpe|*jpeg|*gif)
+ curl -sL "$1" > "/tmp/$(echo "$1" | sed "s/.*\///;s/%20/ /g")" && sxiv -a "/tmp/$(echo "$1" | sed "s/.*\///;s/%20/ /g")" >/dev/null 2>&1 & ;;
+ *pdf|*cbz|*cbr)
+ curl -sL "$1" > "/tmp/$(echo "$1" | sed "s/.*\///;s/%20/ /g")" && zathura "/tmp/$(echo "$1" | sed "s/.*\///;s/%20/ /g")" >/dev/null 2>&1 & ;;
+ *mp3|*flac|*opus|*mp3?source*)
+ qndl "$1" 'curl -LO' >/dev/null 2>&1 ;;
+ *)
+ [ -f "$1" ] && setsid -f "$TERMINAL" -e "$EDITOR" "$1" >/dev/null 2>&1 || setsid -f "$BROWSER" "$1" >/dev/null 2>&1
+esac
diff --git a/scripts/.local/bin/maimpick b/scripts/.local/bin/maimpick
new file mode 100755
index 0000000..7125e61
--- /dev/null
+++ b/scripts/.local/bin/maimpick
@@ -0,0 +1,14 @@
+#!/bin/sh
+
+# This is bound to Shift+PrintScreen by default, requires maim. It lets you
+# choose the kind of screenshot to take, including copying the image or even
+# highlighting an area to copy. scrotcucks on suicidewatch right now.
+
+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-"$(date '+%y%m%d-%H%M-%S').png" ;;
+ "current window") maim -i "$(xdotool getactivewindow)" pic-window-"$(date '+%y%m%d-%H%M-%S').png" ;;
+ "full screen") maim pic-full-"$(date '+%y%m%d-%H%M-%S').png" ;;
+ "a selected area (copy)") maim -s | xclip -selection clipboard -t image/png ;;
+ "current window (copy)") maim -i "$(xdotool getactivewindow)" | xclip -selection clipboard -t image/png ;;
+ "full screen (copy)") maim | xclip -selection clipboard -t image/png ;;
+esac
diff --git a/scripts/.local/bin/opout b/scripts/.local/bin/opout
new file mode 100755
index 0000000..7f452df
--- /dev/null
+++ b/scripts/.local/bin/opout
@@ -0,0 +1,13 @@
+#!/bin/sh
+
+# opout: "open output": A general handler for opening a file's intended output,
+# usually the pdf of a compiled document. I find this useful especially
+# running from vim.
+
+basename="$(echo "${*}" | sed 's/\.[^\/.]*$//')"
+
+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 ;;
+esac
diff --git a/scripts/.local/bin/prompt b/scripts/.local/bin/prompt
new file mode 100755
index 0000000..666434f
--- /dev/null
+++ b/scripts/.local/bin/prompt
@@ -0,0 +1,8 @@
+#!/bin/sh
+
+# A dmenu binary prompt script.
+# Gives a dmenu prompt labeled with $1 to perform command $2.
+# 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
diff --git a/scripts/.local/bin/remaps b/scripts/.local/bin/remaps
new file mode 100755
index 0000000..4afa47e
--- /dev/null
+++ b/scripts/.local/bin/remaps
@@ -0,0 +1,13 @@
+#!/bin/sh
+
+# This script is called on startup to remap keys.
+
+# Increase key speed via a rate change
+xset r rate 200 75
+
+# Map the menu button to right super as well.
+xmodmap -e 'keycode 135 = Super_R'
+
+# external keyboard Alt_R may be mapped to Multi_Key instead of ISO_Level3_Shift, which breaks French QWERTY layout
+xmodmap -e "keycode 64 = ISO_Level3_Shift"
+xmodmap -e "keycode 108 = ISO_Level3_Shift"
diff --git a/scripts/.local/bin/rotdir b/scripts/.local/bin/rotdir
new file mode 100755
index 0000000..86da6db
--- /dev/null
+++ b/scripts/.local/bin/rotdir
@@ -0,0 +1,12 @@
+#!/bin/sh
+
+# When I open an image from the file manager in sxiv (the image viewer), I want
+# to be able to press the next/previous keys to key through the rest of the
+# images in the same directory. This script "rotates" the content of a
+# directory based on the first chosen file, so that if I open the 15th image,
+# if I press next, it will go to the 16th etc. Autistic, I know, but this is
+# one of the reasons that sxiv is great for being able to read standard input.
+
+[ -z "$1" ] && echo "usage: rotdir regex 2>&1" && exit 1
+base="$(basename "$1")"
+ls "$PWD" | awk -v BASE="$base" 'BEGIN { lines = ""; m = 0; } { if ($0 == BASE) { m = 1; } } { if (!m) { if (lines) { lines = lines"\n"; } lines = lines""$0; } else { print $0; } } END { print lines; }'
diff --git a/scripts/.local/bin/samedir b/scripts/.local/bin/samedir
new file mode 100755
index 0000000..73facfd
--- /dev/null
+++ b/scripts/.local/bin/samedir
@@ -0,0 +1,8 @@
+#!/bin/sh
+
+# Open a terminal window in the same directory as the currently active window.
+
+PID=$(xprop -id "$(xprop -root | awk '/_NET_ACTIVE_WINDOW\(WINDOW\)/{print $NF}')" | grep -m 1 PID | cut -d " " -f 3)
+PID="$(pstree -lpA "$PID" | tail -n 1 | awk -F'---' '{print $NF}' | sed -re 's/[^0-9]//g')"
+cd "$(readlink /proc/"$PID"/cwd)" || return 1
+"$TERMINAL"
diff --git a/scripts/.local/bin/setbg b/scripts/.local/bin/setbg
new file mode 100755
index 0000000..8112bcd
--- /dev/null
+++ b/scripts/.local/bin/setbg
@@ -0,0 +1,24 @@
+#!/bin/sh
+
+# This script does the following:
+# Run by itself, set the wallpaper (at X start).
+# If given a file, set that as the new wallpaper.
+# If given a directory, choose random file in it.
+# If wal is installed, also generates a colorscheme.
+
+# Location of link to wallpaper link.
+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
+
+# If pywal is installed, use it.
+command -v wal >/dev/null 2>&1 &&
+ wal -i "$trueloc" -o "${XDG_CONFIG_HOME:-$HOME/.config}/wal/postrun" >/dev/null 2>&1 &&
+ pidof dwm >/dev/null && xdotool key super+F12
+
+xwallpaper --zoom "$bgloc"
diff --git a/scripts/.local/bin/texclear b/scripts/.local/bin/texclear
new file mode 100755
index 0000000..bd110f3
--- /dev/null
+++ b/scripts/.local/bin/texclear
@@ -0,0 +1,15 @@
+#!/bin/sh
+
+# Clears the build files of a LaTeX/XeLaTeX build.
+# I have vim run this file whenever I exit a .tex file.
+
+case "$1" in
+ *.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
+ rm -rdf "$dir/_minted-$(basename -- $base)"
+ ;;
+ *) printf "Give .tex file as argument.\\n" ;;
+esac