Skip to content

Instantly share code, notes, and snippets.

@sandorkazi
Created December 14, 2021 00:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sandorkazi/2582578fbb5ac62241e57c21e2ed7fac to your computer and use it in GitHub Desktop.
Save sandorkazi/2582578fbb5ac62241e57c21e2ed7fac to your computer and use it in GitHub Desktop.
tools I use for hotkeys on a linux desktop
#!/usr/bin/env bash
# rotate keyboard layout
# SHIFT + ALT: rotate_layout
function rotate_layout() {
/usr/bin/xkblayout-state set "-1"
notify-send "Keyboard layout changed"
}
# rotate audio sink
# CTRL + ALT + A: rotate_sink
function rotate_sink() {
sink="$(
(
pacmd list-sinks \
| sed -n -E "s/ (\*?) ? index: /\1/p"
echo 0
) \
| grep "*" -A 1 \
| tail -1
)"
pacmd set-default-sink "${sink}"
sink_name="$(
pacmd list-sinks \
| grep " \* index:" -A 100 \
| sed -n -E -e "s/^.*device.description = \"//p" \
| sed -e "s/ .*$//" -e "s/\"$//g" \
| head -1
)"
notify-send "AUDIO SINK ${sink}: ${sink_name}"
}
# bluetooth device command
# CTRL + ALT + B: bt connect
# CTRL + ALT + SHIFT + B: bt disconnect
function bt() {
cmd="${1:-connect}"
mac="${2:-70:26:05:39:B7:0F}"
bluetoothctl "${cmd}" "${mac}" &
sleep 1
}
case $1 in
rotate_layout) ;;
rotate_sink) ;;
bt) ;;
*) echo "UNKNOWN: $@" && exit 1;;
esac
$@
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment