#!/bin/sh default_output=LVDS1 usage() { echo "Usage: rotate (left|right|invert) [output] rotate set (normal|right|inverted|left) [output] Examples: rotate left LVDS1 rotate set right HDMI2 Only the first letter of each command is checked (case-insensitive), so they can be abbreviated or even cut to one letter each in lower or upper case. For example, the following commands do the same thing: rotate set left rotate SET LeFt rotate s l rotate salad lasagna" } rot_to_num() { case $1 in # normal right invert left # convert to numbers to allow math to rotate [nN]*) rot0=0;; [rR]*) rot0=1;; [iI]*) rot0=2;; [lL]*) rot0=3;; *) usage; exit 2;; esac } num_to_rot() { case $1 in # maps to rot_to_num output 0) rot1=normal rot2=none;; 1) rot1=right rot2=cw;; 2) rot1=inverted rot2=half;; 3) rot1=left rot2=ccw;; esac } case $1 in [sS]*) # set: rotate set (normal|right|inverted|left) [output] output=${3:-$default_output} rot_to_num $2 ;; *) # rotate (left|right|invert) [output] output=${2:-$default_output} rot_to_num `xrandr --query --verbose | grep $output | awk '{print $5}'` case $1 in [lL]*) rot0=$(($rot0 - 1));; [rR]*) rot0=$(($rot0 + 1));; [iI]*) rot0=$(($rot0 + 2));; *) usage; exit 1;; esac ;; esac # add 4 modulo 4 to prevent negatives and overflows num_to_rot $((($rot0 + 4) % 4)) xrandr --output $output --rotation $rot1 # x220t if command -v xsetwacom >/dev/null 2>&1; then xsetwacom --set stylus Rotate $rot2 xsetwacom --set eraser Rotate $rot2 xsetwacom --set touch Rotate $rot2 fi # reload bg ~/bin/wall