Last active
March 3, 2019 20:33
-
-
Save matejc/560c251b3e27ad1c221d0f91c85340a5 to your computer and use it in GitHub Desktop.
Revisions
-
matejc revised this gist
Mar 3, 2019 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -36,7 +36,7 @@ fi for output in $outputs do if echo "$entries" | grep -Eq "^${output}$" then mode="$(getMode $output)" if [ "$mode" == "auto" ] || [ -z "$mode" ] -
matejc created this gist
Mar 3, 2019 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,61 @@ #!/usr/bin/env bash set -e state="$(xrandr)"; outputs="$(awk '{if ($2 == "connected") print $1}' <<< "$state")" function getModes() { awk -v output=$1 '{if ($1 == output) {getline; while ($0 ~ /^\ \ /) {print $1; getline;}}}' <<< "$state" } function getMode() { echo "$((echo auto; getModes "$1";) | rofi -dmenu -p "Select mode for $1 output")" } function getPosition() { output="$1" relationTo="$2" echo "$((echo -e "$output same-as $relationTo\n$output left-of $relationTo\n$output right-of $relationTo\n$output above $relationTo\n$output below $relationTo";) | rofi -dmenu -p "Select $output output relation to $relationTo output")" } function permutations() { python -c "import sys, itertools; a=sys.argv[1:]; print('\n'.join('\n'.join(' '.join(str(i) for i in c) for c in itertools.permutations(a, i)) for i in range(1, len(a)+1)))" "$@"; } entries="$(permutations $outputs | rofi -dmenu -p "Select output combination (first one is primary)" | tr ' ' '\n')" flags="" primary="$(head -n 1 <<< "$entries")" if [[ -z "$entries" ]] then echo "No Selection" >&2 exit 1 fi for output in $outputs do if echo "$entries" | grep -Eq "^''${output}$" then mode="$(getMode $output)" if [ "$mode" == "auto" ] || [ -z "$mode" ] then modeFlag="--auto" else modeFlag="--mode $mode" fi if [ "$primary" == "$output" ] then flags="$flags --output $output --primary $modeFlag" else positionFlag="$(getPosition $output $primary | awk '{printf "--"$2" "$3}')" flags="$flags --output $output $modeFlag $positionFlag" fi else flags="$flags --output $output --off" fi done xrandr $flags