dotfiles/nushell/config/xrandr.nu

67 lines
2.0 KiB
Plaintext
Raw Normal View History

2023-11-27 15:23:20 +01:00
# xrandr wrapper for nushell
2023-11-13 14:47:09 +01:00
def xrandr [] {
mut output = []
2023-11-27 21:05:45 +01:00
mut current_screen = {
2023-11-13 14:47:09 +01:00
name: ""
connected: false
2023-11-27 21:05:45 +01:00
on: false
primary: false
resolution: null
position: null
2023-11-13 14:47:09 +01:00
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)
2023-11-27 21:05:45 +01:00
$current_screen.resolutions = []
$current_screen.on = false
$current_screen.resolution = null
$current_screen.position = null
}
$current_screen.name = ($split | get 0)
$current_screen.connected = (($split | get 1) != "disconnected")
$current_screen.primary = (($split | get 2) == "primary")
let resolution = if $current_screen.primary {
($split | get 3 | split column -c '+' | get column1 | get 0)
} else {
($split | get 2 | split column -c '+' | get column1 | get 0)
}
if not ($resolution | str starts-with "(") {
$current_screen.on = true
$current_screen.resolution = $resolution
$current_screen.position = if $current_screen.primary {
($split | get 3 | split column -c '+' | each { "+" + $in.column2 + "+" + $in.column3 } | get 0)
} else {
($split | get 2 | split column -c '+' | each { "+" + $in.column2 + "+" + $in.column3 } | get 0)
}
2023-11-13 14:47:09 +01:00
}
} else {
$current_screen.resolutions = ($current_screen.resolutions | append ($split | get 1))
}
}
if $current_screen.name != "" {
$output = ($output | append $current_screen)
}
$output
}