mirror of
https://github.com/tomru/switchmon.git
synced 2026-03-03 22:47:31 +01:00
fix that all montiors are added to be turned off
This commit is contained in:
31
swm
31
swm
@@ -21,28 +21,45 @@ usage() {
|
|||||||
|
|
||||||
echoerr() { echo "$@" 1>&2; }
|
echoerr() { echo "$@" 1>&2; }
|
||||||
|
|
||||||
|
getFirstWord() {
|
||||||
|
awk '{print $1}'
|
||||||
|
}
|
||||||
|
|
||||||
|
linesToWords() {
|
||||||
|
awk 'BEGIN{ORS=" "} {print}'
|
||||||
|
}
|
||||||
|
|
||||||
|
wordsToLines() {
|
||||||
|
awk 'BEGIN{RS=" "} {print}'
|
||||||
|
}
|
||||||
|
|
||||||
|
without() {
|
||||||
|
comm -3 <(echo "$1") <(echo "$2")
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if [[ $1 == "-h" ]] || [[ $1 == "--help" ]] ; then
|
if [[ $1 == "-h" ]] || [[ $1 == "--help" ]] ; then
|
||||||
usage
|
usage
|
||||||
exit
|
exit
|
||||||
fi
|
fi
|
||||||
|
|
||||||
TARGET=$1;
|
TARGET=$1;
|
||||||
CONNECTED=$( xrandr | grep " connected" | awk 'BEGIN{ORS=" "} {print $1}');
|
CONNECTED=$( xrandr | grep " connected" | sort | getFirstWord);
|
||||||
DISCONNECTED=$( xrandr | grep "disconnected" | awk 'BEGIN{ORS=" "} {print $1}');
|
DISCONNECTED=$( xrandr | grep "disconnected" | sort | getFirstWord);
|
||||||
|
|
||||||
POSTCMD="herbstclient reload";
|
POSTCMD="herbstclient reload";
|
||||||
|
|
||||||
|
echo connected devices: $(echo $CONNECTED | wordsToLines);
|
||||||
echo connected devices: $CONNECTED;
|
echo disconnected devices: $(echo $DISCONNECTED | wordsToLines);
|
||||||
echo disconnected devices: $DISCONNECTED;
|
|
||||||
|
|
||||||
if [[ -n "$TARGET" ]] && [[ ! "$CONNECTED" =~ "$TARGET" ]] ; then
|
if [[ -n "$TARGET" ]] && [[ ! "$CONNECTED" =~ "$TARGET" ]] ; then
|
||||||
echoerr "error: device $1 is not connected";
|
echoerr "error: device $1 is not connected";
|
||||||
exit 1;
|
exit 1;
|
||||||
fi
|
fi
|
||||||
|
|
||||||
FORON=${1-$CONNECTED};
|
FORON=${@-$CONNECTED};
|
||||||
FOROFF="$DISCONNECTED ${CONNECTED//$TARGET/}";
|
|
||||||
|
FOROFF="$DISCONNECTED $(without "$CONNECTED" "$FORON")";
|
||||||
|
|
||||||
# turn off all disconnected monitors
|
# turn off all disconnected monitors
|
||||||
XRANDR_OFF_OPTIONS="";
|
XRANDR_OFF_OPTIONS="";
|
||||||
|
|||||||
Reference in New Issue
Block a user