-
-
Save cybniv/06feaf76e4ec3f779053422348a109ea to your computer and use it in GitHub Desktop.
dock to docking station
This file contains 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
#!/usr/bin/env ruby | |
@enabled_outputs = ["eDP1", "DP1-1", "DP1-2", "DP1-3", "HDMI1", "HDMI2", "HDMI3", "VGA1"] | |
@max_enabled_outputs = 2 | |
@position = '--right-of' | |
# A connected output looks like this 'HDMI1 connected[...]' | |
def get_connected_outputs(xrandr_output) | |
outputs = [] | |
xrandr_output.each_line do |line| | |
outputs.push line.split(' ')[0] if line.match(' connected') | |
end | |
return outputs | |
end | |
# An enabled output looks like this 'HDMI1 (dis)connected 1920x1080+0+0[...]' | |
def get_enabled_outputs(xrandr_output) | |
outputs = [] | |
xrandr_output.each_line do |line| | |
outputs.push line.split(' ')[0] if line.match(/connected (primary )?[0-9]/) | |
end | |
sorted_outputs = [] | |
for i in 0..(@enabled_outputs.size - 1) | |
sorted_outputs.push(@enabled_outputs[i]) if outputs.include?(@enabled_outputs[i]) | |
end | |
return sorted_outputs | |
end | |
def disable_output(name) | |
`xrandr --output #{name} --off` | |
end | |
def enable_output(name) | |
`xrandr --output #{name} --auto` | |
end | |
xrandr = `xrandr` | |
connected_outputs = get_connected_outputs(xrandr) | |
enabled_outputs = get_enabled_outputs(xrandr) | |
outputs_to_disable = Array.new(enabled_outputs) | |
outputs_to_enable = [] | |
@enabled_outputs.each do |output| | |
if outputs_to_enable.size < @max_enabled_outputs and connected_outputs.include?(output) | |
outputs_to_enable.push output | |
outputs_to_disable.delete output | |
end | |
end | |
outputs_to_disable.map { |output| disable_output(output) } | |
outputs_to_enable -= enabled_outputs | |
outputs_to_enable.map { |output| enable_output(output) } | |
for i in 1..(enabled_outputs.size - 1) | |
`xrandr --output #{enabled_outputs[i]} #{@position} #{enabled_outputs[i-1]}` | |
end | |
# set wallpaper | |
`sh ~/.fehbg` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment