#/bin/bash set -x if [[ "$1" = "--revert" ]]; then mastertop=`xinput | grep 'Virtual core pointer'| grep pointer | grep master | grep -o -P 'id=\d+' | cut -d '=' -f 2` devices=(`xinput | grep pointer | grep "Arduino" | grep -o -P 'id=\d+' | cut -d '=' -f 2`) left=${devices[0]} echo $left right=${devices[1]} echo $right if xinput | grep leftkeyboard; then masterleft=`xinput | grep leftkeyboard | grep pointer | grep master | grep -o -P 'id=\d+' | cut -d '=' -f 2` echo $masterleft xinput remove-master $masterleft fi if xinput | grep rightkeyboard ; then masterright=`xinput | grep rightkeyboard | grep pointer | grep master | grep -o -P 'id=\d+' | cut -d '=' -f 2` echo $masterright xinput remove-master $masterright fi xinput reattach $left $mastertop xinput reattach $right $mastertop else if ! xinput | grep leftkeyboard; then xinput create-master leftkeyboard fi if ! xinput | grep rightkeyboard ; then xinput create-master rightkeyboard fi devices=(`xinput | grep pointer | grep "Arduino" | grep -o -P 'id=\d+' | cut -d '=' -f 2`) left=${devices[0]} echo $left right=${devices[1]} echo $right masterleft=`xinput | grep leftkeyboard | grep pointer | grep master | grep -o -P 'id=\d+' | cut -d '=' -f 2` echo $masterleft masterright=`xinput | grep rightkeyboard | grep pointer | grep master | grep -o -P 'id=\d+' | cut -d '=' -f 2` echo $masterright xinput reattach $left $masterleft xinput reattach $right $masterright fi