Last active
April 11, 2021 01:15
-
-
Save GabrielLasso/1c8c0000ad0cb9dee747f305b7f3a271 to your computer and use it in GitHub Desktop.
Script to choose the display using xrandr and dmenu
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/ruby | |
output=(`xrandr | grep " connected" | cut -f1 -d" "`).split(' ') | |
arr = [] | |
for i in 1..(output.length) | |
arr = arr + output.combination(i).to_a | |
end | |
for i in 0...arr.size | |
arr[i]=arr[i].join("+") | |
end | |
arr = arr.join("\n") | |
chosen = `echo "#{arr}" | dmenu`[0..-2] | |
chosen = chosen.split ('+') | |
cmd = "xrandr" | |
last_out = nil | |
for i in 0...output.size | |
if chosen.include? output[i] | |
cmd << " --output #{output[i]} --auto" | |
cmd << " --right-of #{last_out}" unless last_out.nil? | |
last_out = output[i] | |
else | |
cmd << " --output #{output[i]} --off" | |
end | |
end | |
print chosen | |
if chosen.size > 0 | |
`#{cmd}` | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment