dotfiles/bin/executable_thinkpad-dock

53 lines
1.7 KiB
Bash

#!/usr/bin/env bash
# Watch for the Keyboard instead of the Thinkpad dock since this keeps us from tripping
# into weird race conditions as the docks usb hub takes a few seconds to settle.
if [[ "${ACTION}" != "" && "${NAME}" != '"ZSA Technology Labs Inc ErgoDox EZ Shine Keyboard"' ]] &&
[[ "${ACTION}" != "" && "${NAME}" != '"ZSA Technology Labs ErgoDox EZ Shine Keyboard"' ]] &&
[[ "${ACTION}" != "" && "${NAME}" != '"ZSA Technology Labs Planck EZ Glow Keyboard"' ]]; then
exit 0
fi;
SWAYSOCK=/run/user/$(id -u)/sway-ipc.sock
DBUS_SESSION_BUS_ADDRESS="unix:path=/run/user/$(id -u)/bus"
export SWAYSOCK
export DBUS_SESSION_BUS_ADDRESS
if [[ "${ACTION}" == "add" ]]; then
ICON=$(readlink -f ~/.nix-profile/share/icons/gnome/48x48/devices/computer.png)
else
ICON=$(readlink -f ~/.nix-profile/share/icons/gnome/48x48/devices/display.png)
fi;
sleep 0.5
# Home and at my main desk
if (swaymsg -t get_inputs | grep "ErgoDox EZ"); then
doas /run/current-system/sw/bin/networkctl down wifi
doas /run/current-system/sw/bin/networkctl reconfigure ethernet
ACTION="On main desk."
if grep closed /proc/acpi/button/lid/LID/state; then
swaymsg output eDP-1 disable
ACTION="${ACTION}\n Laptop lid is closed"
fi
# Home and on the side desk
elif swaymsg -t get_inputs | grep "Planck EZ"; then
ACTION="On side desk."
doas /run/current-system/sw/bin/networkctl down wifi
doas /run/current-system/sw/bin/networkctl reconfigure dorhamm-docking
# Whereever else
else
ACTION="Not docked at all"
swaymsg output eDP-1 enable
doas /run/current-system/sw/bin/networkctl up wifi
fi;
TITLE="${ACTION} ${NAME}"
swaymsg exec -- /home/bascht/.nix-profile/bin/notify-send -t 3000 --icon="${ICON}" "Docking event" "$TITLE"