2023-11-24 09:14:42 +00:00
|
|
|
# xrandr wrapper for nushell
|
2023-11-13 13:47:09 +00:00
|
|
|
def xrandr [] {
|
|
|
|
mut output = []
|
|
|
|
mut current_screen: record<name: string, connected: bool, resolutions: list<string>> = {
|
|
|
|
name: ""
|
|
|
|
connected: false
|
|
|
|
resolutions: []
|
|
|
|
}
|
|
|
|
|
|
|
|
let lines = ^xrandr | lines
|
|
|
|
let length = $lines | length
|
|
|
|
|
|
|
|
# We skip the first line
|
|
|
|
for i in 1..<$length {
|
|
|
|
|
|
|
|
let line = $lines | get $i
|
|
|
|
let split = $line | split row -r '\s+'
|
|
|
|
|
|
|
|
# This will be true whether the screen is connected or not
|
|
|
|
if $line =~ "connected" {
|
|
|
|
|
|
|
|
if $current_screen.name != "" {
|
|
|
|
$output = ($output | append $current_screen)
|
|
|
|
}
|
|
|
|
|
|
|
|
$current_screen.name = (echo $split | get 0)
|
|
|
|
$current_screen.connected = ((echo $split | get 1) != "disconnected")
|
|
|
|
$current_screen.resolutions = []
|
|
|
|
|
|
|
|
} else {
|
|
|
|
$current_screen.resolutions = ($current_screen.resolutions | append ($split | get 1))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if $current_screen.name != "" {
|
|
|
|
$output = ($output | append $current_screen)
|
|
|
|
}
|
|
|
|
|
|
|
|
$output
|
|
|
|
}
|