#!/bin/bash displays=( $(xrandr | sed -rn 's#^([^ ]+) connected.*#\1#p' | grep -v '^eDP-1$') $(xrandr | sed -rn 's#^([^ ]+) disconnected primary [0-9].*#\1#p' | grep -v '^eDP-1$') $(xrandr | sed -rn 's#^([^ ]+) disconnected [0-9].*#\1#p' | grep -v '^eDP-1$') ) for display in "${displays[@]}"; do xrandr --output "$display" --off done xrandr --output eDP1 --primary xrandr --output eDP-1 --primary