mirror of https://gitlab.com/dabruh/dotfiles.git
Add attribute for enabled/disabled monitors
This commit is contained in:
parent
b433ef57d3
commit
7128f6c74e
|
@ -4,21 +4,40 @@
|
||||||
|
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
_monitors="" # Cache for the xrandr output
|
_monitors=() # Cache for the xrandr output
|
||||||
|
|
||||||
# Get the list of connected and disconnected monitors.
|
# Get the list of connected and disconnected monitors.
|
||||||
# Includes information about the primary monitor
|
# Includes information about the primary monitor
|
||||||
# E.g:
|
# E.g:
|
||||||
# eDP-1,connected,primary
|
# eDP-1,connected,primary,1920x1080+0+0,enabled
|
||||||
# HDMI-1,disconnected
|
# HDMI-1,disconnected,1920x1080+1920+0,enabled
|
||||||
# DP-1,disconnected
|
# DP-1,disconnected,disabled
|
||||||
_get_monitors() {
|
_get_monitors() {
|
||||||
if [ -z "$_monitors" ]; then
|
local monitors enabled_regex="[[:digit:]]+x[[:digit:]]+\+[[:digit:]]+\+[[:digit:]]+" # Regex for enabled monitors
|
||||||
# Cache the xrandr output
|
|
||||||
_monitors=$(xrandr | grep -Eo '^.* ((dis|)connected)( primary|) ' | sed 's/ /,/g' | sed 's/,$//g')
|
# Use caching to avoid multiple calls to xrandr
|
||||||
|
if [ ${#_monitors[@]} -eq 0 ]; then
|
||||||
|
# Get the list of connected and disconnected monitors
|
||||||
|
monitors=$(xrandr | grep -Eo "^.* ((dis|)connected)( primary|) ($enabled_regex|)" | sed 's/ /,/g' | sed 's/,$//g')
|
||||||
|
|
||||||
|
for monitor in $monitors; do
|
||||||
|
# Set "enabled" if it matches the enabled regex and remove the matching string, else set "disabled"
|
||||||
|
if [[ "$monitor" =~ $enabled_regex ]]; then
|
||||||
|
monitor="$monitor,enabled"
|
||||||
|
else
|
||||||
|
monitor="$monitor,disabled"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "$_monitors"
|
# Add to the list of monitors
|
||||||
|
_monitors+=("$monitor")
|
||||||
|
done
|
||||||
|
|
||||||
|
# _monitors="$monitors"
|
||||||
|
fi
|
||||||
|
|
||||||
|
for monitor in "${_monitors[@]}"; do
|
||||||
|
echo "$monitor"
|
||||||
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
# Function that gets all monitors and takes an optional amount of arguments to filter the list.
|
# Function that gets all monitors and takes an optional amount of arguments to filter the list.
|
||||||
|
|
Loading…
Reference in New Issue