summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/2fa21
-rwxr-xr-xscripts/aoc52
-rwxr-xr-xscripts/battery-checknow22
-rwxr-xr-xscripts/battery-status17
-rwxr-xr-xscripts/clip63
-rwxr-xr-xscripts/cth8
-rwxr-xr-xscripts/cubeviz62
-rwxr-xr-xscripts/dmenu-bookmarks14
-rwxr-xr-xscripts/dmenu-dwm-sessionmanager44
-rwxr-xr-xscripts/dmenu-filepicker47
-rwxr-xr-xscripts/dmenu-screenshot40
-rwxr-xr-xscripts/dmenu-unmount49
-rwxr-xr-xscripts/dmenu-urlselect28
-rwxr-xr-xscripts/event154
-rwxr-xr-xscripts/feed97
-rwxr-xr-xscripts/ffmpeg-facecam6
-rwxr-xr-xscripts/ffmpeg-screenrecord8
-rwxr-xr-xscripts/mail-compose6
-rwxr-xr-xscripts/mergepdf26
-rwxr-xr-xscripts/notify37
-rwxr-xr-xscripts/old/brightness16
-rwxr-xr-xscripts/old/dmenu-filepicker-old31
-rwxr-xr-xscripts/old/dunst-toggle14
-rwxr-xr-xscripts/old/gfmt9
-rwxr-xr-xscripts/old/mail-checknow18
-rwxr-xr-xscripts/old/mblaze-extras61
-rwxr-xr-xscripts/old/notify-battery10
-rwxr-xr-xscripts/old/notify-status7
-rwxr-xr-xscripts/old/notify-time15
-rwxr-xr-xscripts/old/sfeed-browser80
-rwxr-xr-xscripts/old/theme23
-rwxr-xr-xscripts/old/togglemute18
-rwxr-xr-xscripts/old/volume13
-rwxr-xr-xscripts/old/xkboptions6
-rwxr-xr-xscripts/old/xprop-active-window-id6
-rwxr-xr-xscripts/open-file122
-rwxr-xr-xscripts/open-stdin12
-rwxr-xr-xscripts/open-url28
-rwxr-xr-xscripts/popup-cal126
-rwxr-xr-xscripts/popup-cal36
-rwxr-xr-xscripts/popup-terminal5
-rwxr-xr-xscripts/secret52
-rwxr-xr-xscripts/sel136
-rwxr-xr-xscripts/spawn5
-rwxr-xr-xscripts/status13
-rwxr-xr-xscripts/status-linux52
-rwxr-xr-xscripts/status-openbsd26
-rwxr-xr-xscripts/templess10
-rwxr-xr-xscripts/terminal7
-rwxr-xr-xscripts/trash44
-rwxr-xr-xscripts/unused/addressgrep8
-rwxr-xr-xscripts/unused/alg444
-rwxr-xr-xscripts/unused/config-backup28
-rwxr-xr-xscripts/unused/dmenu-mail-aliases29
-rwxr-xr-xscripts/unused/dmenu-websearch8
-rwxr-xr-xscripts/unused/practice170
-rwxr-xr-xscripts/unused/share13
-rwxr-xr-xscripts/unused/translate11
-rwxr-xr-xscripts/unused/websearch11
-rwxr-xr-xscripts/unused/xplumb65
-rwxr-xr-xscripts/urlgrep9
-rwxr-xr-xscripts/virename25
-rwxr-xr-xscripts/xedit9
-rwxr-xr-xscripts/xedit-filter9
-rwxr-xr-xscripts/xroot-update8
-rwxr-xr-xscripts/xwallpaper-random-notify17
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
9secrets_folder="$HOME/box/secrets"
10
11if [ -z "$1" ]; then
12 echo "usage: 2fa service [time]"
13 exit 1
14fi
15
16if [ -n "$2" ]; then
17 t="-N $2"
18fi
19
20secret="$(secret show "$secrets_folder/$1-2fa")"
21oathtool -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
10editor="vi a.py"
11basedir="$HOME/src/aoc"
12lynx_cookie_file="$(mktemp)"
13clibrowser="lynx -cookie_file=$lynx_cookie_file"
14
15year="${1:-$(date +'%Y')}"
16day="${2:-$(date +'%d')}"
17daynozero="$(echo "$day" | sed 's/^0//')"
18
19cd "$basedir/$year/$day"
20
21# Download the puzzle input and save it to input.txt
22if [ ! -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
25fi
26
27# Download the problem statement page and split out the code blocks
28url="https://adventofcode.com/$year/day/$daynozero"
29curl "$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.
45printf 'adventofcode.com\tFALSE\t/\tTRUE\t2079722976\tsession\t%s' \
46 "$AOC_SESSION_COOKIE" > "$lynx_cookie_file"
47tmux 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
6file="${XDG_DATA_HOME:-$HOME/.local/share}/batterystatus"
7notify=${NOTIFY:-"notify push"}
8low=20
9crit=15
10
11new=$(battery-status)
12level=$(echo "$new" | sed 's/%.*//')
13status=$(echo "$new" | awk '{print $2}')
14
15[ "$status" = "Discharging" ] && [ "$level" -le "$low" ] && status="Low"
16[ "$status" = "Discharging" ] && [ "$level" -le "$crit" ] && status="Critical"
17
18if [ "$status" != "$(cat "$file")" ] || [ "$status" = "Critical" ]; then
19 $notify "Battery: $(battery-status)"
20fi
21
22echo "$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
6battery="/sys/class/power_supply/BAT0"
7message=""
8
9if [ -d $battery ]; then
10 capacity=$(cat $battery/capacity)
11 status=$(cat $battery/status)
12 message="$capacity% $status"
13else
14 message="No battery"
15fi
16
17echo "$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
14menu="dmenu -i -l 25"
15
16usage() {
17 echo "Usage: clip [-m MENU]"
18}
19
20while getopts "m:" opt; do
21 case "$opt" in
22 m)
23 menu="$OPTARG"
24 ;;
25 *)
26 usage
27 exit 1
28 ;;
29 esac
30done
31shift "$((OPTIND - 1))"
32
33dir="/tmp/clipdir"
34mkdir -p "$dir"
35
36file1="$(mktemp -p "$dir" "$(date +%s)".XXXXXX)"
37file2="$(mktemp -p "$dir" "$(date +%s)"b.XXXXX)"
38echo "created $file1"
39echo "created $file2"
40xsel > "$file1"
41xsel -b > "$file2"
42
43# Avoid duplicates
44for 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
47done
48
49list="$(mktemp)"
50ls "$dir" > "$list";
51
52lines="$(mktemp)"
53for 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"
58done
59
60selected=$(sort -r "$lines" | $menu | awk '{print $1}')
61if [ -n "$selected" ]; then
62 xsel -ib < "$dir/$selected"
63fi
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
6name=$1
7shift
8sed -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
10visualcube="http://cube.rider.biz/visualcube.php"
11
12usage() {
13 echo "Usage: cubeviz [type] [alg]"
14 echo "Types: trigger"
15 echo "Alg: use the standard notation"
16}
17
18trigger() {
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
54case "$1" in
55 trigger)
56 trigger "$2"
57 ;;
58 *)
59 usage
60 exit 1
61 ;;
62esac
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
9dir=$HOME/box/bookmarks
10picker="dmenu-filepicker"
11
12$picker "$@" "$dir" | while read -r line; do
13 cat "$line"
14done | 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
9sudo=doas
10wmname="dwm"
11shutdown_cmd="$sudo poweroff"
12reboot_cmd="$sudo reboot"
13closewm_cmd="pkill $wmname"
14
15menu="dmenu -i"
16prompt="Do you want to quit?"
17
18usage() {
19 echo "Usage: dmenu-dwm-sessionmanager [-m MENU]"
20}
21
22while getopts "m:" opt; do
23 case "$opt" in
24 m)
25 menu="$OPTARG"
26 ;;
27 *)
28 usage
29 exit 1
30 ;;
31 esac
32done
33shift $((OPTIND - 1))
34
35value=$(printf 'Shutdown\nReboot\nQuit dwm\n' | $menu -p "$prompt")
36
37if [ "$value" = "Shutdown" ]; then
38 $shutdown_cmd
39elif [ "$value" = "Reboot" ]; then
40 $reboot_cmd
41elif [ "$value" = "Quit $wmname" ]; then
42 $closewm_cmd
43fi
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
8menu="dmenu -i -l 15"
9
10usage() {
11 echo "Usage: dmenu-filepicker [-m MENU] [PATH]"
12}
13
14while getopts "m:" opt; do
15 case "$opt" in
16 m)
17 menu="$OPTARG"
18 ;;
19 *)
20 usage
21 exit 1
22 ;;
23 esac
24done
25shift $((OPTIND - 1))
26
27fullpath=$(realpath "${@:-"$(pwd)"}")
28
29while 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
47done
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
8usage() {
9 echo "Usage: dmenu-screenshot [-m MENU]"
10}
11
12menu="dmenu -i"
13prompt="Select type of screenshot:"
14
15while getopts "m:" opt; do
16 case "$opt" in
17 m)
18 menu="$OPTARG"
19 ;;
20 *)
21 usage
22 exit 1
23 ;;
24 esac
25done
26shift $((OPTIND - 1))
27
28folder="$HOME/box/pictures/screenshots"
29filename="screenshot_$(date +%Y-%m-%d-%H%M%S).png"
30filepath="${folder}/${filename}"
31
32t=$(printf 'Full\nSelection\n' | $menu -p "$prompt")
33if [ "$t" = "Full" ]; then
34 op="-window root"
35else
36 pkill xbanish # otherwise I can't use mouse to select area
37fi
38
39[ -n "$t" ] && sleep 0.1 && import $op "$filepath"
40spawn 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
9menu=dmenu
10writeout=${NOTIFY:-"notify push"}
11
12usage() {
13 echo "Usage: dmenu-unmount [-m MENU] [-w WRITER]"
14 echo "Example: dmenu-unmount -m slmenu -w echo"
15}
16
17while 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
30done
31shift $((OPTIND - 1))
32
33listdev=$(grep "media" /proc/mounts | sed 's/\/media.*\///g' | \
34 awk '{print $1" ("$2")"}')
35
36if [ -z "$listdev" ]; then
37 $writeout "Nothing to unmount"
38else
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
49fi
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
9menu="dmenu -i -l 20"
10
11usage() {
12 echo "Usage: dmenu-urlselect [-m MENU]"
13}
14
15while getopts "m:" opt; do
16 case "$opt" in
17 m)
18 menu="$OPTARG"
19 ;;
20 *)
21 usage
22 exit 1
23 ;;
24 esac
25done
26shift $((OPTIND - 1))
27
28urlgrep | $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
8file="$HOME/box/events" # Change to $XDG_DATA_HOME/events or whatever
9editor=${EDITOR:-vi}
10
11usage() {
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
24secondstoday() {
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
32secondstomin() {
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
40datetoseconds() {
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
49today() { echo "$(date +'%Y-%m-%d') 00:00"; }
50dayplus() {
51 d="$1"
52 n="$(datetoseconds $(today))"
53 echo "$((n+d*60*60*24))"
54}
55monday() { d="$(date +%u)"; dayplus "$((1-d))"; }
56monday1() { d="$(date +%u)"; dayplus "$((8-d))"; }
57monday2() { d="$(date +%u)"; dayplus "$((15-d))"; }
58daydiff() {
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
90secondsline() {
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
98filterlines() {
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
106list() {
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
126case "$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 ;;
154esac
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
9dir=$HOME/box/sfeed
10feeddir=$dir/urls
11destdir=$dir/new
12readdir=$dir/last
13menu="${FEEDMENU:-dmenu -l 20 -i}"
14urlopener=open-url
15
16usage() {
17 echo "Usage: feed [get|menu|clear|show]"
18}
19
20getnew() {
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
44show() {
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
55selectmenu() {
56 $menu | awk '{print $NF}' | xargs $urlopener
57}
58
59while getopts "m:" opt; do
60 case "$opt" in
61 m)
62 menu="$OPTARG"
63 ;;
64 *)
65 usage
66 exit 1
67 ;;
68 esac
69done
70
71shift $((OPTIND - 1))
72
73if [ -z "$1" ]; then
74 usage
75 exit 1
76fi
77
78case "$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 ;;
97esac
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
6ffplay -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
6outfile=${1:-output.mkv}
7
8ffmpeg -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
6terminal 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
8outname=merged.pdf
9
10usage() {
11 echo "Usage: mergepdf [-o OUTFILE] file1.pdf file2.pdf ..."
12}
13
14while getopts "o:" opt; do
15 case "$opt" in
16 o)
17 outname="$OPTARG"
18 ;;
19 *)
20 usage
21 ;;
22 esac
23done
24shift $((OPTIND - 1))
25
26gs -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
9update=xroot-update
10file="${XDG_DATA_HOME:-.local/share}/notify"
11date=$(date +'%H:%M')
12
13usage() {
14 echo "Usage: notify [push MESSAGE | clean | edit | show]"
15}
16
17touch "$file"
18case "$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 ;;
37esac
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"
12notify="herbe"
13
14pkill herbe # comment this too if not using herbe
15
16xbacklight -$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
7menu=${MENU:-dmenu}
8menuopts="-i -l 15"
9
10basedir="$(pwd)"
11
12next="${@:-$(pwd)}"
13
14while 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
29done
30
31cd "$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
6if [ "$(dunstctl is-paused)" = "false" ]; then
7 notify-send -t 3000 "Notifications: OFF" "Notifications will be hidden"
8 sleep 3
9 dunstctl set-paused true
10else
11 dunstctl set-paused false
12 notify-send -t 3000 "Notifications: ON" "Notifications reactivated"
13fi
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
7sed 's/ //' | \
8sed 'a\\' | \
9fold -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
6file="$XDG_DATA_HOME/newmail"
7#notify="notify-send"
8notify=herbe
9
10l=$(cat "$file")
11n=$(mpop -s | awk '/new*./{print $2}')
12
13if [ -n "$n" ]; then
14 echo "$n" > "$file"
15 if [ "$n" != "no" ] && [ "$l" != "$n" ]; then
16 $notify "New email ($n)"
17 fi
18fi
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
14menu=${MENU:-dmenu}
15mdir=$HOME/mail
16mpopdir=$HOME/.config/mpop
17
18mbextra_scan() {
19 folder=${1:-inbox}
20 mlist -t $mdir/$folder | mthread | mseq -S
21 mscan
22}
23
24mbextra_get() {
25 mpop --filter=$mpopdir/filter-$1.sh
26 minc -q $mdir/inbox
27 mbextra_scan inbox
28}
29
30mbextra_pick() {
31 field=$1
32 shift
33 mpick -t "$field =~~ \"$@\""
34}
35
36mbextra_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
49if [ -z "$1" ]; then
50 echo "Usage: mblaze-extras COMMAND"
51elif [ "$1" = "scan" ]; then
52 mbextra_scan $2
53elif [ "$1" = "get" ]; then
54 mbextra_get $2
55elif [ "$1" = "save" ]; then
56 shift
57 mbextra_save $@
58elif [ "$1" = "pick" ]; then
59 shift
60 mbextra_pick $@
61fi
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
8notify=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
7herbe "$(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
10notify=herbe
11
12t=$(date +"%H:%M:%S")
13d=$(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
18filepicker="dmenu-filepicker" # Try "nnn -p -"
19menu="dmenu -l 35 -i"
20urlopener=open-url
21sfd="$HOME/box/sfeed"
22showlast=10
23
24usage() {
25 echo "sfeed-browser [-m MENU]"
26}
27
28while getopts "m:" opt; do
29 case "$opt" in
30 m)
31 menu="$OPTARG"
32 ;;
33 *)
34 usage
35 exit 1
36 ;;
37 esac
38done
39
40# Might add more stuff later
41fixurl() {
42 sed 's/old\.reddit\.com/reddit\.com/'
43}
44
45dirtofeedpaths() {
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
53pathstosfeedrc() {
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
63feedmenu() {
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
70openfeeds() {
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"
78pathstosfeedrc < "$sfd/last" > "$sfd/sfeedrc"
79sfeed_update "$sfd/sfeedrc"
80feedmenu < "$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
8src=$HOME/.local/src
9
10case "$@" 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 ;;
21esac
22
23make && 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
7notify=herbe
8
9ismute=$(pulsemixer --toggle-mute --get-mute)
10
11if [ "$ismute" = "1" ]; then
12 m="muted"
13else
14 m="unmuted"
15fi
16
17pkill 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
8notify=herbe
9
10newvol=$(pulsemixer --change-volume "$1" --get-volume | awk '{print $1}')
11
12pkill 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
5setxkbmap -option compose:ralt
6setxkbmap -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
6xprop -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
9menu="dmenu -i -l 15"
10
11# Change default apps here
12video=${VIDEO:-vlc}
13music=${MUSIC:-vlc}
14pdf=${PDF:-zathura}
15img="${IMGVIEW:-nsxiv}"
16word="${WORDS:-libreoffice}"
17sheet="${SHEETS:-libreoffice}"
18html="${BROWSER:-firefox} --new-window"
19xedit="${XEDIT:-xedit}"
20
21usage() {
22 echo "Usage: open-file [-m MENU] [-s LAUNCHER] [-t MIMETYPE] [files...]"
23}
24
25openfile() {
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
93while 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
109done
110
111shift $((OPTIND - 1))
112
113if [ -n "$1" ]; then
114 while [ -n "$1" ]; do
115 openfile "$1" &
116 shift
117 done
118else
119 dmenu-filepicker -m "$menu" | while read -r line; do
120 openfile "$line" &
121 done
122fi
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
7folder=${TMPDIR:-/tmp}
8open=${OPENER:-open-file}
9
10tempfile=$(mktemp -p "$folder")
11
12cat > "$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
6browser=${BROWSER:-firefox}
7imageviewer=${IMAGEVIEWER:-nsxiv}
8
9[ -z "$1" ] && exit 0
10
11# Optional: copy url to clipboard
12echo "$@" | xsel -ib
13
14case "$@" 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 ;;
27esac
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
6st -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
6st -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
5st -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
19opts="aes-256-cbc -iter 1000" # options for openssl
20timeout=10 # timeout for clip, in ms
21editor=${EDITOR:-vi}
22
23if [ -z "$1" ] || [ -z "$2" ]; then
24 echo "usage: secret command file"
25else
26case "$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 ;;
51esac
52fi
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
25file="$XDG_DATA_HOME/selectedfiles"
26menu="" # default uses dmenu-filepicker default
27editor=${EDITOR:-vi}
28rm="trash rm" # replace with rm -r if you don't use trash
29
30usage() {
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
44while getopts "m:" opt; do
45 case "$opt" in
46 m)
47 menu="$OPTARG"
48 ;;
49 *)
50 usage
51 exit 1
52 ;;
53 esac
54done
55shift $((OPTIND - 1))
56
57add() {
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
71clear() {
72 cat /dev/null > "$file"
73}
74
75cphere() {
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
92open() {
93 while read -r f; do
94 open-file "$f"
95 done < "$file"
96}
97
98remove() {
99 while read -r f; do
100 $rm "$f"
101 done < "$file"
102}
103
104if [ -z "$1" ]; then
105 cat "$file"
106else
107case "$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 ;;
135esac
136fi
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
6case "$(uname)" in
7OpenBSD)
8 status-openbsd
9 ;;
10*)
11 status-linux
12 ;;
13esac
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
11sep=${1:-" | "}
12
13time=$(date +"%H:%M")
14date=$(date +"%a %d %b")
15
16if [ "$(pulsemixer --get-mute)" -eq 1 ]; then
17 volume="Muted"
18else
19 volume="Vol $(pulsemixer --get-volume | awk '{print $1}')%"
20fi
21
22bat="/sys/class/power_supply/BAT0"
23if [ -d $bat ]; then
24 charge_status="$(cat $bat/status | awk '{print substr ($0, 0, 2)}')"
25 battery="Bat $(cat $bat/capacity)% $charge_status"
26else
27 battery="No battery"
28fi
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
38network="$(iwctl station wlan0 show | grep 'Connected network' | awk '{print $3}')"
39if [ "$(cat /sys/class/net/eth0/carrier)" = 1 ]; then
40 if [ -z "$network" ]; then
41 network="eth"
42 else
43 network="eth & $network"
44 fi
45fi
46
47noticount=$(notify show | wc -l)
48
49printf '%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]"
52printf '\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
10sep=${1:-" | "}
11
12time=$(date +"%H:%M")
13date=$(date +"%d %b")
14battery="$(apm | grep -o '[^ ]*%')"
15ifconfig="$(ifconfig athn0)"
16network="$(echo "$ifconfig" | grep status | sed 's/.*status: //')"
17if [ "$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
23fi
24network="$(printf "%.20s" "$nwid")" # Make it shorter
25
26echo "$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
7pager=${PAGER:-less}
8tempfile=$(mktemp)
9
10cat > "$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
5terminal=${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
11trashfolder=$XDG_DATA_HOME/mytrash
12
13usage() {
14 echo "Usage: trash [rm FILES... | ls | empty]"
15}
16
17if [ -z "$1" ]; then
18 usage
19 exit 1
20fi
21
22case "$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 ;;
44esac
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
5reg='[a-z0-9\._\+\-%]+@[a-z0-9\._\+\-%]+\.[a-zA-Z]+'
6
7grep -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
8usage() {
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
15default_editor=vi
16basedir="$HOME/box/speedcubing/bld/algs"
17ebuffer=UR
18cbuffer=UFR
19wbuffer=UFr
20xbuffer=Ubl
21tbuffer=Uf
22
23edge() {
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
48corner() {
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
72wing() {
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
98xcenter() {
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
124tcenter() {
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
150edit() {
151 mkdir -p "$basedir/$1/$2/$3"
152 $editor "$basedir/$1/$2/$3/$4"
153}
154
155showall_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
169showall_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
183showall_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
197showall_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
211showall_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
225export_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
249export_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
273export_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
297export_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
321export_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
345run() {
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
438if [ -n "$1" ]; then
439 run $@
440else
441 while read -r args; do
442 [ -n "$args" ] && run $args
443 done
444fi
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
5folder=$HOME/box/configbackups
6
7dotfiles=".bash_profile .bashrc .profile .inputrc .mblaze .nexrc .tmux.conf .virc .xinitrc .config/isyncrc"
8config="colors fontconfig git imv msmtp zathura"
9src="dmenu dwm st"
10
11for d in config home src ssh; do mkdir -p "$folder/$d"; done
12
13# copy
14
15for i in $dotfiles;
16 do cp -Rf "$HOME"/"$i" "$folder"/home/
17done
18
19for i in $config
20 do cp -Rf "$HOME"/.config/"$i" "$folder"/config/
21done
22
23for i in $src
24 do mkdir "$folder"/src/"$i"
25 cp -f "$HOME"/.local/src/"$i"/*.{c,h} "$folder"/src/"$i"/
26done
27
28cp "$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
9usage() {
10 echo "Usage: dmenu-mail-aliases [-m MENU]"
11}
12
13menu="dmenu -l 20"
14aliasfile="$HOME/.mblaze/aliases"
15
16while getopts "m:" opt; do
17 case "$opt" in
18 m)
19 menu="$OPTARG"
20 ;;
21 *)
22 usage
23 exit 1
24 ;;
25 esac
26done
27shift $((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
6menu=${MENU:-dmenu}
7
8websearch "$(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
7nissy="nissy"
8prompt="Press enter for a new scramble, Ctr+C (or Ctrl+Z) to quit:"
9
10usage() {
11 echo "Usage: practice [eo|dr|htr|fin]"
12 exit 1
13}
14
15practice_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
55practice_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
104practice_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
134practice_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
5srv=tronto.net
6dir=$(tr -cd 'a-z0-9' < /dev/random | fold -w 8 | head -n 1)
7htp=https://share.tronto.net/$dir
8pth=/var/www/htdocs/share.tronto.net/$dir
9url=$srv:$pth
10
11ssh tronto.net mkdir "$pth"
12scp "$@" "$url"/
13for 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
5translator="https://translate.google.com/"
6from=$1
7to=$2
8
9shift 2
10text=$(echo "$@" | sed 's/ /\%20/g')
11open-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
5browser=${BROWSER:-firefox}
6searchengine="https://www.startpage.com/sp/search?query="
7#searchengine="https://duckduckgo.com/?q="
8#searchendinge="https://www.google.com/search?q="
9
10arg=$(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
16browser=${BROWSER:-firefox}
17menu=${MENU:-dmenu}
18menuopts="-l 10"
19
20text=$(xsel | sed 's/\n/ /g')
21if [ "${#text}" -ge 11 ]; then
22 shorttext=$(echo "$text" | cut -b 1-10)...
23else
24 shorttext="$text"
25fi
26
27choice() {
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
40trymail() {
41 addr=$(echo "$1" | addressgrep)
42 ( [ -n "$addr" ] && mail-compose "$addr" ) || return 1
43}
44
45tryman() {
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
56tryurl() {
57 url=$(echo "$1" | urlgrep)
58 ( [ -n "$url" ] && "$browser" "$url" ) || return 1
59}
60
61#open-file -s spawn "$text" || \
62tryurl "$text" || \
63trymail "$text" || \
64tryman "$text" || \
65choice
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
5protocols='http|https|ftp|sftp|gemini|mailto'
6valid_chars="][a-zA-Z0-9_~/?#@!$&'()*+=.,;:-"
7regex="(($protocols):|www\.)[$valid_chars]+"
8
9egrep -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
6file=$(mktemp)
7file2=$(mktemp)
8editor=${EDITOR:-vi}
9
10ls | tee "$file" > "$file2"
11$editor "$file2"
12
13if [ "$(wc -l "$file" | awk '{print $1}')" != \
14 "$(wc -l "$file2" | awk '{print $1}')" ]; then
15 echo "Error reading new file names"
16else
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
25fi
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
6editor=${EDITOR:-${VISUAL:-vi}}
7xed=${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
6f=$(mktemp)
7cat > "$f"
8xedit "$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
8xsetroot -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
7notify="notify push"
8
9folder=~/pictures/wallpapers
10pic=$(ls $folder | sort -R | head -1)
11
12# Alternative: use feh
13#feh --bg-fill --no-fehbg "$folder"/"$pic"
14xwallpaper --zoom "$folder"/"$pic"
15
16# Uncomment to notify
17#$notify "Background of the day" "$pic"

Generated with cgit - Back to sebastiano.tronto.net