Skip to content

Instantly share code, notes, and snippets.

@afresh1
Last active December 14, 2015 13:48
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 afresh1/5095884 to your computer and use it in GitHub Desktop.
Save afresh1/5095884 to your computer and use it in GitHub Desktop.
uses xrandr to setup my displays the way I want them on my x220 running OpenBSD. Including a statusbar using dzen2
#!/bin/sh
_screen=1
xrandr | sed -ne 's/(.*$//' -e 's/.* connected *//p'|
while read _line; do
_size=${_line#* }
echo SCREEN_${_screen}_HEIGHT=`echo $_size | sed -e 's/.*x//' -e 's/\+.*//'`
echo SCREEN_${_screen}_WIDTH=`echo $_size | sed -e 's/x.*//'`
echo SCREEN_${_screen}_X=`echo $_size | sed -e 's/[^+]*+\([0-9]*\).*/\1/'`
echo SCREEN_${_screen}_Y=`echo $_size | sed -e 's/.*+.*+//'`
echo SCREEN_COUNT=$_screen
[ "$_line" == "${_line#*primary }" ] && echo SCREEN_PRIMARY=$_screen
_screen=$(($_screen + 1))
done
#!/bin/sh
XRANDR=""
for o in `xrandr | sed -ne 's/ disconnected.*//p'`; do
XRANDR="$XRANDR --output $o --off"
done
[ -n "$XRANDR" ] && xrandr $XRANDR
set -- `xrandr | sort | sed -ne 's/ connected.*//p'`
D1=$1
D2=$2
D3=$3
#echo "$D1 - $D2 - $D3"
XRANDR=""
for o in $D1 $D2 $D3; do
if [ X"$o" != X"" ]; then
XRANDR="$XRANDR --output $o --pos 0x0 --auto"
fi
done
[ -n "$XRANDR" ] && xrandr $XRANDR
XRANDR="--auto"
if [ X"$D1" != X"" ]; then
XRANDR="--output $D1 --primary"
if [ X"$D2" != X"" ]; then
# It's on the docking station
if [ X"$D1" == X"HDMI3" -a X"$D2" == X"LVDS1" ]; then
P=`xrandr | sed -e 's/ primary//' | awk '
/^LVDS/ { L=$3; sub(".*x","",L); sub("\\\+.*","", L) };
/HDMI3/ { H=$3; sub(".*x","",H); sub("\\\+.*","", H) };
END { print "0x" H - L }'`
S=`xrandr | awk '/^LVDS/ { sub("x.*","", $3); print $3 + 1 "x-400" }'`
XRANDR="--output $D2 --pos $P $XRANDR --pos $S"
else
XRANDR="$XRANDR --output $D2 --right-of $D1"
fi
fi
if [ X"$D3" != X"" ]; then
XRANDR="$XRANDR --output $D3 --left-of $D1"
fi
fi
echo xrandr $XRANDR
xrandr $XRANDR
~/bin/set_bg #~/.backgrounds/Grazing-Galaxies.jpg
statusbar &
#!/bin/sh
if [ ! -x /usr/local/bin/dzen2 ]; then
echo dzen2 not installed exit
fi
eval `screen_sizes`
local dzen_height=15
local clock_width=153
down=$(( $SCREEN_1_HEIGHT + $SCREEN_1_Y - $dzen_height ))
width=$(( $SCREEN_1_WIDTH - $clock_width))
right=$(( $SCREEN_1_WIDTH + $SCREEN_1_X - $width ))
touch ~/.wootoff
pkill xclock
pkill dzen
xclock -digital -bg black -fg green -padding 2 -update 1 \
-strftime '%a %Y.%m.%d %H:%M:%S' -geometry $clock_width+0+${down} &
while true; do
/usr/bin/pgrep xlock > /dev/null && sleep 1 && continue
[ -e ~/.wootoff ] && echo -n "`woot_watch` | "
#echo -n "`currently_playing` | "
vmstat -c 2 | tail -1 | awk '{ printf "%3dM free %d%% idle ", $5 / 1024, $19 }'
echo -n "`sysctl -n hw.cpuspeed` MHz "
power='^fg(#FFFF00)BAT'
batt_color='^fg(#00FF00)'
symbol='-'
adapter_status=`sysctl -n hw.sensors.acpiac0.indicator0`
if [ ${adapter_status%% *} == On ]; then
power='^fg(#00FF00)AC'
batt_color='^fg()'
else
power="$power $batt_color$( apm | awk '/Battery state/ { print $6 " mins" }' )"
fi
batt_pct=`apm | sed -ne 's/%.*//;/Battery state/s/.*,//p'`
if [ $batt_pct -lt 33 ]; then
batt_color='^fg(#FFFF00)^bg(#FF0000)'
elif [ $batt_pct -lt 66 ]; then
batt_color='^fg(#FFFF00)'
fi
batt_status=`sysctl -n hw.sensors.acpibat0.raw0`
if [ ${batt_status%% *} = 0 ]; then
symbol='='
elif [ ${batt_status%% *} = 2 ]; then
symbol='+'
fi
echo $batt_pct | dbar -nonl -l "$power$batt_color" -s "$symbol"
echo '^fg()'
sleep 5
done | dzen2 -y $down -x $right -w $width
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment