From 351ce98112731d18d73876acf1050bd8e4f487ee Mon Sep 17 00:00:00 2001 From: Yuchen Pei Date: Tue, 20 Jun 2023 00:22:29 +1000 Subject: Adding a buncha misc files Also .gitignore --- misc/bin/display_toggle.sh | 61 +++++++++++++++++++++++++++++++++++++++++++ misc/bin/screengrab-window.sh | 7 +++++ misc/bin/screengrab.sh | 7 +++++ misc/bin/toggle-dvorak.sh | 8 ++++++ misc/bin/touchpad_toggle.sh | 13 +++++++++ 5 files changed, 96 insertions(+) create mode 100755 misc/bin/display_toggle.sh create mode 100755 misc/bin/screengrab-window.sh create mode 100755 misc/bin/screengrab.sh create mode 100755 misc/bin/toggle-dvorak.sh create mode 100755 misc/bin/touchpad_toggle.sh (limited to 'misc/bin') 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 -- cgit v1.2.3