Skip to content

Instantly share code, notes, and snippets.

@jan-matejka
Last active May 27, 2017 20:19
Show Gist options
  • Select an option

  • Save jan-matejka/2689745c450e1adec69ea576150c841d to your computer and use it in GitHub Desktop.

Select an option

Save jan-matejka/2689745c450e1adec69ea576150c841d to your computer and use it in GitHub Desktop.

remy-dock

Udev rule to handle docking/undocking on workstation remy.

Installation

Install/uninstall with make.

Debugging

Events can be monitored with udevadm monitor -e.

The script can be tested with env -i UDEV_VARS=foobar zsh dock.

The script can be debugged through udevd logging (journalctl -xfeu systemd-udevd) enabled through udevadm control --log-priority debug but the script must write to stderr, stdout doesn't seem to be logged by udevd.

#!/usr/bin/zsh
setopt no_unset
setopt pipe_fail
setopt warn_create_global
SELF=${0##*/}
ROOT=$(realpath $(dirname $0))
function handle_event {
case "$EVENT" in
"dock")
su yac -c "${ROOT}/${SELF} xrandr-dock"
;;
"undock")
su yac -c "${ROOT}/${SELF} xrandr-undock"
;;
*)
printf "Invalid EVENT %s" -- "$EVENT" >&2
exit 1
esac
}
function cmd_xrandr-dock {
export DISPLAY=:0
local i=0
while ! xrandr | grep -q "DP-2 connected"; do
i=$(( i + 1 ))
sleep 1
[[ $i -gt 4 ]] && exit 1
done
xrandr --output DP-2 --auto
xrandr --output DP-2 --right-of eDP-1 --primary
xrandr --output eDP-1 --noprimary
}
function cmd_xrandr-undock {
export DISPLAY=:0
xrandr --output DP-2 --off
}
if [[ $# == 0 ]]; then
handle_event
else
cmd="cmd_$1"
$cmd
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment