From 0cab2a664098941232c2ce350c7ad4197c7f073e Mon Sep 17 00:00:00 2001 From: dabruh <11458706-dabruh@users.noreply.gitlab.com> Date: Fri, 19 Apr 2024 08:45:15 +0200 Subject: [PATCH] Cache xrandr output --- .local/bin/xmonconf | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/.local/bin/xmonconf b/.local/bin/xmonconf index fb820be..3ab704c 100755 --- a/.local/bin/xmonconf +++ b/.local/bin/xmonconf @@ -4,6 +4,8 @@ set -euo pipefail +_monitors="" # Cache for the xrandr output + # Get the number of monitors connected to the system get_monitor_count() { xrandr --listmonitors | head -n1 | cut -d' ' -f2 @@ -16,7 +18,12 @@ get_monitor_count() { # HDMI-1,disconnected # DP-1,disconnected _get_monitors() { - xrandr | grep -Eo '^.* ((dis|)connected)( primary|) ' | sed 's/ /,/g' | sed 's/,$//g' + if [ -z "$_monitors" ]; then + # Cache the xrandr output + _monitors=$(xrandr | grep -Eo '^.* ((dis|)connected)( primary|) ' | sed 's/ /,/g' | sed 's/,$//g') + fi + + echo "$_monitors" } # Function that gets all monitors and takes an optional amount of arguments to filter the list.