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.