dotfiles

configuration files for shell, text editor, graphical environment, etc.
git clone git://src.adamsgaard.dk/dotfiles
Log | Files | Refs | README | LICENSE Back to index

commit a667056b3386f0e329743353375e12db0d9f603e
parent ac8ae73881279d67bd8a48742bd513ab1c2d2e0e
Author: Anders Damsgaard <anders@adamsgaard.dk>
Date:   Fri, 16 Oct 2020 09:51:03 +0200

mon: automatically detect external display device name

Diffstat:
M.local/bin/mon | 22++++++++++++++--------
1 file changed, 14 insertions(+), 8 deletions(-)

diff --git a/.local/bin/mon b/.local/bin/mon @@ -1,8 +1,10 @@ #!/bin/sh -if [ -z "$INT" ]; then INT=eDP-1; fi -if [ -z "$DPI_INT" ]; then DPI_INT=315; fi -if [ -z "$EXT" ]; then EXT=HDMI-1; fi +xrandr_q="$(xrandr -q)" + +find_ext() { + ext="$(printf '%s\n' "$xrandr_q" | grep ' connected' | awk 'END{ print $1 }')" +} xrdb_normal() { xrdb "${HOME}/.Xresources" @@ -22,9 +24,8 @@ res_from_xrandr() { } find_res() { - xrandr_q="$(xrandr -q)" res_int="$(printf '%s' "$xrandr_q" | res_from_xrandr "$INT")" - if printf '%s' "$xrandr_q" | grep -q "${EXT} connected"; then + if [ -n "$EXT" ]; then res_ext="$(printf '%s' "$xrandr_q" | res_from_xrandr "$EXT")" fi @@ -47,8 +48,10 @@ die() { int() { xrdb_hidpi xrandr --dpi "${DPI_INT}" --fb "${res_int}" \ - --output "${INT}" --mode "${res_int}" --scale 1x1 \ - --output "${EXT}" --off + --output "${INT}" --mode "${res_int}" --scale 1x1 + if [ -n "$EXT" ]; then + xrandr --output "${EXT}" --off + fi } ext() { @@ -104,8 +107,11 @@ mirror_native() { --pos "0x0" } +if [ -z "$INT" ]; then INT=eDP-1; fi +if [ -z "$DPI_INT" ]; then DPI_INT=315; fi +if [ -z "$EXT" ]; then EXT="$(find_ext)"; fi find_res -if [ $# -eq 0 ] || [ -z "$res_ext" ]; then +if [ $# -eq 0 ] || [ -z "$res_ext" ] || [ "$EXT" = "$INT" ]; then int else case "$1" in