aboutsummaryrefslogtreecommitdiff
path: root/misc/bin
diff options
context:
space:
mode:
Diffstat (limited to 'misc/bin')
-rwxr-xr-xmisc/bin/check-ovpn.sh2
-rwxr-xr-xmisc/bin/display_toggle.sh20
-rwxr-xr-xmisc/bin/switch-display.sh35
-rwxr-xr-xmisc/bin/unzipall.sh8
-rwxr-xr-xmisc/bin/zipall.sh9
5 files changed, 65 insertions, 9 deletions
diff --git a/misc/bin/check-ovpn.sh b/misc/bin/check-ovpn.sh
index fe5d576..9669190 100755
--- a/misc/bin/check-ovpn.sh
+++ b/misc/bin/check-ovpn.sh
@@ -3,7 +3,7 @@
# Check that the vpn is up. Check every 5 seconds for 11 times - for
# use as a minutely cron task
for i in $(seq 1 11); do
- if ifconfig tun0 | grep -q "00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00"; then
+ if ifconfig | grep -q "00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00"; then
echo YES > ~/.local/ovpn-up
else
rm -f ~/.local/ovpn-up
diff --git a/misc/bin/display_toggle.sh b/misc/bin/display_toggle.sh
index b2c7e5c..e7dfcf5 100755
--- a/misc/bin/display_toggle.sh
+++ b/misc/bin/display_toggle.sh
@@ -1,11 +1,14 @@
#!/bin/bash
-# Assuming there are two displays. A small one (e.g. laptop) and a big
-# one (e.g. monitor). Identify the displays, and toggle between 3
-# states: small one only -> both with the big one to the left of the
-# small one -> big one only
-# small one: <20 inch
-# big one: >20 inch
+# toggle display arrangements.
+
+# If there is only one monitor, then run xrandr --auto
+
+# Otherwise assume there are two displays. A small one (e.g. laptop)
+# and a big one (e.g. monitor). Identify the displays, and toggle
+# between 3 states: small one only -> both with the big one to the
+# left of the small one -> big one only small one: <20 inch big one:
+# >20 inch
# Make sure the variables from pipe can be assigned
# https://stackoverflow.com/questions/42963395/bash-assign-variable-from-pipe
@@ -21,9 +24,10 @@ xrandr | grep " connected " | while IFS=$'\n' read -r line; do
fi
done
+# Only one monitor: run xrandr --auto
if (( i == 1 )); then
- echo "Only one connected display"
- exit 1
+ xrandr --auto
+ exit 0
fi
regex="^.*/([0-9]+)x.*/([0-9]+).* ([^ ]+)$"
diff --git a/misc/bin/switch-display.sh b/misc/bin/switch-display.sh
new file mode 100755
index 0000000..4c3cba6
--- /dev/null
+++ b/misc/bin/switch-display.sh
@@ -0,0 +1,35 @@
+#!/bin/bash
+
+logger "$1" "$2" "$3"
+# Switch to the biggest display available. for use as an acpid hook
+
+# Make sure the variables from pipe can be assigned
+# https://stackoverflow.com/questions/42963395/bash-assign-variable-from-pipe
+shopt -s lastpipe
+
+# enable all monitors so that they show up in xrandr
+# --listactivemonitors output. somehow this output is identical to
+# that of xrandr --listmonitors
+xrandr --auto
+
+# find the widest monitor
+regex="^.*/([0-9]+)x.*/([0-9]+).* ([^ ]+)$"
+widest=0
+widest_name=""
+xrandr --listactivemonitors | while IFS=$'\n' read -r line; do
+ if [[ $line =~ $regex ]]; then
+ if (( "${BASH_REMATCH[1]}" > "$widest" )); then
+ widest="${BASH_REMATCH[1]}"
+ widest_name="${BASH_REMATCH[3]}"
+ fi
+ fi
+done
+
+# turn off all other monitors
+xrandr --listactivemonitors | while IFS=$'\n' read -r line; do
+ if [[ $line =~ $regex ]]; then
+ if [[ "${BASH_REMATCH[3]}" != "$widest_name" ]]; then
+ xrandr --output "${BASH_REMATCH[3]}" --off
+ fi
+ fi
+done
diff --git a/misc/bin/unzipall.sh b/misc/bin/unzipall.sh
new file mode 100755
index 0000000..2d654f0
--- /dev/null
+++ b/misc/bin/unzipall.sh
@@ -0,0 +1,8 @@
+#/bin/bash
+
+# unzip all zip/7z files with 7z in pwd
+for f in ./*; do
+ ext=${f##*.}
+ if test "$ext" = zip; then 7z e "$f"; fi;
+ if test "$ext" = 7z; then 7z e "$f"; fi;
+done
diff --git a/misc/bin/zipall.sh b/misc/bin/zipall.sh
new file mode 100755
index 0000000..0a244c2
--- /dev/null
+++ b/misc/bin/zipall.sh
@@ -0,0 +1,9 @@
+#/bin/bash
+
+# zip all non-7z and non-zip files with 7z in pwd and delete the original
+for f in ./*; do
+ ext=${f##*.}
+ if test "$ext" = zip; then continue; fi;
+ if test "$ext" = 7z; then continue; fi;
+ 7z a -sdel "$f.7z" "$f"
+done