Skip to content

Instantly share code, notes, and snippets.

@5long
Last active March 9, 2019 07:27
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 5long/3b7a51aa4b8cd3bd94245298a1a26572 to your computer and use it in GitHub Desktop.
Save 5long/3b7a51aa4b8cd3bd94245298a1a26572 to your computer and use it in GitHub Desktop.
Poor man's multihead management

mont

Poor man's multihead management.

Usage

  • mont r put external 1080p monitor to the right of laptop's built-in 4K monitor.
  • mont s use built-in monitor only.
  • mont a automatically choose among the above 2 setups.
#!/bin/bash
DPI=192
IND=eDP-1
EXD="will be overridden later"
dir=$1
shift
xrr() {
xrandr --dpi $DPI "$@"
}
xrrtop() {
xrr \
--output "$IND" --auto --pos 0x2160 --primary \
--output "$EXD" --auto --pos 0x0 --scale 2x2
}
xrrleft() {
xrr \
--output "$IND" --auto --pos 3840x0 --primary \
--output "$EXD" --auto --scale 2x2 --pos 0x0
}
xrrright() {
xrr \
--output "$IND" --auto --pos 0x0 --primary \
--output "$EXD" --auto --scale 2x2 --pos 3840x0
}
xrrsingle() {
active_exd="$(xrandr --listactivemonitors | grep -Ee '\b(HDMI|DP)\b' | awk '{print $4}')"
xrr --output "$IND" --auto --primary \
--output "$active_exd" --off
}
find_external_display() {
EXD="$(xrandr -q | grep -E '\bconnected\b' | grep -v "^$IND" | cut -d ' ' -f1)"
}
find_external_display
case $dir in
a|auto)
if xrandr --listmonitors | grep "$EXD" -q &>/dev/null; then
xrrright
else
xrrsingle
fi
;;
up|u|t|top)
xrrtop
;;
left|l)
xrrleft
;;
right|r)
xrrright
;;
single|s)
xrrsingle
;;
*)
exit 1
;;
esac
(sleep 1; nitrogen --restore &>/dev/null) &
(sleep 2; launch-polybar &>/dev/null) &
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment