From b08325c2cfa6c9920cfdfd26336911dd4c71fe5e Mon Sep 17 00:00:00 2001 From: Thomas Forgione Date: Mon, 27 Nov 2023 21:05:45 +0100 Subject: [PATCH] Better xrandr --- nushell/config/xrandr.nu | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/nushell/config/xrandr.nu b/nushell/config/xrandr.nu index 5a3d8fd..2e94082 100644 --- a/nushell/config/xrandr.nu +++ b/nushell/config/xrandr.nu @@ -1,9 +1,13 @@ # xrandr wrapper for nushell def xrandr [] { mut output = [] - mut current_screen: record> = { + mut current_screen = { name: "" connected: false + on: false + primary: false + resolution: null + position: null resolutions: [] } @@ -21,11 +25,33 @@ def xrandr [] { if $current_screen.name != "" { $output = ($output | append $current_screen) + $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) + } } - $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))