From 781052e50827d5d4035e3c17041d5b961abf8efb Mon Sep 17 00:00:00 2001 From: Thomas Forgione Date: Mon, 13 Nov 2023 14:47:09 +0100 Subject: [PATCH] Adds basic xrandr --- nushell/config.nu | 1 + nushell/config/xrandr.nu | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 nushell/config/xrandr.nu diff --git a/nushell/config.nu b/nushell/config.nu index 5dbf84d..bf5ae41 100644 --- a/nushell/config.nu +++ b/nushell/config.nu @@ -6,6 +6,7 @@ source ~/.config/nushell/config/update.nu source ~/.config/nushell/config/gclone.nu source ~/.config/nushell/config/pass.nu source ~/.config/nushell/config/docker.nu +source ~/.config/nushell/config/xrandr.nu # Start tfetch tfetch diff --git a/nushell/config/xrandr.nu b/nushell/config/xrandr.nu new file mode 100644 index 0000000..6bd3da9 --- /dev/null +++ b/nushell/config/xrandr.nu @@ -0,0 +1,40 @@ +# nushell-ify xrandr +def xrandr [] { + mut output = [] + mut current_screen: record> = { + 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 +}