dotfiles/nushell/config/xrandr.nu

41 lines
1.1 KiB
Plaintext
Raw Normal View History

2023-11-13 14:47:09 +01:00
# nushell-ify xrandr
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
}