# 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 }