Created
November 17, 2011 14:36
-
-
Save tuxdna/1373278 to your computer and use it in GitHub Desktop.
Script to enable multiple monitors using Xrandr
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Author: siddhesh.in | |
# Here’s a script I’ve written to do this with any external display (monitor, projector, etc.). | |
# Execute it after connecting the display to your box: | |
typeset -a resx | |
typeset -a resy | |
typeset -a screen | |
typeset -i name=1 | |
typeset -i count=0 | |
tmpfile=$(mktemp) | |
cmd="xrandr --fb " | |
xrandr | grep -A 1 " connected " | grep -v "^--$" | awk '{print $1}' > $tmpfile | |
count=0 | |
for line in $(cat $tmpfile); do | |
if [ $name -eq 1 ]; then | |
screen[$count]=$line | |
name=0 | |
else | |
line=$(echo $line|sed 's/[Xx]/ /g') | |
resx[$count]=$(echo $line | awk '{print $1}') | |
resy[$count]=$(echo $line | awk '{print $2}') | |
count=$((count+1)) | |
name=1 | |
fi | |
done | |
total_width=0 | |
prev_scr= | |
max_height=0 | |
for i in $(seq 0 $((count-1))); do | |
if [ $max_height -lt ${resy[$i]} ]; then | |
max_height=${resy[$i]} | |
fi | |
cmd_ext="$cmd_ext --output ${screen[$i]} --mode ${resx[$i]}x${resy[$i]}" | |
if [ -n "$prev_scr" ]; then | |
cmd_ext="$cmd_ext --right-of $prev_scr" | |
fi | |
prev_scr=${screen[$i]} | |
total_width=$((total_width+${resx[$i]})) | |
done | |
cmd="xrandr --fb ${total_width}x${max_height} $cmd_ext" | |
echo "Running command: $cmd" | |
eval $cmd | |
rm -f tmpfile |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nice script. There is a typo. > in line 15 should be >.