diff options
| author | Sebastiano Tronto <sebastiano@tronto.net> | 2026-05-06 08:30:49 +0200 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano@tronto.net> | 2026-05-06 08:30:49 +0200 |
| commit | 60052659b98832c78c902e4f27ecee2663d8e913 (patch) | |
| tree | 9efc1388569c43456557aa1975b4bec99bf06c94 /scripts | |
| parent | 10e16c2fb2266bb2b46ec7ea64d721de0c29a0d9 (diff) | |
| download | config-60052659b98832c78c902e4f27ecee2663d8e913.tar.gz config-60052659b98832c78c902e4f27ecee2663d8e913.zip | |
Added scripts
Diffstat (limited to '')
66 files changed, 2516 insertions, 0 deletions
diff --git a/scripts/2fa b/scripts/2fa new file mode 100755 index 0000000..23725fd --- /dev/null +++ b/scripts/2fa | |||
| @@ -0,0 +1,21 @@ | |||
| 1 | #!/bin/sh | ||
| 2 | |||
| 3 | # 2-factor authentication based on oathtool | ||
| 4 | |||
| 5 | # Usage: 2fa service [time] | ||
| 6 | |||
| 7 | # Requires: secret, oathtool | ||
| 8 | |||
| 9 | secrets_folder="$HOME/box/secrets" | ||
| 10 | |||
| 11 | if [ -z "$1" ]; then | ||
| 12 | echo "usage: 2fa service [time]" | ||
| 13 | exit 1 | ||
| 14 | fi | ||
| 15 | |||
| 16 | if [ -n "$2" ]; then | ||
| 17 | t="-N $2" | ||
| 18 | fi | ||
| 19 | |||
| 20 | secret="$(secret show "$secrets_folder/$1-2fa")" | ||
| 21 | oathtool -b --totp "$secret" $t | ||
diff --git a/scripts/aoc b/scripts/aoc new file mode 100755 index 0000000..40f94ed --- /dev/null +++ b/scripts/aoc | |||
| @@ -0,0 +1,52 @@ | |||
| 1 | #!/bin/sh | ||
| 2 | |||
| 3 | # Set up a working environment for Advent of Code (https://adventofcode.com/). | ||
| 4 | # Requires tmux, lynx, curl and a valid AOC_SESSION_COOKIE session cookie. | ||
| 5 | |||
| 6 | # usage: aoc [yyyy nn] | ||
| 7 | # If yyyy (year) and nn (day, with leading zero if single digit) are not | ||
| 8 | # specified, the current year and day are used. | ||
| 9 | |||
| 10 | editor="vi a.py" | ||
| 11 | basedir="$HOME/src/aoc" | ||
| 12 | lynx_cookie_file="$(mktemp)" | ||
| 13 | clibrowser="lynx -cookie_file=$lynx_cookie_file" | ||
| 14 | |||
| 15 | year="${1:-$(date +'%Y')}" | ||
| 16 | day="${2:-$(date +'%d')}" | ||
| 17 | daynozero="$(echo "$day" | sed 's/^0//')" | ||
| 18 | |||
| 19 | cd "$basedir/$year/$day" | ||
| 20 | |||
| 21 | # Download the puzzle input and save it to input.txt | ||
| 22 | if [ ! -e input.txt ]; then | ||
| 23 | url="https://adventofcode.com/$year/day/$daynozero/input" | ||
| 24 | curl "$url" -H "cookie: session=$AOC_SESSION_COOKIE" -o input.txt | ||
| 25 | fi | ||
| 26 | |||
| 27 | # Download the problem statement page and split out the code blocks | ||
| 28 | url="https://adventofcode.com/$year/day/$daynozero" | ||
| 29 | curl "$url" | sed -n '/<pre><code>/,/<\/code><\/pre>/ p' | (\ | ||
| 30 | i=1 | ||
| 31 | rm -f "code-$i.txt" | ||
| 32 | IFS='' | ||
| 33 | while read -r line; do | ||
| 34 | if [ "$line" = "</code></pre>" ]; then | ||
| 35 | i=$((i + 1)) | ||
| 36 | rm -f "code-$i.txt" | ||
| 37 | else | ||
| 38 | echo "$line" | sed 's/<.*>//g' >> "code-$i.txt" | ||
| 39 | fi | ||
| 40 | done | ||
| 41 | ) | ||
| 42 | |||
| 43 | # Open a tmux session with lynx in its own windows, and an editor and a | ||
| 44 | # terminal in split view. | ||
| 45 | printf 'adventofcode.com\tFALSE\t/\tTRUE\t2079722976\tsession\t%s' \ | ||
| 46 | "$AOC_SESSION_COOKIE" > "$lynx_cookie_file" | ||
| 47 | tmux new-session \; \ | ||
| 48 | send-keys "$editor" C-m \; \ | ||
| 49 | split-window -h \; \ | ||
| 50 | select-pane -t 0 \; \ | ||
| 51 | new-window \; \ | ||
| 52 | send-keys "$clibrowser $url" C-m \; | ||
diff --git a/scripts/battery-checknow b/scripts/battery-checknow new file mode 100755 index 0000000..4b76488 --- /dev/null +++ b/scripts/battery-checknow | |||
| @@ -0,0 +1,22 @@ | |||
| 1 | #!/bin/sh | ||
| 2 | |||
| 3 | # Check battery state, save result to a file. Pop up notification if changed. | ||
| 4 | # Requires: battery-status, notify-battery | ||
| 5 | |||
| 6 | file="${XDG_DATA_HOME:-$HOME/.local/share}/batterystatus" | ||
| 7 | notify=${NOTIFY:-"notify push"} | ||
| 8 | low=20 | ||
| 9 | crit=15 | ||
| 10 | |||
| 11 | new=$(battery-status) | ||
| 12 | level=$(echo "$new" | sed 's/%.*//') | ||
| 13 | status=$(echo "$new" | awk '{print $2}') | ||
| 14 | |||
| 15 | [ "$status" = "Discharging" ] && [ "$level" -le "$low" ] && status="Low" | ||
| 16 | [ "$status" = "Discharging" ] && [ "$level" -le "$crit" ] && status="Critical" | ||
| 17 | |||
| 18 | if [ "$status" != "$(cat "$file")" ] || [ "$status" = "Critical" ]; then | ||
| 19 | $notify "Battery: $(battery-status)" | ||
| 20 | fi | ||
| 21 | |||
| 22 | echo "$status" > "$file" | ||
diff --git a/scripts/battery-status b/scripts/battery-status new file mode 100755 index 0000000..c30b2c5 --- /dev/null +++ b/scripts/battery-status | |||
| @@ -0,0 +1,17 @@ | |||
| 1 | #!/bin/sh | ||
| 2 | |||
| 3 | # Send battery information to stdout | ||
| 4 | |||
| 5 | # Get battery status | ||
| 6 | battery="/sys/class/power_supply/BAT0" | ||
| 7 | message="" | ||
| 8 | |||
| 9 | if [ -d $battery ]; then | ||
| 10 | capacity=$(cat $battery/capacity) | ||
| 11 | status=$(cat $battery/status) | ||
| 12 | message="$capacity% $status" | ||
| 13 | else | ||
| 14 | message="No battery" | ||
| 15 | fi | ||
| 16 | |||
| 17 | echo "$message" | ||
diff --git a/scripts/clip b/scripts/clip new file mode 100755 index 0000000..b7bab10 --- /dev/null +++ b/scripts/clip | |||
| @@ -0,0 +1,63 @@ | |||
| 1 | #!/bin/sh | ||
| 2 | |||
| 3 | # A primitive clipboard manager. Saves the current selection and clipboard | ||
| 4 | # to a temporary file and shows all saved selections in dmenu for the user | ||
| 5 | # to select one. Duplicate selections are avoided. | ||
| 6 | |||
| 7 | # Bugs (wontfix): the program fails if it can't create the temporary | ||
| 8 | # directory with the designated name. | ||
| 9 | |||
| 10 | # Usage: clip [-m menu] | ||
| 11 | |||
| 12 | # Requires: xsel, dmenu (or similar) | ||
| 13 | |||
| 14 | menu="dmenu -i -l 25" | ||
| 15 | |||
| 16 | usage() { | ||
| 17 | echo "Usage: clip [-m MENU]" | ||
| 18 | } | ||
| 19 | |||
| 20 | while getopts "m:" opt; do | ||
| 21 | case "$opt" in | ||
| 22 | m) | ||
| 23 | menu="$OPTARG" | ||
| 24 | ;; | ||
| 25 | *) | ||
| 26 | usage | ||
| 27 | exit 1 | ||
| 28 | ;; | ||
| 29 | esac | ||
| 30 | done | ||
| 31 | shift "$((OPTIND - 1))" | ||
| 32 | |||
| 33 | dir="/tmp/clipdir" | ||
| 34 | mkdir -p "$dir" | ||
| 35 | |||
| 36 | file1="$(mktemp -p "$dir" "$(date +%s)".XXXXXX)" | ||
| 37 | file2="$(mktemp -p "$dir" "$(date +%s)"b.XXXXX)" | ||
| 38 | echo "created $file1" | ||
| 39 | echo "created $file2" | ||
| 40 | xsel > "$file1" | ||
| 41 | xsel -b > "$file2" | ||
| 42 | |||
| 43 | # Avoid duplicates | ||
| 44 | for f in "$dir"/*; do | ||
| 45 | [ "$f" != "$file1" ] && if diff "$f" "$file1"; then rm "$file1"; fi | ||
| 46 | [ "$f" != "$file2" ] && if diff "$f" "$file2"; then rm "$file2"; fi | ||
| 47 | done | ||
| 48 | |||
| 49 | list="$(mktemp)" | ||
| 50 | ls "$dir" > "$list"; | ||
| 51 | |||
| 52 | lines="$(mktemp)" | ||
| 53 | for f in "$dir"/*; do | ||
| 54 | nlines="$(wc -l "$f" | awk '{print $1}')" | ||
| 55 | fclean="$(echo "$f" | sed "s|$dir\/||")" | ||
| 56 | printf '%s (%s) | %s\n' \ | ||
| 57 | "$fclean" "$((1+nlines))" "$(head -n 1 "$f")" >> "$lines" | ||
| 58 | done | ||
| 59 | |||
| 60 | selected=$(sort -r "$lines" | $menu | awk '{print $1}') | ||
| 61 | if [ -n "$selected" ]; then | ||
| 62 | xsel -ib < "$dir/$selected" | ||
| 63 | fi | ||
diff --git a/scripts/cth b/scripts/cth new file mode 100755 index 0000000..4fd109d --- /dev/null +++ b/scripts/cth | |||
| @@ -0,0 +1,8 @@ | |||
| 1 | #!/bin/sh | ||
| 2 | |||
| 3 | # Print a function or struct defintion from a C file | ||
| 4 | # see https://sebastiano.tronto.net/blog/2022-06-12-shell-ide-sed | ||
| 5 | |||
| 6 | name=$1 | ||
| 7 | shift | ||
| 8 | sed -n "/^$name/,/^}/ p" "$@" | ||
diff --git a/scripts/cubeviz b/scripts/cubeviz new file mode 100755 index 0000000..da453c2 --- /dev/null +++ b/scripts/cubeviz | |||
| @@ -0,0 +1,62 @@ | |||
| 1 | #!/bin/sh | ||
| 2 | |||
| 3 | # Get images for a Rubik's cube state from http://cube.rider.biz/visualcube.php | ||
| 4 | # Can be used with a local installation of visualcube. | ||
| 5 | |||
| 6 | # Usage: cubeviz [type] [alg] | ||
| 7 | # See usage() for details | ||
| 8 | # Requires: curl, ImageMagick | ||
| 9 | |||
| 10 | visualcube="http://cube.rider.biz/visualcube.php" | ||
| 11 | |||
| 12 | usage() { | ||
| 13 | echo "Usage: cubeviz [type] [alg]" | ||
| 14 | echo "Types: trigger" | ||
| 15 | echo "Alg: use the standard notation" | ||
| 16 | } | ||
| 17 | |||
| 18 | trigger() { | ||
| 19 | alg="$(echo "$1" | tr "'" "3" | tr -d " ")" | ||
| 20 | w="wwwwwwwww" | ||
| 21 | y="yyyyyyyyy" | ||
| 22 | l="lllllllll" | ||
| 23 | d="ddddddddd" | ||
| 24 | t="ttttttttt" | ||
| 25 | ud="$visualcube?fmt=svg&fc=$y$l$l$y$l$l&size=200&view=plan" | ||
| 26 | top="$ud&alg=$alg" | ||
| 27 | bottom="$ud&alg=${alg}x2" | ||
| 28 | s="$visualcube?fmt=svg&fc=$y$t$t$y$t$t&size=200&r=y30x-30" | ||
| 29 | side="$s&co=30&alg=$alg" | ||
| 30 | |||
| 31 | d="pics_tmp" | ||
| 32 | f="trigger_$alg.png" | ||
| 33 | |||
| 34 | # We need some temporary files because visualcube is broken | ||
| 35 | # on Conrad's website and cannot output formats other than svg. | ||
| 36 | mkdir "$d" | ||
| 37 | curl "$top" > $d/top.svg | ||
| 38 | curl "$bottom" > $d/bottom.svg | ||
| 39 | curl "$side" > $d/side.svg | ||
| 40 | |||
| 41 | c="convert -density 400" | ||
| 42 | $c $d/top.svg $d/top.png | ||
| 43 | $c $d/bottom.svg $d/bottom.png | ||
| 44 | $c $d/side.svg $d/side.png | ||
| 45 | |||
| 46 | montage -tile 2x2 -mode concatenate \ | ||
| 47 | $d/top.png $d/side.png $d/bottom.png $f | ||
| 48 | |||
| 49 | rm -r "$d" | ||
| 50 | } | ||
| 51 | |||
| 52 | [ -z "$2" ] && usage && exit 1 | ||
| 53 | |||
| 54 | case "$1" in | ||
| 55 | trigger) | ||
| 56 | trigger "$2" | ||
| 57 | ;; | ||
| 58 | *) | ||
| 59 | usage | ||
| 60 | exit 1 | ||
| 61 | ;; | ||
| 62 | esac | ||
diff --git a/scripts/dmenu-bookmarks b/scripts/dmenu-bookmarks new file mode 100755 index 0000000..4b85367 --- /dev/null +++ b/scripts/dmenu-bookmarks | |||
| @@ -0,0 +1,14 @@ | |||
| 1 | #!/bin/sh | ||
| 2 | |||
| 3 | # A bookmark browser based on dmenu | ||
| 4 | |||
| 5 | # Usage: dmenu-bookmarks [picker options...] | ||
| 6 | |||
| 7 | # Requires: dmenu-filepicker (or similar), open-url | ||
| 8 | |||
| 9 | dir=$HOME/box/bookmarks | ||
| 10 | picker="dmenu-filepicker" | ||
| 11 | |||
| 12 | $picker "$@" "$dir" | while read -r line; do | ||
| 13 | cat "$line" | ||
| 14 | done | xargs open-url | ||
diff --git a/scripts/dmenu-dwm-sessionmanager b/scripts/dmenu-dwm-sessionmanager new file mode 100755 index 0000000..03343a0 --- /dev/null +++ b/scripts/dmenu-dwm-sessionmanager | |||
| @@ -0,0 +1,44 @@ | |||
| 1 | #!/bin/sh | ||
| 2 | |||
| 3 | # Prompts menu to shutdown/reboot/close dwm | ||
| 4 | # Requires: dmenu (or equivalent), dwm (optional) | ||
| 5 | |||
| 6 | # Usage: dmenu-dwm-sessionmanager [-m menu] | ||
| 7 | |||
| 8 | #sudo=sudo | ||
| 9 | sudo=doas | ||
| 10 | wmname="dwm" | ||
| 11 | shutdown_cmd="$sudo poweroff" | ||
| 12 | reboot_cmd="$sudo reboot" | ||
| 13 | closewm_cmd="pkill $wmname" | ||
| 14 | |||
| 15 | menu="dmenu -i" | ||
| 16 | prompt="Do you want to quit?" | ||
| 17 | |||
| 18 | usage() { | ||
| 19 | echo "Usage: dmenu-dwm-sessionmanager [-m MENU]" | ||
| 20 | } | ||
| 21 | |||
| 22 | while getopts "m:" opt; do | ||
| 23 | case "$opt" in | ||
| 24 | m) | ||
| 25 | menu="$OPTARG" | ||
| 26 | ;; | ||
| 27 | *) | ||
| 28 | usage | ||
| 29 | exit 1 | ||
| 30 | ;; | ||
| 31 | esac | ||
| 32 | done | ||
| 33 | shift $((OPTIND - 1)) | ||
| 34 | |||
| 35 | value=$(printf 'Shutdown\nReboot\nQuit dwm\n' | $menu -p "$prompt") | ||
| 36 | |||
| 37 | if [ "$value" = "Shutdown" ]; then | ||
| 38 | $shutdown_cmd | ||
| 39 | elif [ "$value" = "Reboot" ]; then | ||
| 40 | $reboot_cmd | ||
| 41 | elif [ "$value" = "Quit $wmname" ]; then | ||
| 42 | $closewm_cmd | ||
| 43 | fi | ||
| 44 | |||
diff --git a/scripts/dmenu-filepicker b/scripts/dmenu-filepicker new file mode 100755 index 0000000..288cac9 --- /dev/null +++ b/scripts/dmenu-filepicker | |||
| @@ -0,0 +1,47 @@ | |||
| 1 | #!/bin/sh | ||
| 2 | |||
| 3 | # A dmenu-based file picker (prints selected file to stdout) | ||
| 4 | # Requires: dmenu (or similar) | ||
| 5 | |||
| 6 | # Usage: dmenu-filepicker [-m menu] [path] | ||
| 7 | |||
| 8 | menu="dmenu -i -l 15" | ||
| 9 | |||
| 10 | usage() { | ||
| 11 | echo "Usage: dmenu-filepicker [-m MENU] [PATH]" | ||
| 12 | } | ||
| 13 | |||
| 14 | while getopts "m:" opt; do | ||
| 15 | case "$opt" in | ||
| 16 | m) | ||
| 17 | menu="$OPTARG" | ||
| 18 | ;; | ||
| 19 | *) | ||
| 20 | usage | ||
| 21 | exit 1 | ||
| 22 | ;; | ||
| 23 | esac | ||
| 24 | done | ||
| 25 | shift $((OPTIND - 1)) | ||
| 26 | |||
| 27 | fullpath=$(realpath "${@:-"$(pwd)"}") | ||
| 28 | |||
| 29 | while true; do | ||
| 30 | if [ "$sel" = "." ]; then | ||
| 31 | echo "$fullpath" | sed 's|/\.||' | ||
| 32 | break | ||
| 33 | elif [ -d "$fullpath" ] || [ -z "$fullpath" ]; then | ||
| 34 | if [ -z "$fullpath" ]; then fp="/"; else fp="$fullpath"; fi | ||
| 35 | sel=$(ls -a "$fp" | sed 's|.*/||' | $menu) | ||
| 36 | if [ "$sel" = ".." ]; then | ||
| 37 | fullpath=$(echo "$fullpath" | sed "s|/[^/]*$||") | ||
| 38 | else | ||
| 39 | fullpath=$(echo "$sel" | sed "s|^|$fullpath/|") | ||
| 40 | fi | ||
| 41 | else | ||
| 42 | echo "$fullpath" | ||
| 43 | break | ||
| 44 | fi | ||
| 45 | |||
| 46 | [ -z "$sel" ] && break | ||
| 47 | done | ||
diff --git a/scripts/dmenu-screenshot b/scripts/dmenu-screenshot new file mode 100755 index 0000000..e2e8adf --- /dev/null +++ b/scripts/dmenu-screenshot | |||
| @@ -0,0 +1,40 @@ | |||
| 1 | #!/bin/sh | ||
| 2 | |||
| 3 | # Screenshot utility | ||
| 4 | # Requires: dmenu (or similar), imagemagick | ||
| 5 | |||
| 6 | # Usage: dmenu-screenshot [-m menu] | ||
| 7 | |||
| 8 | usage() { | ||
| 9 | echo "Usage: dmenu-screenshot [-m MENU]" | ||
| 10 | } | ||
| 11 | |||
| 12 | menu="dmenu -i" | ||
| 13 | prompt="Select type of screenshot:" | ||
| 14 | |||
| 15 | while getopts "m:" opt; do | ||
| 16 | case "$opt" in | ||
| 17 | m) | ||
| 18 | menu="$OPTARG" | ||
| 19 | ;; | ||
| 20 | *) | ||
| 21 | usage | ||
| 22 | exit 1 | ||
| 23 | ;; | ||
| 24 | esac | ||
| 25 | done | ||
| 26 | shift $((OPTIND - 1)) | ||
| 27 | |||
| 28 | folder="$HOME/box/pictures/screenshots" | ||
| 29 | filename="screenshot_$(date +%Y-%m-%d-%H%M%S).png" | ||
| 30 | filepath="${folder}/${filename}" | ||
| 31 | |||
| 32 | t=$(printf 'Full\nSelection\n' | $menu -p "$prompt") | ||
| 33 | if [ "$t" = "Full" ]; then | ||
| 34 | op="-window root" | ||
| 35 | else | ||
| 36 | pkill xbanish # otherwise I can't use mouse to select area | ||
| 37 | fi | ||
| 38 | |||
| 39 | [ -n "$t" ] && sleep 0.1 && import $op "$filepath" | ||
| 40 | spawn xbanish # This can be removed if you don't use xbanish | ||
diff --git a/scripts/dmenu-unmount b/scripts/dmenu-unmount new file mode 100755 index 0000000..93c8186 --- /dev/null +++ b/scripts/dmenu-unmount | |||
| @@ -0,0 +1,49 @@ | |||
| 1 | #!/bin/sh | ||
| 2 | |||
| 3 | # Prompts selection for mounted devices and unmounts the selected one | ||
| 4 | # Requires: udevil, dmenu (or similar), notify-send or similar (optional) | ||
| 5 | |||
| 6 | # Usage: dmenu-unmount [-m menu] [-w writer] | ||
| 7 | # Example: dmenu-unmount -m slmenu -w echo | ||
| 8 | |||
| 9 | menu=dmenu | ||
| 10 | writeout=${NOTIFY:-"notify push"} | ||
| 11 | |||
| 12 | usage() { | ||
| 13 | echo "Usage: dmenu-unmount [-m MENU] [-w WRITER]" | ||
| 14 | echo "Example: dmenu-unmount -m slmenu -w echo" | ||
| 15 | } | ||
| 16 | |||
| 17 | while getopts "m:w:" opt; do | ||
| 18 | case "$opt" in | ||
| 19 | m) | ||
| 20 | menu="$OPTARG" | ||
| 21 | ;; | ||
| 22 | w) | ||
| 23 | writeout="$OPTARG" | ||
| 24 | ;; | ||
| 25 | *) | ||
| 26 | usage | ||
| 27 | exit 1 | ||
| 28 | ;; | ||
| 29 | esac | ||
| 30 | done | ||
| 31 | shift $((OPTIND - 1)) | ||
| 32 | |||
| 33 | listdev=$(grep "media" /proc/mounts | sed 's/\/media.*\///g' | \ | ||
| 34 | awk '{print $1" ("$2")"}') | ||
| 35 | |||
| 36 | if [ -z "$listdev" ]; then | ||
| 37 | $writeout "Nothing to unmount" | ||
| 38 | else | ||
| 39 | seldev=$(echo "$listdev" | $menu | awk '{print $1}') | ||
| 40 | if [ -n "$seldev" ]; then | ||
| 41 | udevil unmount "$seldev" | ||
| 42 | failed=$(udevil info "$seldev" | grep mounted | awk '{print $3}') | ||
| 43 | if [ "$failed" -eq 1 ]; then | ||
| 44 | $writeout "Unmount FAILED" "Device is still mounted!" | ||
| 45 | else | ||
| 46 | $writeout "Device unmounted" | ||
| 47 | fi | ||
| 48 | fi | ||
| 49 | fi | ||
diff --git a/scripts/dmenu-urlselect b/scripts/dmenu-urlselect new file mode 100755 index 0000000..a988826 --- /dev/null +++ b/scripts/dmenu-urlselect | |||
| @@ -0,0 +1,28 @@ | |||
| 1 | #!/bin/sh | ||
| 2 | |||
| 3 | # Finds all URLs in stdin and prompts a dmenu choice, then writes the selected | ||
| 4 | # url to stdout. | ||
| 5 | # Requires: dmenu (or similar), urlgrep | ||
| 6 | |||
| 7 | # Usage: dmenu-urlselect [-m menu] | ||
| 8 | |||
| 9 | menu="dmenu -i -l 20" | ||
| 10 | |||
| 11 | usage() { | ||
| 12 | echo "Usage: dmenu-urlselect [-m MENU]" | ||
| 13 | } | ||
| 14 | |||
| 15 | while getopts "m:" opt; do | ||
| 16 | case "$opt" in | ||
| 17 | m) | ||
| 18 | menu="$OPTARG" | ||
| 19 | ;; | ||
| 20 | *) | ||
| 21 | usage | ||
| 22 | exit 1 | ||
| 23 | ;; | ||
| 24 | esac | ||
| 25 | done | ||
| 26 | shift $((OPTIND - 1)) | ||
| 27 | |||
| 28 | urlgrep | $menu | ||
diff --git a/scripts/event b/scripts/event new file mode 100755 index 0000000..16991cf --- /dev/null +++ b/scripts/event | |||
| @@ -0,0 +1,154 @@ | |||
| 1 | #!/bin/sh | ||
| 2 | |||
| 3 | # Manage events (replacement for https://git.tronto.net/sdep) | ||
| 4 | |||
| 5 | # Usage: event [command [argument]] | ||
| 6 | # See usage() for details | ||
| 7 | |||
| 8 | file="$HOME/box/events" # Change to $XDG_DATA_HOME/events or whatever | ||
| 9 | editor=${EDITOR:-vi} | ||
| 10 | |||
| 11 | usage() { | ||
| 12 | echo "Usage: event [command]" | ||
| 13 | echo "Commands:" | ||
| 14 | echo " add [day] Add a new event (default date: none)" | ||
| 15 | echo " day: today, t; tomorrow, tm" | ||
| 16 | echo " clear Sort and cleanup event file" | ||
| 17 | echo " edit Open event file in $editor" | ||
| 18 | echo " list [date] List all events on date (default: all events)" | ||
| 19 | echo " date: now, n; today, t; tomorrow, tm;" | ||
| 20 | echo " week, w; nextweek, nw;" | ||
| 21 | echo " future, f; past, p" | ||
| 22 | } | ||
| 23 | |||
| 24 | secondstoday() { | ||
| 25 | if [ "$(uname)" = "Linux" ]; then | ||
| 26 | date -d @$1 +'%Y-%m-%d' | ||
| 27 | else # Assume BSD date | ||
| 28 | date -r $1 +'%Y-%m-%d' | ||
| 29 | fi | ||
| 30 | } | ||
| 31 | |||
| 32 | secondstomin() { | ||
| 33 | if [ "$(uname)" = "Linux" ]; then | ||
| 34 | date -d @$1 +'%Y-%m-%d %H:%M' | ||
| 35 | else # Assume BSD date | ||
| 36 | date -r $1 +'%Y-%m-%d %H:%M' | ||
| 37 | fi | ||
| 38 | } | ||
| 39 | |||
| 40 | datetoseconds() { | ||
| 41 | # Read date in YYYY-MM-DD HH:MM format | ||
| 42 | if [ "$(uname)" = "Linux" ]; then | ||
| 43 | date -d "$1 $2" +'%s' | ||
| 44 | else # Assume BSD date | ||
| 45 | date -f '%Y-%m-%d %H:%M' -j "$1 $2" +'%s' | ||
| 46 | fi | ||
| 47 | } | ||
| 48 | |||
| 49 | today() { echo "$(date +'%Y-%m-%d') 00:00"; } | ||
| 50 | dayplus() { | ||
| 51 | d="$1" | ||
| 52 | n="$(datetoseconds $(today))" | ||
| 53 | echo "$((n+d*60*60*24))" | ||
| 54 | } | ||
| 55 | monday() { d="$(date +%u)"; dayplus "$((1-d))"; } | ||
| 56 | monday1() { d="$(date +%u)"; dayplus "$((8-d))"; } | ||
| 57 | monday2() { d="$(date +%u)"; dayplus "$((15-d))"; } | ||
| 58 | daydiff() { | ||
| 59 | ar="$1" | ||
| 60 | d="$(date +%u)" | ||
| 61 | case "$ar" in | ||
| 62 | mon|monday) | ||
| 63 | w=1 | ||
| 64 | ;; | ||
| 65 | tue|tuesday) | ||
| 66 | w=2 | ||
| 67 | ;; | ||
| 68 | wed|wednesday) | ||
| 69 | w=3 | ||
| 70 | ;; | ||
| 71 | thu|thursday) | ||
| 72 | w=4 | ||
| 73 | ;; | ||
| 74 | fri|friday) | ||
| 75 | w=5 | ||
| 76 | ;; | ||
| 77 | sat|saturday) | ||
| 78 | w=6 | ||
| 79 | ;; | ||
| 80 | sun|sunday) | ||
| 81 | w=7 | ||
| 82 | ;; | ||
| 83 | *) | ||
| 84 | w=0 | ||
| 85 | ;; | ||
| 86 | esac | ||
| 87 | [ "$w" = "0" ] && echo "" || echo "$(((w-d+7) % 7))" | ||
| 88 | } | ||
| 89 | |||
| 90 | secondsline() { | ||
| 91 | # TODO: this function is not needed, need similar one with weekday | ||
| 92 | line="$(cat)" | ||
| 93 | s="$(datetoseconds $line)" | ||
| 94 | t="$(echo "$line" | sed -E 's/....-..-.. .{1,2}:.. //g')" | ||
| 95 | echo "$s $t" | ||
| 96 | } | ||
| 97 | |||
| 98 | filterlines() { | ||
| 99 | while read -r line; do | ||
| 100 | cleanline="$(echo "$line" | awk '{print $1, $2}')" | ||
| 101 | s="$(datetoseconds $cleanline)" | ||
| 102 | [ "$s" -ge "$1" ] && [ "$s" -lt "$2" ] && echo "$line" | ||
| 103 | done | ||
| 104 | } | ||
| 105 | |||
| 106 | list() { | ||
| 107 | if [ -z "$1" ]; then | ||
| 108 | cat | ||
| 109 | elif [ "$1" = "now" ] || [ "$1" = "n" ]; then | ||
| 110 | grep "$(date +'%Y-%m-%d %H:%M')" | ||
| 111 | elif [ "$1" = "today" ] || [ "$1" = "t" ]; then | ||
| 112 | grep "$(date +'%Y-%m-%d')" | ||
| 113 | elif [ "$1" = "tomorrow" ] || [ "$1" = "tm" ]; then | ||
| 114 | grep "$(secondstoday $(dayplus 1))" | ||
| 115 | elif [ "$1" = "week" ] || [ "$1" = "w" ]; then | ||
| 116 | filterlines "$(monday)" "$(monday1)" | ||
| 117 | elif [ "$1" = "nextweek" ] || [ "$1" = "nw" ]; then | ||
| 118 | filterlines "$(monday1)" "$(monday2)" | ||
| 119 | elif [ "$1" = "future" ] || [ "$1" = "f" ]; then | ||
| 120 | filterlines "$(date +%s)" "9999999999" | ||
| 121 | elif [ "$1" = "past" ] || [ "$1" = "p" ]; then | ||
| 122 | filterlines "0" "$(date +%s)" | ||
| 123 | fi | ||
| 124 | } | ||
| 125 | |||
| 126 | case "$1" in | ||
| 127 | add) | ||
| 128 | if [ "$2" = "today" ] || [ "$2" = "t" ]; then | ||
| 129 | d="$(date +'%Y-%m-%d')" | ||
| 130 | elif [ "$2" = "tomorrow" ] || [ "$2" = "tm" ]; then | ||
| 131 | d="$(secondstoday $(dayplus 1))" | ||
| 132 | elif [ -n "$2" ]; then | ||
| 133 | d="$(secondstoday $(dayplus $(daydiff $2)))" | ||
| 134 | fi | ||
| 135 | [ -n "$d" ] && printf '%s ' "$d" | ||
| 136 | read -r line | ||
| 137 | [ -n "$d" ] && line="$d $line" | ||
| 138 | echo "$line" >> "$file" | ||
| 139 | ;; | ||
| 140 | clear) | ||
| 141 | tmp=$(mktemp) | ||
| 142 | cat "$file" | list future | sort > "$tmp" | ||
| 143 | mv "$tmp" "$file" | ||
| 144 | ;; | ||
| 145 | edit) | ||
| 146 | "$editor" "$file" | ||
| 147 | ;; | ||
| 148 | list) | ||
| 149 | cat "$file" | list $2 | sort | ||
| 150 | ;; | ||
| 151 | *) | ||
| 152 | usage | ||
| 153 | ;; | ||
| 154 | esac | ||
diff --git a/scripts/feed b/scripts/feed new file mode 100755 index 0000000..9e14dab --- /dev/null +++ b/scripts/feed | |||
| @@ -0,0 +1,97 @@ | |||
| 1 | #!/bin/sh | ||
| 2 | |||
| 3 | # RSS feed manager | ||
| 4 | |||
| 5 | # Requires: sfeed, sfeed_plain (get), dmenu, open-url (menu) | ||
| 6 | |||
| 7 | # Usage: feed [-m menu] [get|menu|clear|show] | ||
| 8 | |||
| 9 | dir=$HOME/box/sfeed | ||
| 10 | feeddir=$dir/urls | ||
| 11 | destdir=$dir/new | ||
| 12 | readdir=$dir/last | ||
| 13 | menu="${FEEDMENU:-dmenu -l 20 -i}" | ||
| 14 | urlopener=open-url | ||
| 15 | |||
| 16 | usage() { | ||
| 17 | echo "Usage: feed [get|menu|clear|show]" | ||
| 18 | } | ||
| 19 | |||
| 20 | getnew() { | ||
| 21 | for f in "$feeddir"/*; do | ||
| 22 | read -r url < "$f" | ||
| 23 | name=$(basename "$f") | ||
| 24 | printf '%s... ' "$name" | ||
| 25 | |||
| 26 | d="$destdir/$name" | ||
| 27 | r="$readdir/$name" | ||
| 28 | |||
| 29 | [ -f "$r" ] && read -r lr < "$r" || lr=0 | ||
| 30 | |||
| 31 | # Get new feed items | ||
| 32 | tmp=$(mktemp) | ||
| 33 | curl -s "$url" | sfeed | \ | ||
| 34 | awk -v lr="$lr" '$1 > lr {print $0}' | \ | ||
| 35 | tee "$tmp" | sfeed_plain >> "$d" | ||
| 36 | |||
| 37 | # Update last time stamp | ||
| 38 | awk -v lr="$lr" '$1 > lr {lr=$1} END {print lr}' <"$tmp" >"$r" | ||
| 39 | |||
| 40 | printf 'downloaded\n' | ||
| 41 | done | ||
| 42 | } | ||
| 43 | |||
| 44 | show() { | ||
| 45 | for f in "$destdir"/*; do | ||
| 46 | ff=$(basename "$f") | ||
| 47 | if [ -s "$f" ]; then | ||
| 48 | sort -r "$f" | while read -r line; do | ||
| 49 | printf '%20s %s\n' "$ff" "$line" | ||
| 50 | done | ||
| 51 | fi | ||
| 52 | done | ||
| 53 | } | ||
| 54 | |||
| 55 | selectmenu() { | ||
| 56 | $menu | awk '{print $NF}' | xargs $urlopener | ||
| 57 | } | ||
| 58 | |||
| 59 | while getopts "m:" opt; do | ||
| 60 | case "$opt" in | ||
| 61 | m) | ||
| 62 | menu="$OPTARG" | ||
| 63 | ;; | ||
| 64 | *) | ||
| 65 | usage | ||
| 66 | exit 1 | ||
| 67 | ;; | ||
| 68 | esac | ||
| 69 | done | ||
| 70 | |||
| 71 | shift $((OPTIND - 1)) | ||
| 72 | |||
| 73 | if [ -z "$1" ]; then | ||
| 74 | usage | ||
| 75 | exit 1 | ||
| 76 | fi | ||
| 77 | |||
| 78 | case "$1" in | ||
| 79 | get) | ||
| 80 | getnew | ||
| 81 | countnew=$(cat "$destdir"/* | wc -l) | ||
| 82 | echo "$countnew new feed items" | ||
| 83 | ;; | ||
| 84 | menu) | ||
| 85 | show | selectmenu | ||
| 86 | ;; | ||
| 87 | clear) | ||
| 88 | rm -r "$destdir"/* | ||
| 89 | ;; | ||
| 90 | show) | ||
| 91 | show | ||
| 92 | ;; | ||
| 93 | *) | ||
| 94 | usage | ||
| 95 | exit 1 | ||
| 96 | ;; | ||
| 97 | esac | ||
diff --git a/scripts/ffmpeg-facecam b/scripts/ffmpeg-facecam new file mode 100755 index 0000000..d15a052 --- /dev/null +++ b/scripts/ffmpeg-facecam | |||
| @@ -0,0 +1,6 @@ | |||
| 1 | #!/bin/sh | ||
| 2 | |||
| 3 | # Opens a window streaming from the webcam | ||
| 4 | # Requires: ffplay (part of ffmpeg) | ||
| 5 | |||
| 6 | ffplay -i /dev/video0 | ||
diff --git a/scripts/ffmpeg-screenrecord b/scripts/ffmpeg-screenrecord new file mode 100755 index 0000000..bef2167 --- /dev/null +++ b/scripts/ffmpeg-screenrecord | |||
| @@ -0,0 +1,8 @@ | |||
| 1 | #!/bin/sh | ||
| 2 | |||
| 3 | # One-line screen record with ffmpeg (I always forget the command) | ||
| 4 | # Requires: ffmpeg | ||
| 5 | |||
| 6 | outfile=${1:-output.mkv} | ||
| 7 | |||
| 8 | ffmpeg -f x11grab -i :0 -f pulse -i default "$outfile" | ||
diff --git a/scripts/mail-compose b/scripts/mail-compose new file mode 100755 index 0000000..c7002ce --- /dev/null +++ b/scripts/mail-compose | |||
| @@ -0,0 +1,6 @@ | |||
| 1 | #!/bin/sh | ||
| 2 | |||
| 3 | # Open a mail composer. | ||
| 4 | # Requires: mblaze, terminal | ||
| 5 | |||
| 6 | terminal mcom "$@" | ||
diff --git a/scripts/mergepdf b/scripts/mergepdf new file mode 100755 index 0000000..5de7e19 --- /dev/null +++ b/scripts/mergepdf | |||
| @@ -0,0 +1,26 @@ | |||
| 1 | #!/bin/sh | ||
| 2 | |||
| 3 | # Merge multiple pdf files into one | ||
| 4 | # Requires: gs | ||
| 5 | |||
| 6 | # Usage: mergepdf [-o outname] file1.pdf file2.pdf ... | ||
| 7 | |||
| 8 | outname=merged.pdf | ||
| 9 | |||
| 10 | usage() { | ||
| 11 | echo "Usage: mergepdf [-o OUTFILE] file1.pdf file2.pdf ..." | ||
| 12 | } | ||
| 13 | |||
| 14 | while getopts "o:" opt; do | ||
| 15 | case "$opt" in | ||
| 16 | o) | ||
| 17 | outname="$OPTARG" | ||
| 18 | ;; | ||
| 19 | *) | ||
| 20 | usage | ||
| 21 | ;; | ||
| 22 | esac | ||
| 23 | done | ||
| 24 | shift $((OPTIND - 1)) | ||
| 25 | |||
| 26 | gs -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile="$outname" "$@" | ||
diff --git a/scripts/notify b/scripts/notify new file mode 100755 index 0000000..38e1793 --- /dev/null +++ b/scripts/notify | |||
| @@ -0,0 +1,37 @@ | |||
| 1 | #!/bin/sh | ||
| 2 | |||
| 3 | # Simple notification manager. | ||
| 4 | # Notifications are sent to a log file together with a time stamp. | ||
| 5 | # Requires: xroot-update (optional) | ||
| 6 | |||
| 7 | # Usage: notify [push MESSAGE | clean | edit | show] | ||
| 8 | |||
| 9 | update=xroot-update | ||
| 10 | file="${XDG_DATA_HOME:-.local/share}/notify" | ||
| 11 | date=$(date +'%H:%M') | ||
| 12 | |||
| 13 | usage() { | ||
| 14 | echo "Usage: notify [push MESSAGE | clean | edit | show]" | ||
| 15 | } | ||
| 16 | |||
| 17 | touch "$file" | ||
| 18 | case "$1" in | ||
| 19 | push) | ||
| 20 | echo "[$date $2]" >> "$file" | ||
| 21 | $update | ||
| 22 | ;; | ||
| 23 | clean) | ||
| 24 | printf "" > "$file" | ||
| 25 | $update | ||
| 26 | ;; | ||
| 27 | edit) | ||
| 28 | $EDITOR "$file" | ||
| 29 | ;; | ||
| 30 | show) | ||
| 31 | cat "$file" | ||
| 32 | ;; | ||
| 33 | *) | ||
| 34 | usage | ||
| 35 | exit 1 | ||
| 36 | ;; | ||
| 37 | esac | ||
diff --git a/scripts/old/brightness b/scripts/old/brightness new file mode 100755 index 0000000..a7294fb --- /dev/null +++ b/scripts/old/brightness | |||
| @@ -0,0 +1,16 @@ | |||
| 1 | #!/bin/sh | ||
| 2 | |||
| 3 | # Increase / decrease brightness, and pops up a notification | ||
| 4 | # Requires: xbacklight, a notification program such as herbe or notify-send | ||
| 5 | # Usage: brightness {inc|dec} n | ||
| 6 | |||
| 7 | # ksh completion | ||
| 8 | # set -A complete_brightness_1 inc dec | ||
| 9 | # set -A complete_brightness_2 5 | ||
| 10 | |||
| 11 | #notify="notify-send" | ||
| 12 | notify="herbe" | ||
| 13 | |||
| 14 | pkill herbe # comment this too if not using herbe | ||
| 15 | |||
| 16 | xbacklight -$1 $2 && $notify "Brightness: $(xbacklight | sed 's/\..*$//')%" | ||
diff --git a/scripts/old/dmenu-filepicker-old b/scripts/old/dmenu-filepicker-old new file mode 100755 index 0000000..532fb82 --- /dev/null +++ b/scripts/old/dmenu-filepicker-old | |||
| @@ -0,0 +1,31 @@ | |||
| 1 | #!/bin/sh | ||
| 2 | |||
| 3 | # A dmenu-based file picker (prints selected file to stdout) | ||
| 4 | # Requires: dmenu (or similar) | ||
| 5 | # Usage: dmenu-filepicker [path] | ||
| 6 | |||
| 7 | menu=${MENU:-dmenu} | ||
| 8 | menuopts="-i -l 15" | ||
| 9 | |||
| 10 | basedir="$(pwd)" | ||
| 11 | |||
| 12 | next="${@:-$(pwd)}" | ||
| 13 | |||
| 14 | while true; do | ||
| 15 | if [ -z "$next" ]; then | ||
| 16 | break | ||
| 17 | elif [ "$next" = "." ]; then | ||
| 18 | pwd | ||
| 19 | break | ||
| 20 | elif [ -d "$next" ]; then | ||
| 21 | cd "$next" | ||
| 22 | next=$(ls -a | $menu $menuopts) | ||
| 23 | else | ||
| 24 | echo "$next" | while read line; do | ||
| 25 | echo "$(pwd)/$line" | ||
| 26 | done | ||
| 27 | break | ||
| 28 | fi | ||
| 29 | done | ||
| 30 | |||
| 31 | cd "$basedir" | ||
diff --git a/scripts/old/dunst-toggle b/scripts/old/dunst-toggle new file mode 100755 index 0000000..2de2343 --- /dev/null +++ b/scripts/old/dunst-toggle | |||
| @@ -0,0 +1,14 @@ | |||
| 1 | #!/bin/sh | ||
| 2 | |||
| 3 | # Toggle "do not disturbe" mode with dunst | ||
| 4 | # Requires: dunst, notify-send | ||
| 5 | |||
| 6 | if [ "$(dunstctl is-paused)" = "false" ]; then | ||
| 7 | notify-send -t 3000 "Notifications: OFF" "Notifications will be hidden" | ||
| 8 | sleep 3 | ||
| 9 | dunstctl set-paused true | ||
| 10 | else | ||
| 11 | dunstctl set-paused false | ||
| 12 | notify-send -t 3000 "Notifications: ON" "Notifications reactivated" | ||
| 13 | fi | ||
| 14 | |||
diff --git a/scripts/old/gfmt b/scripts/old/gfmt new file mode 100755 index 0000000..d38351f --- /dev/null +++ b/scripts/old/gfmt | |||
| @@ -0,0 +1,9 @@ | |||
| 1 | #!/bin/sh | ||
| 2 | |||
| 3 | # Format text from gemtext format to short lines with double \n | ||
| 4 | |||
| 5 | # TODO: remove double spacing from within ``` | ||
| 6 | |||
| 7 | sed 's/ //' | \ | ||
| 8 | sed 'a\\' | \ | ||
| 9 | fold -sw 80 | ||
diff --git a/scripts/old/mail-checknow b/scripts/old/mail-checknow new file mode 100755 index 0000000..188042b --- /dev/null +++ b/scripts/old/mail-checknow | |||
| @@ -0,0 +1,18 @@ | |||
| 1 | #!/bin/sh | ||
| 2 | |||
| 3 | # Check for new email, save result to file. | ||
| 4 | # Requires: mpop, notify-send or similar | ||
| 5 | |||
| 6 | file="$XDG_DATA_HOME/newmail" | ||
| 7 | #notify="notify-send" | ||
| 8 | notify=herbe | ||
| 9 | |||
| 10 | l=$(cat "$file") | ||
| 11 | n=$(mpop -s | awk '/new*./{print $2}') | ||
| 12 | |||
| 13 | if [ -n "$n" ]; then | ||
| 14 | echo "$n" > "$file" | ||
| 15 | if [ "$n" != "no" ] && [ "$l" != "$n" ]; then | ||
| 16 | $notify "New email ($n)" | ||
| 17 | fi | ||
| 18 | fi | ||
diff --git a/scripts/old/mblaze-extras b/scripts/old/mblaze-extras new file mode 100755 index 0000000..7a4fe8a --- /dev/null +++ b/scripts/old/mblaze-extras | |||
| @@ -0,0 +1,61 @@ | |||
| 1 | #!/bin/sh | ||
| 2 | |||
| 3 | # Useful extra commands for mblaze | ||
| 4 | |||
| 5 | # Requires: mblaze, mpop | ||
| 6 | |||
| 7 | # Usage: mblaze-extras command | ||
| 8 | # List of commands: | ||
| 9 | # get [filter] | ||
| 10 | # pick [field] | ||
| 11 | # save | ||
| 12 | # scan [folder] | ||
| 13 | |||
| 14 | menu=${MENU:-dmenu} | ||
| 15 | mdir=$HOME/mail | ||
| 16 | mpopdir=$HOME/.config/mpop | ||
| 17 | |||
| 18 | mbextra_scan() { | ||
| 19 | folder=${1:-inbox} | ||
| 20 | mlist -t $mdir/$folder | mthread | mseq -S | ||
| 21 | mscan | ||
| 22 | } | ||
| 23 | |||
| 24 | mbextra_get() { | ||
| 25 | mpop --filter=$mpopdir/filter-$1.sh | ||
| 26 | minc -q $mdir/inbox | ||
| 27 | mbextra_scan inbox | ||
| 28 | } | ||
| 29 | |||
| 30 | mbextra_pick() { | ||
| 31 | field=$1 | ||
| 32 | shift | ||
| 33 | mpick -t "$field =~~ \"$@\"" | ||
| 34 | } | ||
| 35 | |||
| 36 | mbextra_save() { | ||
| 37 | dir=$2 | ||
| 38 | [ -z "$dir" ] && dir=$(dmenu-filepicker) | ||
| 39 | mkdir -p "$dir" | ||
| 40 | |||
| 41 | if [ ! -d "$dir" ]; then | ||
| 42 | echo "No directory selected, skipping." | ||
| 43 | else | ||
| 44 | cd "$dir" | ||
| 45 | mshow -x $1 | ||
| 46 | fi | ||
| 47 | } | ||
| 48 | |||
| 49 | if [ -z "$1" ]; then | ||
| 50 | echo "Usage: mblaze-extras COMMAND" | ||
| 51 | elif [ "$1" = "scan" ]; then | ||
| 52 | mbextra_scan $2 | ||
| 53 | elif [ "$1" = "get" ]; then | ||
| 54 | mbextra_get $2 | ||
| 55 | elif [ "$1" = "save" ]; then | ||
| 56 | shift | ||
| 57 | mbextra_save $@ | ||
| 58 | elif [ "$1" = "pick" ]; then | ||
| 59 | shift | ||
| 60 | mbextra_pick $@ | ||
| 61 | fi | ||
diff --git a/scripts/old/notify-battery b/scripts/old/notify-battery new file mode 100755 index 0000000..0294b70 --- /dev/null +++ b/scripts/old/notify-battery | |||
| @@ -0,0 +1,10 @@ | |||
| 1 | #!/bin/sh | ||
| 2 | |||
| 3 | # Popup battery notification, based on the script battery-status | ||
| 4 | |||
| 5 | # Requires: notify-send or similar | ||
| 6 | |||
| 7 | #notify=notify-send | ||
| 8 | notify=herbe | ||
| 9 | |||
| 10 | $notify "Battery" "$(battery-status)" | ||
diff --git a/scripts/old/notify-status b/scripts/old/notify-status new file mode 100755 index 0000000..73a9435 --- /dev/null +++ b/scripts/old/notify-status | |||
| @@ -0,0 +1,7 @@ | |||
| 1 | #!/bin/sh | ||
| 2 | |||
| 3 | # Simple script to send a notification displaying the output of status | ||
| 4 | |||
| 5 | # Requires: status, herbe (or similar, e.g. notify-send) | ||
| 6 | |||
| 7 | herbe "$(status '\n\n')" | ||
diff --git a/scripts/old/notify-time b/scripts/old/notify-time new file mode 100755 index 0000000..4b77c74 --- /dev/null +++ b/scripts/old/notify-time | |||
| @@ -0,0 +1,15 @@ | |||
| 1 | #!/bin/sh | ||
| 2 | |||
| 3 | # Little notification to show time and date | ||
| 4 | |||
| 5 | # Requires: notify-send or similar | ||
| 6 | |||
| 7 | # TODO: check if it still works with notify-send | ||
| 8 | |||
| 9 | #notify=notify-send | ||
| 10 | notify=herbe | ||
| 11 | |||
| 12 | t=$(date +"%H:%M:%S") | ||
| 13 | d=$(date +"%d %B %Y, %A") | ||
| 14 | |||
| 15 | $notify "$t" "$d" | ||
diff --git a/scripts/old/sfeed-browser b/scripts/old/sfeed-browser new file mode 100755 index 0000000..774c808 --- /dev/null +++ b/scripts/old/sfeed-browser | |||
| @@ -0,0 +1,80 @@ | |||
| 1 | #!/bin/sh | ||
| 2 | |||
| 3 | # This script is based on sfeed (https://codemadness.org/sfeed.html), but | ||
| 4 | # it allows you organize your feeds in directories and subdirectories. | ||
| 5 | # In your $sfd directory (see below) you should have two folders: | ||
| 6 | # urls: it can contain more subfolders and files. Each file should contain | ||
| 7 | # only one line with the url to the feed. The name of the file is the | ||
| 8 | # name of the feed (it can contains spaces and such). | ||
| 9 | # files: this one can be empty, it will be filled with the feed files | ||
| 10 | # An older version of this script also marked viewed items and removed | ||
| 11 | # them before displaying the choice of feeds. Contact me if you are interested | ||
| 12 | # in using it. | ||
| 13 | |||
| 14 | # Requires: sfeed, dmenu-file-picker (or similar), open-url (or similar) | ||
| 15 | |||
| 16 | # Usage: sfeed-browser [-m menu] | ||
| 17 | |||
| 18 | filepicker="dmenu-filepicker" # Try "nnn -p -" | ||
| 19 | menu="dmenu -l 35 -i" | ||
| 20 | urlopener=open-url | ||
| 21 | sfd="$HOME/box/sfeed" | ||
| 22 | showlast=10 | ||
| 23 | |||
| 24 | usage() { | ||
| 25 | echo "sfeed-browser [-m MENU]" | ||
| 26 | } | ||
| 27 | |||
| 28 | while getopts "m:" opt; do | ||
| 29 | case "$opt" in | ||
| 30 | m) | ||
| 31 | menu="$OPTARG" | ||
| 32 | ;; | ||
| 33 | *) | ||
| 34 | usage | ||
| 35 | exit 1 | ||
| 36 | ;; | ||
| 37 | esac | ||
| 38 | done | ||
| 39 | |||
| 40 | # Might add more stuff later | ||
| 41 | fixurl() { | ||
| 42 | sed 's/old\.reddit\.com/reddit\.com/' | ||
| 43 | } | ||
| 44 | |||
| 45 | dirtofeedpaths() { | ||
| 46 | while read -r line; do | ||
| 47 | find "$line" | while read -r fname; do | ||
| 48 | [ -f "$fname" ] && echo "$fname" | ||
| 49 | done | ||
| 50 | done | ||
| 51 | } | ||
| 52 | |||
| 53 | pathstosfeedrc() { | ||
| 54 | printf 'sfeedpath="%s"\n\nfeeds() {\n' "$sfd/files" | ||
| 55 | while read -r line; do | ||
| 56 | feedname=$(echo "$line" | sed 's/.*\///') | ||
| 57 | read -r feedurl <"$line" | ||
| 58 | printf '\tfeed "%s" "%s"\n' "$feedname" "$feedurl" | ||
| 59 | done | ||
| 60 | printf "}\n" | ||
| 61 | } | ||
| 62 | |||
| 63 | feedmenu() { | ||
| 64 | while read -r line; do | ||
| 65 | feedname=$(echo "$line" | sed 's/.*\///') | ||
| 66 | sfeed_plain "$sfd/files/$feedname" | head -$showlast | ||
| 67 | done | $menu | ||
| 68 | } | ||
| 69 | |||
| 70 | openfeeds() { | ||
| 71 | while read -r line; do | ||
| 72 | url=$(echo "$line" | sed 's/.*[\t ]//' | fixurl) | ||
| 73 | [ -n "$url" ] && echo "$url" | ||
| 74 | done | xargs $urlopener | ||
| 75 | } | ||
| 76 | |||
| 77 | $filepicker "$@" "$sfd/urls" | dirtofeedpaths > "$sfd/last" | ||
| 78 | pathstosfeedrc < "$sfd/last" > "$sfd/sfeedrc" | ||
| 79 | sfeed_update "$sfd/sfeedrc" | ||
| 80 | feedmenu < "$sfd/last" | openfeeds | ||
diff --git a/scripts/old/theme b/scripts/old/theme new file mode 100755 index 0000000..7e0107a --- /dev/null +++ b/scripts/old/theme | |||
| @@ -0,0 +1,23 @@ | |||
| 1 | #!/bin/sh | ||
| 2 | |||
| 3 | # This script is a shortcut to change between a dark and a light theme | ||
| 4 | # for my terminal emulator (st). | ||
| 5 | |||
| 6 | # Usage: theme (dark|light) | ||
| 7 | |||
| 8 | src=$HOME/.local/src | ||
| 9 | |||
| 10 | case "$@" in | ||
| 11 | dark) | ||
| 12 | cd $src/st-darkbg | ||
| 13 | ;; | ||
| 14 | light) | ||
| 15 | cd $src/st-lightbg | ||
| 16 | ;; | ||
| 17 | *) | ||
| 18 | echo "usage: theme (dark|light)" | ||
| 19 | exit 1 | ||
| 20 | ;; | ||
| 21 | esac | ||
| 22 | |||
| 23 | make && sudo make install | ||
diff --git a/scripts/old/togglemute b/scripts/old/togglemute new file mode 100755 index 0000000..b799b02 --- /dev/null +++ b/scripts/old/togglemute | |||
| @@ -0,0 +1,18 @@ | |||
| 1 | #!/bin/sh | ||
| 2 | |||
| 3 | # Toggle mute state and notify | ||
| 4 | # Requires: pulsemixer, notify-send or similar | ||
| 5 | |||
| 6 | #notify=notify-send | ||
| 7 | notify=herbe | ||
| 8 | |||
| 9 | ismute=$(pulsemixer --toggle-mute --get-mute) | ||
| 10 | |||
| 11 | if [ "$ismute" = "1" ]; then | ||
| 12 | m="muted" | ||
| 13 | else | ||
| 14 | m="unmuted" | ||
| 15 | fi | ||
| 16 | |||
| 17 | pkill herbe # comment this line too if not using herbe | ||
| 18 | $notify "Audio $m" | ||
diff --git a/scripts/old/volume b/scripts/old/volume new file mode 100755 index 0000000..8dcd36a --- /dev/null +++ b/scripts/old/volume | |||
| @@ -0,0 +1,13 @@ | |||
| 1 | #!/bin/sh | ||
| 2 | |||
| 3 | # Change volume and notify | ||
| 4 | # Usage: volume {+n|-n} | ||
| 5 | # Requires: pulsemixer, notify-send or similar | ||
| 6 | |||
| 7 | #notify=notify-send | ||
| 8 | notify=herbe | ||
| 9 | |||
| 10 | newvol=$(pulsemixer --change-volume "$1" --get-volume | awk '{print $1}') | ||
| 11 | |||
| 12 | pkill herbe # comment this line too if not using herbe | ||
| 13 | $notify "Volume" "$newvol%" | ||
diff --git a/scripts/old/xkboptions b/scripts/old/xkboptions new file mode 100755 index 0000000..e63456d --- /dev/null +++ b/scripts/old/xkboptions | |||
| @@ -0,0 +1,6 @@ | |||
| 1 | #!/bin/sh | ||
| 2 | |||
| 3 | # Loads my xkboptions | ||
| 4 | |||
| 5 | setxkbmap -option compose:ralt | ||
| 6 | setxkbmap -option caps:swapescape | ||
diff --git a/scripts/old/xprop-active-window-id b/scripts/old/xprop-active-window-id new file mode 100755 index 0000000..97cf60f --- /dev/null +++ b/scripts/old/xprop-active-window-id | |||
| @@ -0,0 +1,6 @@ | |||
| 1 | #!/bin/sh | ||
| 2 | |||
| 3 | # Get the ID of the current active window (hexadecimal) | ||
| 4 | # Requires: xprop | ||
| 5 | |||
| 6 | xprop -root | grep _NET_ACTIVE_WINDOW | head -1 | sed 's/.* //' | ||
diff --git a/scripts/open-file b/scripts/open-file new file mode 100755 index 0000000..c985bf4 --- /dev/null +++ b/scripts/open-file | |||
| @@ -0,0 +1,122 @@ | |||
| 1 | #!/bin/sh | ||
| 2 | |||
| 3 | # Inspired by https://github.com/salman-abedin/launch.sh | ||
| 4 | # Launches files based on their mimetypes | ||
| 5 | # Requires: dmenu_path or similar (fallback), dmenu-filepicker | ||
| 6 | |||
| 7 | # Usage: open-file [-m menu] [-s launcher] [-t mimetype] [files...] | ||
| 8 | |||
| 9 | menu="dmenu -i -l 15" | ||
| 10 | |||
| 11 | # Change default apps here | ||
| 12 | video=${VIDEO:-vlc} | ||
| 13 | music=${MUSIC:-vlc} | ||
| 14 | pdf=${PDF:-zathura} | ||
| 15 | img="${IMGVIEW:-nsxiv}" | ||
| 16 | word="${WORDS:-libreoffice}" | ||
| 17 | sheet="${SHEETS:-libreoffice}" | ||
| 18 | html="${BROWSER:-firefox} --new-window" | ||
| 19 | xedit="${XEDIT:-xedit}" | ||
| 20 | |||
| 21 | usage() { | ||
| 22 | echo "Usage: open-file [-m MENU] [-s LAUNCHER] [-t MIMETYPE] [files...]" | ||
| 23 | } | ||
| 24 | |||
| 25 | openfile() { | ||
| 26 | f="$*" | ||
| 27 | localmime="$mimetype" | ||
| 28 | |||
| 29 | [ ! -f "$f" ] && echo "$f: bad argument" && exit 1 | ||
| 30 | [ -z "$mimetype" ] && localmime="$(file --mime-type "$f" -bL)" | ||
| 31 | |||
| 32 | prog="" | ||
| 33 | case "$localmime" in | ||
| 34 | video/*) | ||
| 35 | prog="$video" | ||
| 36 | ;; | ||
| 37 | audio/*) | ||
| 38 | prog="$music" | ||
| 39 | ;; | ||
| 40 | application/pdf | application/postscript | image/vnd.djvu) | ||
| 41 | prog="$pdf" | ||
| 42 | ;; | ||
| 43 | image/*) | ||
| 44 | prog="$img" | ||
| 45 | ;; | ||
| 46 | application/msword | \ | ||
| 47 | application/vnd.oasis.opendocument.text | text/rtf | \ | ||
| 48 | application/vnd.openxmlformats-officedocument.wordprocessingml.*) | ||
| 49 | prog="$word" | ||
| 50 | ;; | ||
| 51 | application/ms-excel | \ | ||
| 52 | application/vnd.oasis.opendocument.spreadsheet | \ | ||
| 53 | application/vnd.openxmlformats-officedocument.spreadsheetml.*) | ||
| 54 | prog="$sheet" | ||
| 55 | ;; | ||
| 56 | text/html | text/enriched) | ||
| 57 | prog="$html" | ||
| 58 | ;; | ||
| 59 | text/*) | ||
| 60 | prog="$xedit" | ||
| 61 | ;; | ||
| 62 | application/zip) | ||
| 63 | prog="unzip" | ||
| 64 | ;; | ||
| 65 | application/x-rar-compressed) | ||
| 66 | prog="unrar" | ||
| 67 | ;; | ||
| 68 | application/x-archive | application/x-tar | \ | ||
| 69 | application/x-bzip2 | application/gzip | application/x-lzip | \ | ||
| 70 | application/x-lzma | application/x-xz | application/x-gtar) | ||
| 71 | prog="tar -tavf" | ||
| 72 | ;; | ||
| 73 | application/java-archive) | ||
| 74 | prog="java -jar" | ||
| 75 | ;; | ||
| 76 | *) | ||
| 77 | if [ "$menu" = dmenu ]; then | ||
| 78 | menuprompt="-p \"How to open $f? \"" | ||
| 79 | else | ||
| 80 | menuprompt="--prompt=\"How to open $f? \"" | ||
| 81 | fi | ||
| 82 | prog=$(dmenu_path | $menu "$menuprompt") | ||
| 83 | ;; | ||
| 84 | esac | ||
| 85 | |||
| 86 | if [ -n "$prog" ]; then | ||
| 87 | $launcher $prog "$f" | ||
| 88 | else | ||
| 89 | exit 1 | ||
| 90 | fi | ||
| 91 | } | ||
| 92 | |||
| 93 | while getopts "m:s:t:" opt; do | ||
| 94 | case "$opt" in | ||
| 95 | m) | ||
| 96 | menu="$OPTARG" | ||
| 97 | ;; | ||
| 98 | s) | ||
| 99 | launcher="$OPTARG" | ||
| 100 | ;; | ||
| 101 | t) | ||
| 102 | mimetype="$OPTARG" | ||
| 103 | ;; | ||
| 104 | *) | ||
| 105 | usage | ||
| 106 | exit 1 | ||
| 107 | ;; | ||
| 108 | esac | ||
| 109 | done | ||
| 110 | |||
| 111 | shift $((OPTIND - 1)) | ||
| 112 | |||
| 113 | if [ -n "$1" ]; then | ||
| 114 | while [ -n "$1" ]; do | ||
| 115 | openfile "$1" & | ||
| 116 | shift | ||
| 117 | done | ||
| 118 | else | ||
| 119 | dmenu-filepicker -m "$menu" | while read -r line; do | ||
| 120 | openfile "$line" & | ||
| 121 | done | ||
| 122 | fi | ||
diff --git a/scripts/open-stdin b/scripts/open-stdin new file mode 100755 index 0000000..a1e10b5 --- /dev/null +++ b/scripts/open-stdin | |||
| @@ -0,0 +1,12 @@ | |||
| 1 | #!/bin/sh | ||
| 2 | |||
| 3 | # Saves standard input in a temporary file and opens it (spawn) | ||
| 4 | # Usage: open-stdin | ||
| 5 | # Requires: open-file (or set $OPENER to e.g. xdg-open) | ||
| 6 | |||
| 7 | folder=${TMPDIR:-/tmp} | ||
| 8 | open=${OPENER:-open-file} | ||
| 9 | |||
| 10 | tempfile=$(mktemp -p "$folder") | ||
| 11 | |||
| 12 | cat > "$tempfile" && $open $@ "$tempfile" | ||
diff --git a/scripts/open-url b/scripts/open-url new file mode 100755 index 0000000..bd1b1a1 --- /dev/null +++ b/scripts/open-url | |||
| @@ -0,0 +1,28 @@ | |||
| 1 | #!/bin/sh | ||
| 2 | |||
| 3 | # Open link in preferred application | ||
| 4 | # Requires: mail-compose, spawn, xsel (optional) | ||
| 5 | |||
| 6 | browser=${BROWSER:-firefox} | ||
| 7 | imageviewer=${IMAGEVIEWER:-nsxiv} | ||
| 8 | |||
| 9 | [ -z "$1" ] && exit 0 | ||
| 10 | |||
| 11 | # Optional: copy url to clipboard | ||
| 12 | echo "$@" | xsel -ib | ||
| 13 | |||
| 14 | case "$@" in | ||
| 15 | mailto:*) | ||
| 16 | mail-compose "$@" | ||
| 17 | ;; | ||
| 18 | *.jpg | *.jpeg | *.png) | ||
| 19 | spawn "$imageviewer" "$@" | ||
| 20 | ;; | ||
| 21 | *.gif) | ||
| 22 | spawn "$imageviewer" "$@" | ||
| 23 | ;; | ||
| 24 | *) | ||
| 25 | spawn "$browser" "$@" | ||
| 26 | ;; | ||
| 27 | esac | ||
| 28 | |||
diff --git a/scripts/popup-cal12 b/scripts/popup-cal12 new file mode 100755 index 0000000..1c85b3d --- /dev/null +++ b/scripts/popup-cal12 | |||
| @@ -0,0 +1,6 @@ | |||
| 1 | #!/bin/sh | ||
| 2 | |||
| 3 | # Popup terminal displaying cal -3 | ||
| 4 | # Requires: st (suckless terminal) | ||
| 5 | |||
| 6 | st -T "stfloat" -g 69x36+620+250 -e sh -c "cal $(date +%Y); read x" | ||
diff --git a/scripts/popup-cal3 b/scripts/popup-cal3 new file mode 100755 index 0000000..6dfed54 --- /dev/null +++ b/scripts/popup-cal3 | |||
| @@ -0,0 +1,6 @@ | |||
| 1 | #!/bin/sh | ||
| 2 | |||
| 3 | # Popup terminal displaying cal -3 | ||
| 4 | # Requires: st (suckless terminal) | ||
| 5 | |||
| 6 | st -T "stfloat" -g 68x11+620+450 -e sh -c 'cal -3; read x' | ||
diff --git a/scripts/popup-terminal b/scripts/popup-terminal new file mode 100755 index 0000000..5a9a931 --- /dev/null +++ b/scripts/popup-terminal | |||
| @@ -0,0 +1,5 @@ | |||
| 1 | #!/bin/sh | ||
| 2 | |||
| 3 | # TODO maybe I want to run e.g. tmux in this? | ||
| 4 | |||
| 5 | st -T "stfloat" -g 85x25+550+300 tmux new-session "$@" | ||
diff --git a/scripts/secret b/scripts/secret new file mode 100755 index 0000000..14ec2e0 --- /dev/null +++ b/scripts/secret | |||
| @@ -0,0 +1,52 @@ | |||
| 1 | #!/bin/sh | ||
| 2 | |||
| 3 | # Encrypt and decrypt files using a fixed cipher and passphrase. | ||
| 4 | # The first line of the (unencrypted) file is considered the "password", | ||
| 5 | # the rest can be anything. | ||
| 6 | |||
| 7 | # Usage: secret command file | ||
| 8 | # Available commands: | ||
| 9 | # clip: copy the secret to clipboard; deleted after 10 seconds | ||
| 10 | # edit: edit or add a file | ||
| 11 | # show: show the full encrypted file | ||
| 12 | |||
| 13 | # Requires: openssl, xsel (for clip only) | ||
| 14 | |||
| 15 | # ksh completion | ||
| 16 | # set -A complete_sel_1 clip edit show | ||
| 17 | # set -A complete_sel_2 box/secret | ||
| 18 | |||
| 19 | opts="aes-256-cbc -iter 1000" # options for openssl | ||
| 20 | timeout=10 # timeout for clip, in ms | ||
| 21 | editor=${EDITOR:-vi} | ||
| 22 | |||
| 23 | if [ -z "$1" ] || [ -z "$2" ]; then | ||
| 24 | echo "usage: secret command file" | ||
| 25 | else | ||
| 26 | case "$1" in | ||
| 27 | clip) | ||
| 28 | openssl $opts -d < "$2" | head -n 1 | xargs printf "%s" | xsel -ib | ||
| 29 | sleep $timeout && xsel -db & | ||
| 30 | ;; | ||
| 31 | edit) | ||
| 32 | tempfile=$(mktemp) | ||
| 33 | if [ -f "$2" ]; then | ||
| 34 | openssl $opts -d < "$2" > "$tempfile" | ||
| 35 | fi | ||
| 36 | $editor "$tempfile" | ||
| 37 | read -p "Are you sure? [N/yes] " an | ||
| 38 | if [ "$an" = yes ] || [ "$an" = Yes ] || [ "$an" = YES ]; then | ||
| 39 | openssl $opts < "$tempfile" > "$2" | ||
| 40 | else | ||
| 41 | echo "Changes discarded" | ||
| 42 | fi | ||
| 43 | rm "$tempfile" | ||
| 44 | ;; | ||
| 45 | show) | ||
| 46 | openssl $opts -d < "$2" | ||
| 47 | ;; | ||
| 48 | *) | ||
| 49 | echo "$1: not a valid command" | ||
| 50 | ;; | ||
| 51 | esac | ||
| 52 | fi | ||
diff --git a/scripts/sel b/scripts/sel new file mode 100755 index 0000000..6ecf4fe --- /dev/null +++ b/scripts/sel | |||
| @@ -0,0 +1,136 @@ | |||
| 1 | #!/bin/sh | ||
| 2 | |||
| 3 | # Allow bulk operations on a list of selected files. | ||
| 4 | |||
| 5 | # Requires: dmenu (or similar), trash (optional), open-file (for open only) | ||
| 6 | |||
| 7 | # Usage: sel [-m menu] [command] | ||
| 8 | # If no command is specified, shows the list of selected files | ||
| 9 | # Commands: | ||
| 10 | # add [files...]: add files to selection | ||
| 11 | # addall: add all files in the current folder to selection | ||
| 12 | # clear: clear selection | ||
| 13 | # cp: copy to current dir, possbily after editing filenames | ||
| 14 | # edit: open selection in editor | ||
| 15 | # mv: move to current dir, possbily after editing filenames | ||
| 16 | # open: open files using open-file | ||
| 17 | # rm: remove selected files and clear selection | ||
| 18 | |||
| 19 | # TODO: The usage of paste(1) is a bit of a hack, and for example it does | ||
| 20 | # not work if filenames contain tab characters. Fix this. | ||
| 21 | |||
| 22 | # Bug (probably not fixing this, use virename): moving a file to | ||
| 23 | # itself gives an error and rm is not run. | ||
| 24 | |||
| 25 | file="$XDG_DATA_HOME/selectedfiles" | ||
| 26 | menu="" # default uses dmenu-filepicker default | ||
| 27 | editor=${EDITOR:-vi} | ||
| 28 | rm="trash rm" # replace with rm -r if you don't use trash | ||
| 29 | |||
| 30 | usage() { | ||
| 31 | echo "Usage: sel [-m MENU] [COMMAND]" | ||
| 32 | echo "If no COMMAND is specified, shows the list of selected files" | ||
| 33 | echo "Possible commands:" | ||
| 34 | echo " add [files...]: add files to selection" | ||
| 35 | echo " addall: add all files in the current folder to selection" | ||
| 36 | echo " clear: clear selection" | ||
| 37 | echo " cp: copy to current dir, possbily after editing filenames" | ||
| 38 | echo " edit: open selection in editor" | ||
| 39 | echo " mv: move to current dir, possbily after editing filenames" | ||
| 40 | echo " open: open files using open-file" | ||
| 41 | echo " rm: remove selected files and clear selection" | ||
| 42 | } | ||
| 43 | |||
| 44 | while getopts "m:" opt; do | ||
| 45 | case "$opt" in | ||
| 46 | m) | ||
| 47 | menu="$OPTARG" | ||
| 48 | ;; | ||
| 49 | *) | ||
| 50 | usage | ||
| 51 | exit 1 | ||
| 52 | ;; | ||
| 53 | esac | ||
| 54 | done | ||
| 55 | shift $((OPTIND - 1)) | ||
| 56 | |||
| 57 | add() { | ||
| 58 | shift 1 | ||
| 59 | if [ -z "$1" ]; then | ||
| 60 | if [ -n "$menu" ]; then | ||
| 61 | dmenu-filepicker -m "$menu" >> "$file" | ||
| 62 | else | ||
| 63 | dmenu-filepicker >> "$file" | ||
| 64 | fi | ||
| 65 | else | ||
| 66 | for i in "$@"; do realpath "$i" >> "$file"; done | ||
| 67 | fi | ||
| 68 | sort -u -o "$file" "$file" | ||
| 69 | } | ||
| 70 | |||
| 71 | clear() { | ||
| 72 | cat /dev/null > "$file" | ||
| 73 | } | ||
| 74 | |||
| 75 | cphere() { | ||
| 76 | file2=$(mktemp) | ||
| 77 | sed 's/^.*\///' "$file" > "$file2" | ||
| 78 | $editor "$file2" | ||
| 79 | if [ "$(wc -l "$file" | awk '{print $1}')" != \ | ||
| 80 | "$(wc -l "$file2" | awk '{print $1}')" ]; then | ||
| 81 | echo "Error reading new file names" | ||
| 82 | return 1 | ||
| 83 | else | ||
| 84 | paste "$file" "$file2" | while read -r f; do | ||
| 85 | fold=$(echo "$f" | sed 's/ .*//') | ||
| 86 | fnew=$(echo "$f" | sed 's/.* //') | ||
| 87 | cp -R "$fold" ./"$fnew" || return 1 | ||
| 88 | done | ||
| 89 | fi | ||
| 90 | } | ||
| 91 | |||
| 92 | open() { | ||
| 93 | while read -r f; do | ||
| 94 | open-file "$f" | ||
| 95 | done < "$file" | ||
| 96 | } | ||
| 97 | |||
| 98 | remove() { | ||
| 99 | while read -r f; do | ||
| 100 | $rm "$f" | ||
| 101 | done < "$file" | ||
| 102 | } | ||
| 103 | |||
| 104 | if [ -z "$1" ]; then | ||
| 105 | cat "$file" | ||
| 106 | else | ||
| 107 | case "$1" in | ||
| 108 | add) | ||
| 109 | add "$@" | ||
| 110 | ;; | ||
| 111 | addall) | ||
| 112 | add ./* | ||
| 113 | ;; | ||
| 114 | clear) | ||
| 115 | clear | ||
| 116 | ;; | ||
| 117 | cp) | ||
| 118 | cphere && clear | ||
| 119 | ;; | ||
| 120 | edit) | ||
| 121 | $editor "$file" | ||
| 122 | ;; | ||
| 123 | mv) | ||
| 124 | cphere && (remove; clear) | ||
| 125 | ;; | ||
| 126 | open) | ||
| 127 | open | ||
| 128 | ;; | ||
| 129 | rm) | ||
| 130 | remove && clear | ||
| 131 | ;; | ||
| 132 | *) | ||
| 133 | echo "$1: not a valid sel command" | ||
| 134 | ;; | ||
| 135 | esac | ||
| 136 | fi | ||
diff --git a/scripts/spawn b/scripts/spawn new file mode 100755 index 0000000..fdb2614 --- /dev/null +++ b/scripts/spawn | |||
| @@ -0,0 +1,5 @@ | |||
| 1 | #!/bin/sh | ||
| 2 | |||
| 3 | # Simple command to spawn and detach an application | ||
| 4 | |||
| 5 | "$@" >/dev/null 2>&1 & | ||
diff --git a/scripts/status b/scripts/status new file mode 100755 index 0000000..66811b0 --- /dev/null +++ b/scripts/status | |||
| @@ -0,0 +1,13 @@ | |||
| 1 | #!/bin/sh | ||
| 2 | |||
| 3 | # Calls one of the system-specific status scripts to display | ||
| 4 | # a line of text with some status information (battery, date...) | ||
| 5 | |||
| 6 | case "$(uname)" in | ||
| 7 | OpenBSD) | ||
| 8 | status-openbsd | ||
| 9 | ;; | ||
| 10 | *) | ||
| 11 | status-linux | ||
| 12 | ;; | ||
| 13 | esac | ||
diff --git a/scripts/status-linux b/scripts/status-linux new file mode 100755 index 0000000..a2061d1 --- /dev/null +++ b/scripts/status-linux | |||
| @@ -0,0 +1,52 @@ | |||
| 1 | #!/bin/sh | ||
| 2 | |||
| 3 | # Prints some status info to stdout. Includes: | ||
| 4 | # - date and time | ||
| 5 | # - battery | ||
| 6 | # - wifi (requires nmcli) | ||
| 7 | # - past notifications (requires notify) | ||
| 8 | |||
| 9 | # Usage: status [separator] | ||
| 10 | |||
| 11 | sep=${1:-" | "} | ||
| 12 | |||
| 13 | time=$(date +"%H:%M") | ||
| 14 | date=$(date +"%a %d %b") | ||
| 15 | |||
| 16 | if [ "$(pulsemixer --get-mute)" -eq 1 ]; then | ||
| 17 | volume="Muted" | ||
| 18 | else | ||
| 19 | volume="Vol $(pulsemixer --get-volume | awk '{print $1}')%" | ||
| 20 | fi | ||
| 21 | |||
| 22 | bat="/sys/class/power_supply/BAT0" | ||
| 23 | if [ -d $bat ]; then | ||
| 24 | charge_status="$(cat $bat/status | awk '{print substr ($0, 0, 2)}')" | ||
| 25 | battery="Bat $(cat $bat/capacity)% $charge_status" | ||
| 26 | else | ||
| 27 | battery="No battery" | ||
| 28 | fi | ||
| 29 | |||
| 30 | # NetworkManager has a dreadful command line interface | ||
| 31 | # It makes cry every time | ||
| 32 | # pls help | ||
| 33 | #nwline="$(nmcli device status | head -n 2 | tail -n 1)" | ||
| 34 | #nwclean="$(echo "$nwline" | sed 's/ *$//' | sed 's/.* //')" | ||
| 35 | #network="Network: $nwclean" | ||
| 36 | |||
| 37 | # Thank you iwctl for saving us from this dreadful existence | ||
| 38 | network="$(iwctl station wlan0 show | grep 'Connected network' | awk '{print $3}')" | ||
| 39 | if [ "$(cat /sys/class/net/eth0/carrier)" = 1 ]; then | ||
| 40 | if [ -z "$network" ]; then | ||
| 41 | network="eth" | ||
| 42 | else | ||
| 43 | network="eth & $network" | ||
| 44 | fi | ||
| 45 | fi | ||
| 46 | |||
| 47 | noticount=$(notify show | wc -l) | ||
| 48 | |||
| 49 | printf '%s' "$network$sep$volume$sep$battery$sep$date$sep$time" | ||
| 50 | [ "$noticount" = "1" ] && printf '%s' "$sep$(notify show)" | ||
| 51 | [ "$noticount" -gt "1" ] && printf '%s' "${sep}[$noticount]" | ||
| 52 | printf '\n' | ||
diff --git a/scripts/status-openbsd b/scripts/status-openbsd new file mode 100755 index 0000000..6382053 --- /dev/null +++ b/scripts/status-openbsd | |||
| @@ -0,0 +1,26 @@ | |||
| 1 | #!/bin/sh | ||
| 2 | |||
| 3 | # Prints some status info to stdout. Includes: | ||
| 4 | # - date and time | ||
| 5 | # - battery | ||
| 6 | # - wifi (requires ifconfig on OpenBSD) | ||
| 7 | |||
| 8 | # Usage: status [separator] | ||
| 9 | |||
| 10 | sep=${1:-" | "} | ||
| 11 | |||
| 12 | time=$(date +"%H:%M") | ||
| 13 | date=$(date +"%d %b") | ||
| 14 | battery="$(apm | grep -o '[^ ]*%')" | ||
| 15 | ifconfig="$(ifconfig athn0)" | ||
| 16 | network="$(echo "$ifconfig" | grep status | sed 's/.*status: //')" | ||
| 17 | if [ "$network" = "active" ]; then | ||
| 18 | nwid="$(echo "$ifconfig" | grep nwid | sed 's/.*nwid //;s/ chan.*//')" | ||
| 19 | if [ -z "$nwid" ]; then | ||
| 20 | nwid="$(echo "$ifconfig" | grep ieee80211 | \ | ||
| 21 | sed 's/.*ieee80211: join //' | sed 's/ chan.*//')" | ||
| 22 | fi | ||
| 23 | fi | ||
| 24 | network="$(printf "%.20s" "$nwid")" # Make it shorter | ||
| 25 | |||
| 26 | echo "$network$sep$battery$sep$date$sep$time" | ||
diff --git a/scripts/templess b/scripts/templess new file mode 100755 index 0000000..b06ace7 --- /dev/null +++ b/scripts/templess | |||
| @@ -0,0 +1,10 @@ | |||
| 1 | #!/bin/sh | ||
| 2 | |||
| 3 | # Write standard in to a temporary file and sends it to a pager. | ||
| 4 | # This is used to be able to pipe the content displayed by less to | ||
| 5 | # an external program. | ||
| 6 | |||
| 7 | pager=${PAGER:-less} | ||
| 8 | tempfile=$(mktemp) | ||
| 9 | |||
| 10 | cat > "$tempfile" && $pager "$tempfile" | ||
diff --git a/scripts/terminal b/scripts/terminal new file mode 100755 index 0000000..849c037 --- /dev/null +++ b/scripts/terminal | |||
| @@ -0,0 +1,7 @@ | |||
| 1 | #!/bin/sh | ||
| 2 | |||
| 3 | # My default terminal | ||
| 4 | |||
| 5 | terminal=${TERMINAL:-"st -e tmux new-session "$@""} | ||
| 6 | |||
| 7 | $terminal | ||
diff --git a/scripts/trash b/scripts/trash new file mode 100755 index 0000000..5ff5a27 --- /dev/null +++ b/scripts/trash | |||
| @@ -0,0 +1,44 @@ | |||
| 1 | #!/bin/sh | ||
| 2 | |||
| 3 | # Simple trash management. Files are moved to a directory named with the | ||
| 4 | # current date. | ||
| 5 | |||
| 6 | # Usage: trash [rm FILE(s)|ls|empty] | ||
| 7 | |||
| 8 | # ksh completion | ||
| 9 | # set -A complete_trash_1 rm ls empty | ||
| 10 | |||
| 11 | trashfolder=$XDG_DATA_HOME/mytrash | ||
| 12 | |||
| 13 | usage() { | ||
| 14 | echo "Usage: trash [rm FILES... | ls | empty]" | ||
| 15 | } | ||
| 16 | |||
| 17 | if [ -z "$1" ]; then | ||
| 18 | usage | ||
| 19 | exit 1 | ||
| 20 | fi | ||
| 21 | |||
| 22 | case "$1" in | ||
| 23 | empty) | ||
| 24 | # little check | ||
| 25 | if [ -n "$trashfolder" ]; then | ||
| 26 | rm -rf "${trashfolder:?}"/* | ||
| 27 | fi | ||
| 28 | ;; | ||
| 29 | ls) | ||
| 30 | ls "$trashfolder" | ||
| 31 | ;; | ||
| 32 | rm) | ||
| 33 | curdir=$(pwd | sed 's|.*/||') | ||
| 34 | thisfolder="$trashfolder/$(date +'%Y-%m-%d-%s')-$curdir" | ||
| 35 | mkdir -p "$thisfolder" | ||
| 36 | shift 1 | ||
| 37 | mv "$@" "$thisfolder" | ||
| 38 | ;; | ||
| 39 | |||
| 40 | *) | ||
| 41 | usage | ||
| 42 | exit 1 | ||
| 43 | ;; | ||
| 44 | esac | ||
diff --git a/scripts/unused/addressgrep b/scripts/unused/addressgrep new file mode 100755 index 0000000..36b4899 --- /dev/null +++ b/scripts/unused/addressgrep | |||
| @@ -0,0 +1,8 @@ | |||
| 1 | #!/bin/sh | ||
| 2 | |||
| 3 | # Find all email addresses in stdin, print them newline-separated to stdout | ||
| 4 | |||
| 5 | reg='[a-z0-9\._\+\-%]+@[a-z0-9\._\+\-%]+\.[a-zA-Z]+' | ||
| 6 | |||
| 7 | grep -Pio "$reg" | ||
| 8 | |||
diff --git a/scripts/unused/alg b/scripts/unused/alg new file mode 100755 index 0000000..cd5d3c8 --- /dev/null +++ b/scripts/unused/alg | |||
| @@ -0,0 +1,444 @@ | |||
| 1 | #!/bin/sh | ||
| 2 | |||
| 3 | # Script to store and access blindsolving algs (speedcubing stuff) | ||
| 4 | |||
| 5 | # Example: alg e FG - opens up editor to edit $basedir/edges/$ebuffer/RD/LD | ||
| 6 | # Example: alg c UBL E - prints out all first algs for UBL-FDR-* | ||
| 7 | |||
| 8 | usage() { | ||
| 9 | echo "Usage:" | ||
| 10 | echo "alg" | ||
| 11 | echo "alg edit (c|e|w|x|t) [buffer] (1 letter|2 letters)" | ||
| 12 | echo "alg export (c|e|w|x|t|all)" | ||
| 13 | } | ||
| 14 | |||
| 15 | default_editor=vi | ||
| 16 | basedir="$HOME/box/speedcubing/bld/algs" | ||
| 17 | ebuffer=UR | ||
| 18 | cbuffer=UFR | ||
| 19 | wbuffer=UFr | ||
| 20 | xbuffer=Ubl | ||
| 21 | tbuffer=Uf | ||
| 22 | |||
| 23 | edge() { | ||
| 24 | [ "$1" = "a" ] && echo FU | ||
| 25 | [ "$1" = "b" ] && echo UF | ||
| 26 | [ "$1" = "c" ] && echo UL | ||
| 27 | [ "$1" = "d" ] && echo UB | ||
| 28 | [ "$1" = "e" ] && echo FD | ||
| 29 | [ "$1" = "f" ] && echo RD | ||
| 30 | [ "$1" = "g" ] && echo LD | ||
| 31 | [ "$1" = "i" ] && echo FR | ||
| 32 | [ "$1" = "j" ] && echo LU | ||
| 33 | [ "$1" = "k" ] && echo RB | ||
| 34 | [ "$1" = "l" ] && echo DF | ||
| 35 | [ "$1" = "m" ] && echo DB | ||
| 36 | [ "$1" = "n" ] && echo DR | ||
| 37 | [ "$1" = "o" ] && echo FL | ||
| 38 | [ "$1" = "p" ] && echo DL | ||
| 39 | [ "$1" = "r" ] && echo BU | ||
| 40 | [ "$1" = "s" ] && echo BD | ||
| 41 | [ "$1" = "t" ] && echo BL | ||
| 42 | [ "$1" = "u" ] && echo BR | ||
| 43 | [ "$1" = "v" ] && echo LF | ||
| 44 | [ "$1" = "w" ] && echo LB | ||
| 45 | [ "$1" = "z" ] && echo RF | ||
| 46 | } | ||
| 47 | |||
| 48 | corner() { | ||
| 49 | [ "$1" = "a" ] && echo FUL | ||
| 50 | [ "$1" = "b" ] && echo UBL | ||
| 51 | [ "$1" = "c" ] && echo UFL | ||
| 52 | [ "$1" = "d" ] && echo UBR | ||
| 53 | [ "$1" = "e" ] && echo FDR | ||
| 54 | [ "$1" = "f" ] && echo RDB | ||
| 55 | [ "$1" = "g" ] && echo LDF | ||
| 56 | [ "$1" = "j" ] && echo LUF | ||
| 57 | [ "$1" = "k" ] && echo RUB | ||
| 58 | [ "$1" = "l" ] && echo DFR | ||
| 59 | [ "$1" = "m" ] && echo DBR | ||
| 60 | [ "$1" = "n" ] && echo DFL | ||
| 61 | [ "$1" = "o" ] && echo FDL | ||
| 62 | [ "$1" = "p" ] && echo DBL | ||
| 63 | [ "$1" = "r" ] && echo BUR | ||
| 64 | [ "$1" = "s" ] && echo BUL | ||
| 65 | [ "$1" = "t" ] && echo BDL | ||
| 66 | [ "$1" = "u" ] && echo BDR | ||
| 67 | [ "$1" = "v" ] && echo LUB | ||
| 68 | [ "$1" = "w" ] && echo LDB | ||
| 69 | [ "$1" = "z" ] && echo RDF | ||
| 70 | } | ||
| 71 | |||
| 72 | wing() { | ||
| 73 | [ "$1" = "a" ] && echo FUl | ||
| 74 | [ "$1" = "b" ] && echo URb | ||
| 75 | [ "$1" = "c" ] && echo ULf | ||
| 76 | [ "$1" = "d" ] && echo UBl | ||
| 77 | [ "$1" = "e" ] && echo FDr | ||
| 78 | [ "$1" = "f" ] && echo RDb | ||
| 79 | [ "$1" = "g" ] && echo LDf | ||
| 80 | [ "$1" = "i" ] && echo FRu | ||
| 81 | [ "$1" = "j" ] && echo LUb | ||
| 82 | [ "$1" = "k" ] && echo RBu | ||
| 83 | [ "$1" = "l" ] && echo DFl | ||
| 84 | [ "$1" = "m" ] && echo DBr | ||
| 85 | [ "$1" = "n" ] && echo DRf | ||
| 86 | [ "$1" = "o" ] && echo FLd | ||
| 87 | [ "$1" = "p" ] && echo DLb | ||
| 88 | [ "$1" = "r" ] && echo BUr | ||
| 89 | [ "$1" = "s" ] && echo BDl | ||
| 90 | [ "$1" = "t" ] && echo BLu | ||
| 91 | [ "$1" = "u" ] && echo BRd | ||
| 92 | [ "$1" = "v" ] && echo LFu | ||
| 93 | [ "$1" = "w" ] && echo LBd | ||
| 94 | [ "$1" = "x" ] && echo RUf | ||
| 95 | [ "$1" = "z" ] && echo RFd | ||
| 96 | } | ||
| 97 | |||
| 98 | xcenter() { | ||
| 99 | [ "$1" = "a" ] && echo Ful | ||
| 100 | [ "$1" = "b" ] && echo Ufr | ||
| 101 | [ "$1" = "c" ] && echo Ufl | ||
| 102 | [ "$1" = "d" ] && echo Ubr | ||
| 103 | [ "$1" = "e" ] && echo Fdr | ||
| 104 | [ "$1" = "f" ] && echo Rdb | ||
| 105 | [ "$1" = "g" ] && echo Ldf | ||
| 106 | [ "$1" = "i" ] && echo Fur | ||
| 107 | [ "$1" = "j" ] && echo Luf | ||
| 108 | [ "$1" = "k" ] && echo Rub | ||
| 109 | [ "$1" = "l" ] && echo Dfr | ||
| 110 | [ "$1" = "m" ] && echo Dbr | ||
| 111 | [ "$1" = "n" ] && echo Dfl | ||
| 112 | [ "$1" = "o" ] && echo Fdl | ||
| 113 | [ "$1" = "p" ] && echo Dbl | ||
| 114 | [ "$1" = "r" ] && echo Bur | ||
| 115 | [ "$1" = "s" ] && echo Bul | ||
| 116 | [ "$1" = "t" ] && echo Bdl | ||
| 117 | [ "$1" = "u" ] && echo Bdr | ||
| 118 | [ "$1" = "v" ] && echo Lub | ||
| 119 | [ "$1" = "w" ] && echo Ldb | ||
| 120 | [ "$1" = "x" ] && echo Ruf | ||
| 121 | [ "$1" = "z" ] && echo Rdf | ||
| 122 | } | ||
| 123 | |||
| 124 | tcenter() { | ||
| 125 | [ "$1" = "a" ] && echo Fu | ||
| 126 | [ "$1" = "b" ] && echo Ur | ||
| 127 | [ "$1" = "c" ] && echo Ul | ||
| 128 | [ "$1" = "d" ] && echo Ub | ||
| 129 | [ "$1" = "e" ] && echo Fd | ||
| 130 | [ "$1" = "f" ] && echo Rd | ||
| 131 | [ "$1" = "g" ] && echo Ld | ||
| 132 | [ "$1" = "i" ] && echo Fr | ||
| 133 | [ "$1" = "j" ] && echo Lu | ||
| 134 | [ "$1" = "k" ] && echo Rb | ||
| 135 | [ "$1" = "l" ] && echo Df | ||
| 136 | [ "$1" = "m" ] && echo Db | ||
| 137 | [ "$1" = "n" ] && echo Dr | ||
| 138 | [ "$1" = "o" ] && echo Fl | ||
| 139 | [ "$1" = "p" ] && echo Dl | ||
| 140 | [ "$1" = "r" ] && echo Bu | ||
| 141 | [ "$1" = "s" ] && echo Bd | ||
| 142 | [ "$1" = "t" ] && echo Bl | ||
| 143 | [ "$1" = "u" ] && echo Br | ||
| 144 | [ "$1" = "v" ] && echo Lf | ||
| 145 | [ "$1" = "w" ] && echo Lb | ||
| 146 | [ "$1" = "x" ] && echo Ru | ||
| 147 | [ "$1" = "z" ] && echo Rf | ||
| 148 | } | ||
| 149 | |||
| 150 | edit() { | ||
| 151 | mkdir -p "$basedir/$1/$2/$3" | ||
| 152 | $editor "$basedir/$1/$2/$3/$4" | ||
| 153 | } | ||
| 154 | |||
| 155 | showall_c() { | ||
| 156 | all_letters="a b c d e f g j k l m n o p r s t u v w z" | ||
| 157 | buffer="$1" | ||
| 158 | firstletter="$2" | ||
| 159 | firsttarget="$(corner $firstletter)" | ||
| 160 | for secondletter in $all_letters; do | ||
| 161 | secondtarget="$(corner $secondletter)" | ||
| 162 | f="$basedir/corners/$buffer/$firsttarget/$secondtarget" | ||
| 163 | [ -f "$f" ] || continue | ||
| 164 | line="$(head -n 1 "$f")" | ||
| 165 | printf '%s %s\n' "$firstletter$secondletter" "$line" | ||
| 166 | done | ||
| 167 | } | ||
| 168 | |||
| 169 | showall_e() { | ||
| 170 | all_letters="a b c d e f g i j k l m n o p r s t u v w z" | ||
| 171 | buffer="$1" | ||
| 172 | firstletter="$2" | ||
| 173 | firsttarget="$(edge $firstletter)" | ||
| 174 | for secondletter in $all_letters; do | ||
| 175 | secondtarget="$(edge $secondletter)" | ||
| 176 | f="$basedir/edges/$buffer/$firsttarget/$secondtarget" | ||
| 177 | [ -f "$f" ] || continue | ||
| 178 | line="$(head -n 1 "$f")" | ||
| 179 | printf '%s %s\n' "$firstletter$secondletter" "$line" | ||
| 180 | done | ||
| 181 | } | ||
| 182 | |||
| 183 | showall_w() { | ||
| 184 | all_letters="a b c d e f g i j k l m n o p r s t u v w x z" | ||
| 185 | buffer="$1" | ||
| 186 | firstletter="$2" | ||
| 187 | firsttarget="$(wing $firstletter)" | ||
| 188 | for secondletter in $all_letters; do | ||
| 189 | secondtarget="$(wing $secondletter)" | ||
| 190 | f="$basedir/wings/$buffer/$firsttarget/$secondtarget" | ||
| 191 | [ -f "$f" ] || continue | ||
| 192 | line="$(head -n 1 "$f")" | ||
| 193 | printf '%s %s\n' "$firstletter$secondletter" "$line" | ||
| 194 | done | ||
| 195 | } | ||
| 196 | |||
| 197 | showall_x() { | ||
| 198 | all_letters="a b c d e f g i j k l m n o p r s t u v w x z" | ||
| 199 | buffer="$1" | ||
| 200 | firstletter="$2" | ||
| 201 | firsttarget="$(xcenter $firstletter)" | ||
| 202 | for secondletter in $all_letters; do | ||
| 203 | secondtarget="$(xcenter $secondletter)" | ||
| 204 | f="$basedir/xcenters/$buffer/$firsttarget/$secondtarget" | ||
| 205 | [ -f "$f" ] || continue | ||
| 206 | line="$(head -n 1 "$f")" | ||
| 207 | printf '%s %s\n' "$firstletter$secondletter" "$line" | ||
| 208 | done | ||
| 209 | } | ||
| 210 | |||
| 211 | showall_t() { | ||
| 212 | all_letters="a b c d e f g i j k l m n o p r s t u v w x z" | ||
| 213 | buffer="$1" | ||
| 214 | firstletter="$2" | ||
| 215 | firsttarget="$(tcenter $firstletter)" | ||
| 216 | for secondletter in $all_letters; do | ||
| 217 | secondtarget="$(tcenter $secondletter)" | ||
| 218 | f="$basedir/tcenters/$buffer/$firsttarget/$secondtarget" | ||
| 219 | [ -f "$f" ] || continue | ||
| 220 | line="$(head -n 1 "$f")" | ||
| 221 | printf '%s %s\n' "$firstletter$secondletter" "$line" | ||
| 222 | done | ||
| 223 | } | ||
| 224 | |||
| 225 | export_csv_c() { | ||
| 226 | sorted_letters="d b c l n p m k z f j v w g a o e s r u t" | ||
| 227 | buffer="$cbuffer" | ||
| 228 | f="$basedir/corners/$buffer" | ||
| 229 | printf '"",' | ||
| 230 | for first in $sorted_letters; do | ||
| 231 | printf '"%s",' "$(corner $first)" | ||
| 232 | done | ||
| 233 | printf '\n' | ||
| 234 | for first in $sorted_letters; do | ||
| 235 | firstpiece="$(corner $first)" | ||
| 236 | printf '"%s",' "$firstpiece" | ||
| 237 | for second in $sorted_letters; do | ||
| 238 | g="$f/$firstpiece/$(corner $second)" | ||
| 239 | if [ "$first" = "$second" ] || [ ! -f "$g" ]; then | ||
| 240 | printf '"",' | ||
| 241 | else | ||
| 242 | printf '"%s",' "$(head -n 1 "$g")" | ||
| 243 | fi | ||
| 244 | done | ||
| 245 | printf '\n' | ||
| 246 | done | ||
| 247 | } | ||
| 248 | |||
| 249 | export_csv_e() { | ||
| 250 | sorted_letters="d c b n l p m k z f v j w g i a o e t r u s" | ||
| 251 | buffer="$ebuffer" | ||
| 252 | f="$basedir/edges/$buffer" | ||
| 253 | printf '"",' | ||
| 254 | for first in $sorted_letters; do | ||
| 255 | printf '"%s",' "$(edge $first)" | ||
| 256 | done | ||
| 257 | printf '\n' | ||
| 258 | for first in $sorted_letters; do | ||
| 259 | firstpiece="$(edge $first)" | ||
| 260 | printf '"%s",' "$firstpiece" | ||
| 261 | for second in $sorted_letters; do | ||
| 262 | g="$f/$firstpiece/$(edge $second)" | ||
| 263 | if [ "$first" = "$second" ] || [ ! -f "$g" ]; then | ||
| 264 | printf '"",' | ||
| 265 | else | ||
| 266 | printf '"%s",' "$(head -n 1 "$g")" | ||
| 267 | fi | ||
| 268 | done | ||
| 269 | printf '\n' | ||
| 270 | done | ||
| 271 | } | ||
| 272 | |||
| 273 | export_csv_w() { | ||
| 274 | sorted_letters="b d c n l p m k x z f v j w g i a o e t r u s" | ||
| 275 | buffer="$wbuffer" | ||
| 276 | f="$basedir/wings/$buffer" | ||
| 277 | printf '"",' | ||
| 278 | for first in $sorted_letters; do | ||
| 279 | printf '"%s",' "$(wing $first)" | ||
| 280 | done | ||
| 281 | printf '\n' | ||
| 282 | for first in $sorted_letters; do | ||
| 283 | firstpiece="$(wing $first)" | ||
| 284 | printf '"%s",' "$firstpiece" | ||
| 285 | for second in $sorted_letters; do | ||
| 286 | g="$f/$firstpiece/$(wing $second)" | ||
| 287 | if [ "$first" = "$second" ] || [ ! -f "$g" ]; then | ||
| 288 | printf '"",' | ||
| 289 | else | ||
| 290 | printf '"%s",' "$(head -n 1 "$g")" | ||
| 291 | fi | ||
| 292 | done | ||
| 293 | printf '\n' | ||
| 294 | done | ||
| 295 | } | ||
| 296 | |||
| 297 | export_csv_x() { | ||
| 298 | sorted_letters="d c b l n p m k x z f j v w g i a o e s r u t" | ||
| 299 | buffer="$xbuffer" | ||
| 300 | f="$basedir/xcenters/$buffer" | ||
| 301 | printf '"",' | ||
| 302 | for first in $sorted_letters; do | ||
| 303 | printf '"%s",' "$(xcenter $first)" | ||
| 304 | done | ||
| 305 | printf '\n' | ||
| 306 | for first in $sorted_letters; do | ||
| 307 | firstpiece="$(xcenter $first)" | ||
| 308 | printf '"%s",' "$firstpiece" | ||
| 309 | for second in $sorted_letters; do | ||
| 310 | g="$f/$firstpiece/$(xcenter $second)" | ||
| 311 | if [ "$first" = "$second" ] || [ ! -f "$g" ]; then | ||
| 312 | printf '"",' | ||
| 313 | else | ||
| 314 | printf '"%s",' "$(head -n 1 "$g")" | ||
| 315 | fi | ||
| 316 | done | ||
| 317 | printf '\n' | ||
| 318 | done | ||
| 319 | } | ||
| 320 | |||
| 321 | export_csv_t() { | ||
| 322 | sorted_letters="d c b l n p m k x z f j v w g i a o e s r u t" | ||
| 323 | buffer="$tbuffer" | ||
| 324 | f="$basedir/tcenters/$buffer" | ||
| 325 | printf '"",' | ||
| 326 | for first in $sorted_letters; do | ||
| 327 | printf '"%s",' "$(tcenter $first)" | ||
| 328 | done | ||
| 329 | printf '\n' | ||
| 330 | for first in $sorted_letters; do | ||
| 331 | firstpiece="$(tcenter $first)" | ||
| 332 | printf '"%s",' "$firstpiece" | ||
| 333 | for second in $sorted_letters; do | ||
| 334 | g="$f/$firstpiece/$(tcenter $second)" | ||
| 335 | if [ "$first" = "$second" ] || [ ! -f "$g" ]; then | ||
| 336 | printf '"",' | ||
| 337 | else | ||
| 338 | printf '"%s",' "$(head -n 1 "$g")" | ||
| 339 | fi | ||
| 340 | done | ||
| 341 | printf '\n' | ||
| 342 | done | ||
| 343 | } | ||
| 344 | |||
| 345 | run() { | ||
| 346 | case "$1" in | ||
| 347 | edit) | ||
| 348 | editor="$default_editor" | ||
| 349 | shift | ||
| 350 | ;; | ||
| 351 | export) | ||
| 352 | if [ "$2" = "all" ]; then | ||
| 353 | mkdir -p bldsheets | ||
| 354 | export_csv_c > bldsheets/corners.csv | ||
| 355 | export_csv_e > bldsheets/edges.csv | ||
| 356 | export_csv_w > bldsheets/wings.csv | ||
| 357 | export_csv_x > bldsheets/xcenters.csv | ||
| 358 | export_csv_t > bldsheets/tcenters.csv | ||
| 359 | echo "Sheets exported to bldsheets/" | ||
| 360 | return | ||
| 361 | fi | ||
| 362 | #TODO add option for alternative buffers | ||
| 363 | [ "$2" != "c" ] && [ "$2" != "e" ] && \ | ||
| 364 | [ "$2" != "w" ] && [ "$2" != "x" ] && \ | ||
| 365 | [ "$2" != "t" ] && usage && return | ||
| 366 | export_csv_$2 | ||
| 367 | return | ||
| 368 | ;; | ||
| 369 | *) | ||
| 370 | editor="cat" | ||
| 371 | ;; | ||
| 372 | esac | ||
| 373 | |||
| 374 | type="$1" | ||
| 375 | if [ -z "$3" ]; then | ||
| 376 | letters="$2" | ||
| 377 | cbuf="$cbuffer" | ||
| 378 | ebuf="$ebuffer" | ||
| 379 | wbuf="$wbuffer" | ||
| 380 | xbuf="$xbuffer" | ||
| 381 | tbuf="$tbuffer" | ||
| 382 | else | ||
| 383 | letters="$3" | ||
| 384 | cbuf="$2" | ||
| 385 | ebuf="$2" | ||
| 386 | wbuf="$2" | ||
| 387 | xbuf="$2" | ||
| 388 | tbuf="$2" | ||
| 389 | fi | ||
| 390 | |||
| 391 | letter1="$(echo "$letters" | cut -c 1)" | ||
| 392 | letter2="$(echo "$letters" | cut -b 2)" | ||
| 393 | |||
| 394 | [ -z "$letter1" ] && usage && return | ||
| 395 | |||
| 396 | case "$type" in | ||
| 397 | c) | ||
| 398 | if [ -n "$letter2" ]; then | ||
| 399 | edit corners $cbuf $(corner $letter1) $(corner $letter2) | ||
| 400 | else | ||
| 401 | showall_c $cbuf $letter1 | ||
| 402 | fi | ||
| 403 | ;; | ||
| 404 | e) | ||
| 405 | if [ -n "$letter2" ]; then | ||
| 406 | edit edges $ebuf $(edge $letter1) $(edge $letter2) | ||
| 407 | else | ||
| 408 | showall_e $ebuf $letter1 | ||
| 409 | fi | ||
| 410 | ;; | ||
| 411 | w) | ||
| 412 | if [ -n "$letter2" ]; then | ||
| 413 | edit wings $wbuf $(wing $letter1) $(wing $letter2) | ||
| 414 | else | ||
| 415 | showall_w $wbuf $letter1 | ||
| 416 | fi | ||
| 417 | ;; | ||
| 418 | x) | ||
| 419 | if [ -n "$letter2" ]; then | ||
| 420 | edit xcenters $xbuf $(xcenter $letter1) $(xcenter $letter2) | ||
| 421 | else | ||
| 422 | showall_x $xbuf $letter1 | ||
| 423 | fi | ||
| 424 | ;; | ||
| 425 | t) | ||
| 426 | if [ -n "$letter2" ]; then | ||
| 427 | edit tcenters $tbuf $(tcenter $letter1) $(tcenter $letter2) | ||
| 428 | else | ||
| 429 | showall_t $tbuf $letter1 | ||
| 430 | fi | ||
| 431 | ;; | ||
| 432 | *) | ||
| 433 | usage | ||
| 434 | ;; | ||
| 435 | esac | ||
| 436 | } | ||
| 437 | |||
| 438 | if [ -n "$1" ]; then | ||
| 439 | run $@ | ||
| 440 | else | ||
| 441 | while read -r args; do | ||
| 442 | [ -n "$args" ] && run $args | ||
| 443 | done | ||
| 444 | fi | ||
diff --git a/scripts/unused/config-backup b/scripts/unused/config-backup new file mode 100755 index 0000000..87bedeb --- /dev/null +++ b/scripts/unused/config-backup | |||
| @@ -0,0 +1,28 @@ | |||
| 1 | #!/bin/sh | ||
| 2 | |||
| 3 | # Copy my config files to my backup folder | ||
| 4 | |||
| 5 | folder=$HOME/box/configbackups | ||
| 6 | |||
| 7 | dotfiles=".bash_profile .bashrc .profile .inputrc .mblaze .nexrc .tmux.conf .virc .xinitrc .config/isyncrc" | ||
| 8 | config="colors fontconfig git imv msmtp zathura" | ||
| 9 | src="dmenu dwm st" | ||
| 10 | |||
| 11 | for d in config home src ssh; do mkdir -p "$folder/$d"; done | ||
| 12 | |||
| 13 | # copy | ||
| 14 | |||
| 15 | for i in $dotfiles; | ||
| 16 | do cp -Rf "$HOME"/"$i" "$folder"/home/ | ||
| 17 | done | ||
| 18 | |||
| 19 | for i in $config | ||
| 20 | do cp -Rf "$HOME"/.config/"$i" "$folder"/config/ | ||
| 21 | done | ||
| 22 | |||
| 23 | for i in $src | ||
| 24 | do mkdir "$folder"/src/"$i" | ||
| 25 | cp -f "$HOME"/.local/src/"$i"/*.{c,h} "$folder"/src/"$i"/ | ||
| 26 | done | ||
| 27 | |||
| 28 | cp "$HOME"/.ssh/config "$folder"/ssh/ | ||
diff --git a/scripts/unused/dmenu-mail-aliases b/scripts/unused/dmenu-mail-aliases new file mode 100755 index 0000000..76999de --- /dev/null +++ b/scripts/unused/dmenu-mail-aliases | |||
| @@ -0,0 +1,29 @@ | |||
| 1 | #!/bin/sh | ||
| 2 | |||
| 3 | # Select mail alias via dmenu | ||
| 4 | # The email address must be the second word in a line of $aliasfile | ||
| 5 | # Requires: dmenu (or similar) | ||
| 6 | |||
| 7 | # Usage: dmenu-mail-aliases [-m menu] | ||
| 8 | |||
| 9 | usage() { | ||
| 10 | echo "Usage: dmenu-mail-aliases [-m MENU]" | ||
| 11 | } | ||
| 12 | |||
| 13 | menu="dmenu -l 20" | ||
| 14 | aliasfile="$HOME/.mblaze/aliases" | ||
| 15 | |||
| 16 | while getopts "m:" opt; do | ||
| 17 | case "$opt" in | ||
| 18 | m) | ||
| 19 | menu="$OPTARG" | ||
| 20 | ;; | ||
| 21 | *) | ||
| 22 | usage | ||
| 23 | exit 1 | ||
| 24 | ;; | ||
| 25 | esac | ||
| 26 | done | ||
| 27 | shift $((OPTIND - 1)) | ||
| 28 | |||
| 29 | $menu <"$aliasfile" | awk '{print $NF}' | ||
diff --git a/scripts/unused/dmenu-websearch b/scripts/unused/dmenu-websearch new file mode 100755 index 0000000..a8e6a50 --- /dev/null +++ b/scripts/unused/dmenu-websearch | |||
| @@ -0,0 +1,8 @@ | |||
| 1 | #!/bin/sh | ||
| 2 | |||
| 3 | # dmenu prompt for websearch | ||
| 4 | # Requires: dmenu (or similar), websearch | ||
| 5 | |||
| 6 | menu=${MENU:-dmenu} | ||
| 7 | |||
| 8 | websearch "$(echo "" | $menu -p "websearch:")" | ||
diff --git a/scripts/unused/practice b/scripts/unused/practice new file mode 100755 index 0000000..628f15b --- /dev/null +++ b/scripts/unused/practice | |||
| @@ -0,0 +1,170 @@ | |||
| 1 | #!/bin/sh | ||
| 2 | |||
| 3 | # Script based on nissy (see https://nissy.tronto.net) to practice FMC | ||
| 4 | |||
| 5 | # Usage: practice [eo|dr|htr|slice] | ||
| 6 | |||
| 7 | nissy="nissy" | ||
| 8 | prompt="Press enter for a new scramble, Ctr+C (or Ctrl+Z) to quit:" | ||
| 9 | |||
| 10 | usage() { | ||
| 11 | echo "Usage: practice [eo|dr|htr|fin]" | ||
| 12 | exit 1 | ||
| 13 | } | ||
| 14 | |||
| 15 | practice_eo() { | ||
| 16 | nextscr="$(${nissy} scramble fmc)" | ||
| 17 | while true; do | ||
| 18 | scr="$nextscr" | ||
| 19 | echo "Scramble: $scr" | ||
| 20 | nextscr="$(${nissy} scramble fmc)" | ||
| 21 | eofb="$(${nissy} solve -N -M 4 eofb -p "$scr")" | ||
| 22 | eorl="$(${nissy} solve -N -M 4 eorl -p "$scr")" | ||
| 23 | eoud="$(${nissy} solve -N -M 4 eoud -p "$scr")" | ||
| 24 | nfbn="$(echo "$eofb" | grep -v '^$' | grep -Fv '(' | wc -l)" | ||
| 25 | nrln="$(echo "$eorl" | grep -v '^$' | grep -Fv '(' | wc -l)" | ||
| 26 | nudn="$(echo "$eoud" | grep -v '^$' | grep -Fv '(' | wc -l)" | ||
| 27 | nfbi="$(echo "$eofb" | grep '^(' | wc -l)" | ||
| 28 | nrli="$(echo "$eorl" | grep '^(' | wc -l)" | ||
| 29 | nudi="$(echo "$eoud" | grep '^(' | wc -l)" | ||
| 30 | nfbniss="$(echo "$eofb" | grep -v '^(' | grep '(' | wc -l)" | ||
| 31 | nrlniss="$(echo "$eorl" | grep -v '^(' | grep '(' | wc -l)" | ||
| 32 | nudniss="$(echo "$eoud" | grep -v '^(' | grep '(' | wc -l)" | ||
| 33 | nfb="$((nfbn + nfbi + nfbniss))" | ||
| 34 | nrl="$((nrln + nrli + nrlniss))" | ||
| 35 | nud="$((nudn + nudi + nudniss))" | ||
| 36 | n5linear="$(${nissy} solve -L -m 5 -M 5 eo -c "$scr")" | ||
| 37 | n5niss="$(${nissy} solve -N -m 5 -M 5 eo -c "$scr")" | ||
| 38 | n5nonlinear="$((n5niss - n5linear))" | ||
| 39 | read -r x | ||
| 40 | echo "FB: $nfb ($nfbn normal, $nfbi inverse, $nfbniss niss)" | ||
| 41 | echo "RL: $nrl ($nrln normal, $nrli inverse, $nrlniss niss)" | ||
| 42 | echo "UD: $nud ($nudn normal, $nudi inverse, $nudniss niss)" | ||
| 43 | echo "5 movers: $n5linear linear, $n5nonlinear NISS'd" | ||
| 44 | read -r x | ||
| 45 | echo "$eofb" | ||
| 46 | echo "---" | ||
| 47 | echo "$eorl" | ||
| 48 | echo "---" | ||
| 49 | echo "$eoud" | ||
| 50 | printf '\n%s' "$prompt" | ||
| 51 | read -r x | ||
| 52 | done | ||
| 53 | } | ||
| 54 | |||
| 55 | practice_dr() { | ||
| 56 | nextscr="$(${nissy} scramble eo)" | ||
| 57 | while true; do | ||
| 58 | scr="$nextscr" | ||
| 59 | echo "Scramble: $scr" | ||
| 60 | nextscr="$(${nissy} scramble eo)" | ||
| 61 | soleo="$(${nissy} solve -o -p drud-eofb "$scr")" | ||
| 62 | neo="$(echo "$soleo" | grep -v '^$' | wc -l)" | ||
| 63 | leo="$(echo "$soleo" | head -n 1 | wc -w)" | ||
| 64 | solht="$(${nissy} solve -o -p drud "$scr")" | ||
| 65 | nht="$(echo "$solht" | grep -v '^$' | wc -l)" | ||
| 66 | lht="$(echo "$solht" | head -n 1 | wc -w)" | ||
| 67 | soleolr="$(${nissy} solve -o -p drrl-eofb "$scr")" | ||
| 68 | neolr="$(echo "$soleolr" | grep -v '^$' | wc -l)" | ||
| 69 | leolr="$(echo "$soleolr" | head -n 1 | wc -w)" | ||
| 70 | solhtlr="$(${nissy} solve -o -p drrl "$scr")" | ||
| 71 | nhtlr="$(echo "$solhtlr" | grep -v '^$' | wc -l)" | ||
| 72 | lhtlr="$(echo "$solhtlr" | head -n 1 | wc -w)" | ||
| 73 | read -r x | ||
| 74 | echo "DR on U/D: $leo moves ($neo solutions)" | ||
| 75 | if [ "$nht" != "$neo" ]; then | ||
| 76 | echo "Breaking EO: $lht moves ($nht solutions)" | ||
| 77 | fi | ||
| 78 | echo "DR on R/L: $leolr moves ($neolr solutions)" | ||
| 79 | if [ "$nhtlr" != "$neolr" ]; then | ||
| 80 | echo "Breaking EO: $lhtlr moves ($nhtlr solutions)" | ||
| 81 | fi | ||
| 82 | read -r x | ||
| 83 | echo "On U/D:" | ||
| 84 | echo "$soleo" | ||
| 85 | echo "" | ||
| 86 | if [ "$nht" != "$neo" ] || [ "$lht" != "$leo" ]; then | ||
| 87 | echo "Breaking EO:" | ||
| 88 | echo "$solht" | ||
| 89 | echo "" | ||
| 90 | fi | ||
| 91 | echo "On R/L:" | ||
| 92 | echo "$soleolr" | ||
| 93 | echo "" | ||
| 94 | if [ "$nhtlr" != "$neolr" ] || [ "$lhtlr" != "$leolr" ]; then | ||
| 95 | echo "Breaking EO:" | ||
| 96 | echo "$solhtlr" | ||
| 97 | echo "" | ||
| 98 | fi | ||
| 99 | printf '\n%s' "$prompt" | ||
| 100 | read -r x | ||
| 101 | done | ||
| 102 | } | ||
| 103 | |||
| 104 | practice_htr() { | ||
| 105 | nextscr="$(${nissy} scramble dr)" | ||
| 106 | while true; do | ||
| 107 | scr="$nextscr" | ||
| 108 | echo "Scramble: $scr" | ||
| 109 | nextscr="$(${nissy} scramble dr)" | ||
| 110 | sol="$(${nissy} solve -o -p htr "$scr")" | ||
| 111 | nsol="$(echo "$sol" | grep -v '^$' | wc -l)" | ||
| 112 | len="$(echo "$sol" | head -n 1 | wc -w)" | ||
| 113 | fin="$(${nissy} solve -o -p drfin "$scr")" | ||
| 114 | lenf="$(echo "$fin" | head -n 1 | wc -w)" | ||
| 115 | slice="$(${nissy} solve -o -p drslice "$scr")" | ||
| 116 | lens="$(echo "$slice" | head -n 1 | wc -w)" | ||
| 117 | read -r x | ||
| 118 | echo "$len moves ($nsol solutions)" | ||
| 119 | read -r x | ||
| 120 | echo "$sol" | ||
| 121 | if [ "$lenf" != "$lens" ]; then | ||
| 122 | echo "" | ||
| 123 | echo "Optimal leave slice ($lens):" | ||
| 124 | echo "$slice" | ||
| 125 | fi | ||
| 126 | echo "" | ||
| 127 | echo "Optimal DR finish ($lenf):" | ||
| 128 | echo "$fin" | ||
| 129 | printf '\n%s' "$prompt" | ||
| 130 | read -r x | ||
| 131 | done | ||
| 132 | } | ||
| 133 | |||
| 134 | practice_fin() { | ||
| 135 | nextscr="$(${nissy} scramble htr)" | ||
| 136 | while true; do | ||
| 137 | scr="$nextscr" | ||
| 138 | echo "Scramble: $scr" | ||
| 139 | nextscr="$(${nissy} scramble htr)" | ||
| 140 | sol="$(${nissy} solve -o -p drudslice "$scr")" | ||
| 141 | nsol="$(echo "$sol" | grep -v '^$' | wc -l)" | ||
| 142 | len="$(echo "$sol" | head -n 1 | wc -w)" | ||
| 143 | fin="$(${nissy} solve -o -p drudfin "$scr")" | ||
| 144 | nfin="$(echo "$fin" | grep -v '^$' | wc -l)" | ||
| 145 | lenf="$(echo "$fin" | head -n 1 | wc -w)" | ||
| 146 | opt="$(${nissy} solve -o -p "$scr")" | ||
| 147 | leno="$(echo "$opt" | head -n 1 | wc -w)" | ||
| 148 | read -r x | ||
| 149 | echo "Leave slice: $len moves ($nsol solutions)" | ||
| 150 | if [ "$lenf" != "$len" ]; then | ||
| 151 | echo "DR finish: $lenf moves" | ||
| 152 | fi | ||
| 153 | read -r x | ||
| 154 | echo "$sol" | ||
| 155 | if [ "$lenf" != "$len" ]; then | ||
| 156 | echo "" | ||
| 157 | echo "Optimal DR finish ($lenf):" | ||
| 158 | echo "$fin" | ||
| 159 | fi | ||
| 160 | if [ "$leno" != "$lenf" ]; then | ||
| 161 | echo "" | ||
| 162 | echo "Optimal DR-breaking ($leno):" | ||
| 163 | echo "$opt" | ||
| 164 | fi | ||
| 165 | printf '\n%s' "$prompt" | ||
| 166 | read -r x | ||
| 167 | done | ||
| 168 | } | ||
| 169 | |||
| 170 | "practice_$1" || usage | ||
diff --git a/scripts/unused/share b/scripts/unused/share new file mode 100755 index 0000000..1a27d90 --- /dev/null +++ b/scripts/unused/share | |||
| @@ -0,0 +1,13 @@ | |||
| 1 | #!/bin/sh | ||
| 2 | |||
| 3 | # One-liner to upload stuff to my webserver | ||
| 4 | |||
| 5 | srv=tronto.net | ||
| 6 | dir=$(tr -cd 'a-z0-9' < /dev/random | fold -w 8 | head -n 1) | ||
| 7 | htp=https://share.tronto.net/$dir | ||
| 8 | pth=/var/www/htdocs/share.tronto.net/$dir | ||
| 9 | url=$srv:$pth | ||
| 10 | |||
| 11 | ssh tronto.net mkdir "$pth" | ||
| 12 | scp "$@" "$url"/ | ||
| 13 | for i in "$@"; do echo "$htp/$(basename $i)"; done | ||
diff --git a/scripts/unused/translate b/scripts/unused/translate new file mode 100755 index 0000000..9442844 --- /dev/null +++ b/scripts/unused/translate | |||
| @@ -0,0 +1,11 @@ | |||
| 1 | #!/bin/sh | ||
| 2 | |||
| 3 | # Opens google translate | ||
| 4 | |||
| 5 | translator="https://translate.google.com/" | ||
| 6 | from=$1 | ||
| 7 | to=$2 | ||
| 8 | |||
| 9 | shift 2 | ||
| 10 | text=$(echo "$@" | sed 's/ /\%20/g') | ||
| 11 | open-url "${translator}?sl=${from}&tl=${to}&text=${text}&op=translate" | ||
diff --git a/scripts/unused/websearch b/scripts/unused/websearch new file mode 100755 index 0000000..dddcc20 --- /dev/null +++ b/scripts/unused/websearch | |||
| @@ -0,0 +1,11 @@ | |||
| 1 | #!/bin/sh | ||
| 2 | |||
| 3 | # Perform a web search | ||
| 4 | |||
| 5 | browser=${BROWSER:-firefox} | ||
| 6 | searchengine="https://www.startpage.com/sp/search?query=" | ||
| 7 | #searchengine="https://duckduckgo.com/?q=" | ||
| 8 | #searchendinge="https://www.google.com/search?q=" | ||
| 9 | |||
| 10 | arg=$(echo "$@" | sed 's/ /\+/g') | ||
| 11 | [ -n "$arg" ] && spawn "$browser" "${searchengine}$arg" | ||
diff --git a/scripts/unused/xplumb b/scripts/unused/xplumb new file mode 100755 index 0000000..1d89796 --- /dev/null +++ b/scripts/unused/xplumb | |||
| @@ -0,0 +1,65 @@ | |||
| 1 | #!/bin/sh | ||
| 2 | |||
| 3 | # My interpretation of a plumber (plan9 style). | ||
| 4 | # It scans the selected text (xsel) and decides what to do with it among | ||
| 5 | # some possibilities (open file, open url, man page...). If none is matched, | ||
| 6 | # a choice is prompted. | ||
| 7 | |||
| 8 | # Requires: dmenu (or similar), mail-compose, open-file, terminal, websearch, | ||
| 9 | # xedit, xsel | ||
| 10 | |||
| 11 | # TODO: | ||
| 12 | # send mail to email address; | ||
| 13 | # calendar if it is a date | ||
| 14 | # choice: pipe to another program | ||
| 15 | |||
| 16 | browser=${BROWSER:-firefox} | ||
| 17 | menu=${MENU:-dmenu} | ||
| 18 | menuopts="-l 10" | ||
| 19 | |||
| 20 | text=$(xsel | sed 's/\n/ /g') | ||
| 21 | if [ "${#text}" -ge 11 ]; then | ||
| 22 | shorttext=$(echo "$text" | cut -b 1-10)... | ||
| 23 | else | ||
| 24 | shorttext="$text" | ||
| 25 | fi | ||
| 26 | |||
| 27 | choice() { | ||
| 28 | chosen=$(printf "websearch\nedit" | \ | ||
| 29 | $menu $menuopts -p "What to do with \"$shorttext\"?") | ||
| 30 | |||
| 31 | if [ "$chosen" = "websearch" ]; then | ||
| 32 | websearch "$text" | ||
| 33 | elif [ "$chosen" = "edit" ]; then | ||
| 34 | f=$(mktemp) | ||
| 35 | xsel > "$f" | ||
| 36 | xedit "$f" | ||
| 37 | fi | ||
| 38 | } | ||
| 39 | |||
| 40 | trymail() { | ||
| 41 | addr=$(echo "$1" | addressgrep) | ||
| 42 | ( [ -n "$addr" ] && mail-compose "$addr" ) || return 1 | ||
| 43 | } | ||
| 44 | |||
| 45 | tryman() { | ||
| 46 | number=$(echo "$1" | sed 's/[^1-8]//g') | ||
| 47 | name=$(echo "$1" | sed 's/([1-8])//g' | sed 's/ //g') | ||
| 48 | if [ "$(man -w "$number" "$name" | wc -l)" = 1 ]; then | ||
| 49 | terminal -e man "$number" "$name" | ||
| 50 | return 0 | ||
| 51 | else | ||
| 52 | return 1 | ||
| 53 | fi | ||
| 54 | } | ||
| 55 | |||
| 56 | tryurl() { | ||
| 57 | url=$(echo "$1" | urlgrep) | ||
| 58 | ( [ -n "$url" ] && "$browser" "$url" ) || return 1 | ||
| 59 | } | ||
| 60 | |||
| 61 | #open-file -s spawn "$text" || \ | ||
| 62 | tryurl "$text" || \ | ||
| 63 | trymail "$text" || \ | ||
| 64 | tryman "$text" || \ | ||
| 65 | choice | ||
diff --git a/scripts/urlgrep b/scripts/urlgrep new file mode 100755 index 0000000..49afac6 --- /dev/null +++ b/scripts/urlgrep | |||
| @@ -0,0 +1,9 @@ | |||
| 1 | #!/bin/sh | ||
| 2 | |||
| 3 | # Find all URLs in stdin, print them newline-separated to stdout | ||
| 4 | |||
| 5 | protocols='http|https|ftp|sftp|gemini|mailto' | ||
| 6 | valid_chars="][a-zA-Z0-9_~/?#@!$&'()*+=.,;:-" | ||
| 7 | regex="(($protocols):|www\.)[$valid_chars]+" | ||
| 8 | |||
| 9 | egrep -o "$regex" | ||
diff --git a/scripts/virename b/scripts/virename new file mode 100755 index 0000000..8c30ccf --- /dev/null +++ b/scripts/virename | |||
| @@ -0,0 +1,25 @@ | |||
| 1 | #!/bin/sh | ||
| 2 | |||
| 3 | # Rename all files in the current directory with a visual editor. | ||
| 4 | # Similar to sel add all && sel mv, but it actually works. | ||
| 5 | |||
| 6 | file=$(mktemp) | ||
| 7 | file2=$(mktemp) | ||
| 8 | editor=${EDITOR:-vi} | ||
| 9 | |||
| 10 | ls | tee "$file" > "$file2" | ||
| 11 | $editor "$file2" | ||
| 12 | |||
| 13 | if [ "$(wc -l "$file" | awk '{print $1}')" != \ | ||
| 14 | "$(wc -l "$file2" | awk '{print $1}')" ]; then | ||
| 15 | echo "Error reading new file names" | ||
| 16 | else | ||
| 17 | paste "$file" "$file2" | while read -r f; do | ||
| 18 | fold=$(echo "$f" | sed 's/ .*//') | ||
| 19 | fnew=$(echo "$f" | sed 's/.* //') | ||
| 20 | if [ "$fold" != "$fnew" ]; then | ||
| 21 | mv "$fold" "$fnew" \ | ||
| 22 | || echo "Error renaming $fold to $fnew" | ||
| 23 | fi | ||
| 24 | done | ||
| 25 | fi | ||
diff --git a/scripts/xedit b/scripts/xedit new file mode 100755 index 0000000..3f68f24 --- /dev/null +++ b/scripts/xedit | |||
| @@ -0,0 +1,9 @@ | |||
| 1 | #!/bin/sh | ||
| 2 | |||
| 3 | # My X editor | ||
| 4 | # Requires: terminal | ||
| 5 | |||
| 6 | editor=${EDITOR:-${VISUAL:-vi}} | ||
| 7 | xed=${XEDIT:-"terminal "$editor""} | ||
| 8 | |||
| 9 | $xed "$@" | ||
diff --git a/scripts/xedit-filter b/scripts/xedit-filter new file mode 100755 index 0000000..7caf12c --- /dev/null +++ b/scripts/xedit-filter | |||
| @@ -0,0 +1,9 @@ | |||
| 1 | #!/bin/sh | ||
| 2 | |||
| 3 | # Open stdin in a text editor and sends modified selection to stdout | ||
| 4 | # Requires: xedit | ||
| 5 | |||
| 6 | f=$(mktemp) | ||
| 7 | cat > "$f" | ||
| 8 | xedit "$f" && cat "$f" | ||
| 9 | |||
diff --git a/scripts/xroot-update b/scripts/xroot-update new file mode 100755 index 0000000..44ab6c1 --- /dev/null +++ b/scripts/xroot-update | |||
| @@ -0,0 +1,8 @@ | |||
| 1 | #!/bin/sh | ||
| 2 | |||
| 3 | # Updates the xroot window with info from status | ||
| 4 | # Requires: status | ||
| 5 | |||
| 6 | # Usage: xroot-update | ||
| 7 | |||
| 8 | xsetroot -name " $(status) " | ||
diff --git a/scripts/xwallpaper-random-notify b/scripts/xwallpaper-random-notify new file mode 100755 index 0000000..1d9e2bf --- /dev/null +++ b/scripts/xwallpaper-random-notify | |||
| @@ -0,0 +1,17 @@ | |||
| 1 | #!/bin/sh | ||
| 2 | |||
| 3 | # Set a random background from the wallpapers folder and notify about it | ||
| 4 | # Requires: xwallpaper (or feh), notify-send or similar (optional) | ||
| 5 | |||
| 6 | #notify=notify-send | ||
| 7 | notify="notify push" | ||
| 8 | |||
| 9 | folder=~/pictures/wallpapers | ||
| 10 | pic=$(ls $folder | sort -R | head -1) | ||
| 11 | |||
| 12 | # Alternative: use feh | ||
| 13 | #feh --bg-fill --no-fehbg "$folder"/"$pic" | ||
| 14 | xwallpaper --zoom "$folder"/"$pic" | ||
| 15 | |||
| 16 | # Uncomment to notify | ||
| 17 | #$notify "Background of the day" "$pic" | ||
