Adds basic xrandr

This commit is contained in:
Thomas Forgione 2023-11-13 14:47:09 +01:00
parent 1d983ddf30
commit 781052e508
2 changed files with 41 additions and 0 deletions

View File

@ -6,6 +6,7 @@ source ~/.config/nushell/config/update.nu
source ~/.config/nushell/config/gclone.nu source ~/.config/nushell/config/gclone.nu
source ~/.config/nushell/config/pass.nu source ~/.config/nushell/config/pass.nu
source ~/.config/nushell/config/docker.nu source ~/.config/nushell/config/docker.nu
source ~/.config/nushell/config/xrandr.nu
# Start tfetch # Start tfetch
tfetch tfetch

40
nushell/config/xrandr.nu Normal file
View File

@ -0,0 +1,40 @@
# 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
}