Cache xrandr output

This commit is contained in:
dabruh 2024-04-19 08:45:15 +02:00
parent 1888ec9c96
commit 0cab2a6640
1 changed files with 8 additions and 1 deletions

View File

@ -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.