aboutsummaryrefslogtreecommitdiff
path: root/misc/bin
diff options
context:
space:
mode:
authorYuchen Pei <id@ypei.org>2023-06-20 00:22:29 +1000
committerYuchen Pei <id@ypei.org>2023-06-20 00:23:00 +1000
commit351ce98112731d18d73876acf1050bd8e4f487ee (patch)
treed8ee277e6f9f9a9fa3eb8c56d91934d5b7fc1bef /misc/bin
parent06914aff2b0011d41bc50447965a8d7c6ef52c9b (diff)
Adding a buncha misc files
Also .gitignore
Diffstat (limited to 'misc/bin')
-rwxr-xr-xmisc/bin/display_toggle.sh61
-rwxr-xr-xmisc/bin/screengrab-window.sh7
-rwxr-xr-xmisc/bin/screengrab.sh7
-rwxr-xr-xmisc/bin/toggle-dvorak.sh8
-rwxr-xr-xmisc/bin/touchpad_toggle.sh13
5 files changed, 96 insertions, 0 deletions
diff --git a/misc/bin/display_toggle.sh b/misc/bin/display_toggle.sh
new file mode 100755
index 0000000..b2c7e5c
--- /dev/null
+++ b/misc/bin/display_toggle.sh
@@ -0,0 +1,61 @@
+#!/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
+
+# Make sure the variables from pipe can be assigned
+# https://stackoverflow.com/questions/42963395/bash-assign-variable-from-pipe
+shopt -s lastpipe
+i=0
+regex="^([^ ]+).* .*$"
+
+# Read the output of xrandr for connected display names and sizes
+xrandr | grep " connected " | while IFS=$'\n' read -r line; do
+ if [[ $line =~ $regex ]]; then
+ name["$i"]="${BASH_REMATCH[1]}"
+ (( i++ ))
+ fi
+done
+
+if (( i == 1 )); then
+ echo "Only one connected display"
+ exit 1
+fi
+
+regex="^.*/([0-9]+)x.*/([0-9]+).* ([^ ]+)$"
+xrandr --listactivemonitors | while IFS=$'\n' read -r line; do
+ if [[ $line =~ $regex ]]; then
+ if (( "${BASH_REMATCH[1]}" > 500 )); then
+ bigger="${BASH_REMATCH[3]}"
+ if [[ $bigger == "${name[0]}" ]]; then
+ smaller=${name[1]}
+ else
+ smaller=${name[0]}
+ fi
+ else
+ smaller="${BASH_REMATCH[3]}"
+ if [[ $smaller == "${name[0]}" ]]; then
+ bigger=${name[1]}
+ else
+ bigger=${name[0]}
+ fi
+ fi
+ fi
+done
+
+# If only smaller on, then have both on
+if ! xrandr --listactivemonitors | grep -q "$bigger"; then
+ xrandr --output "$bigger" --primary --auto --output "$smaller" --right-of "$bigger" --auto
+ # if only bigger on, then only smaller on
+elif ! xrandr --listactivemonitors | grep -q "$smaller"; then
+ xrandr --output "$bigger" --auto --left-of "$smaller" --output "$smaller" --primary --auto
+ xrandr --output "$bigger" --off
+ # if both are on, then only bigger on
+else
+ xrandr --output "$bigger" --primary --auto --left-of "$smaller" --output "$smaller" --auto
+ xrandr --output "$smaller" --off
+fi
diff --git a/misc/bin/screengrab-window.sh b/misc/bin/screengrab-window.sh
new file mode 100755
index 0000000..bfbf73e
--- /dev/null
+++ b/misc/bin/screengrab-window.sh
@@ -0,0 +1,7 @@
+#!/bin/bash
+
+filename1="$MY_SCREENSHOTS_DIR/$(date +%Y-%m-%d--%H-%M-%S)_"
+filename2="$(xdotool getactivewindow getwindowname | sed -r 's/[^a-zA-Z0-9\-]+/_/g')" #get the title of the window, and replace non alphanumerics with '_'
+filename3='.png'
+scrot "${filename1}${filename2}${filename3}" -u
+xclip -r -selection clipboard <<<"$HOME${filename1}${filename2}${filename3}"
diff --git a/misc/bin/screengrab.sh b/misc/bin/screengrab.sh
new file mode 100755
index 0000000..f1f8704
--- /dev/null
+++ b/misc/bin/screengrab.sh
@@ -0,0 +1,7 @@
+#!/bin/bash
+
+filename1="$MY_SCREENSHOTS_DIR/$(date +%Y-%m-%d--%H-%M-%S)_"
+filename2="$(xdotool getactivewindow getwindowname | sed -r 's/[^a-zA-Z0-9\-]+/_/g')" #get the title of the window, and replace non alphanumerics with '_'
+filename3='.png'
+scrot "${filename1}${filename2}${filename3}" -s
+xclip -r -selection clipboard <<<"$HOME${filename1}${filename2}${filename3}"
diff --git a/misc/bin/toggle-dvorak.sh b/misc/bin/toggle-dvorak.sh
new file mode 100755
index 0000000..2dc75df
--- /dev/null
+++ b/misc/bin/toggle-dvorak.sh
@@ -0,0 +1,8 @@
+#!/bin/bash
+
+qwerty=$(setxkbmap -print -verbose 10 | grep "layout:.*us")
+if [ -n "$qwerty" ]; then
+ setxkbmap dvorak
+else
+ setxkbmap us
+fi
diff --git a/misc/bin/touchpad_toggle.sh b/misc/bin/touchpad_toggle.sh
new file mode 100755
index 0000000..93bf5e2
--- /dev/null
+++ b/misc/bin/touchpad_toggle.sh
@@ -0,0 +1,13 @@
+#!/bin/bash
+# Toggle the touchpad, if there is one
+
+# Guess the touchpad name
+touch_name=$(xinput list --name-only | grep -i touchpad)
+
+if [ -n "$touch_name" ]; then
+ if xinput list-props "$touch_name" | grep 'Device Enabled .*:.*1'; then
+ xinput set-prop "$touch_name" "Device Enabled" 0
+ else
+ xinput set-prop "$touch_name" "Device Enabled" 1
+ fi
+fi