Advertisement
Spirit_of_Stallman

mon act

May 21st, 2013
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.15 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. DISPLAY=":0" && export DISPLAY
  4.  
  5. [ -f "$HOME/res.info" ] && rm -f $HOME/res.info
  6.  
  7. [ "$1" == "--rotate" ] && {
  8.     case "$2" in
  9.         "nn" ) rotate1="normal"; rotate2="normal" ;;
  10.         "nr" ) rotate1="normal"; rotate2="right"  ;;
  11.         "nl" ) rotate1="normal"; rotate2="left"   ;;
  12.         "rn" ) rotate1="right" ; rotate2="normal" ;;
  13.         "ln" ) rotate1="left"  ; rotate2="normal" ;;
  14.         "ll" ) rotate1="left"  ; rotate2="left"   ;;
  15.         "rr" ) rotate1="right" ; rotate2="right"  ;;
  16.         "rl" ) rotate1="right" ; rotate2="left"   ;;
  17.         "lr" ) rotate1="left"  ; rotate2="right"  ;;
  18.         *    ) rotate1="normal"; rotate2="normal" ;;
  19.     esac
  20. }
  21. [ ! "$1" ] && { rotate1="normal"; rotate2="normal"; }
  22. [ "$1" == "-h" ] && {
  23.     echo -e "use: script --rotate (n|r|l)(n|r|l)\nn-normal,l-left,r-right\nexemple: \"script --rotate ll\" for both left scr rotate"
  24.     exit
  25. }
  26.  
  27. mon_data=`xrandr -q | sed -e "/disconnected/d" -e "/Screen/d"`
  28. outputs=`echo "$mon_data" | grep -o -E '.{3,7} connected' | grep -o -E '^.{3,7} '`
  29. output1=`echo "$outputs" | sed '2d'`
  30. output2=`echo "$outputs" | sed '1d'`
  31.  
  32. [[ ! "$output1" || ! "$output2" ]] && { echo "err 2"; exit; }
  33.  
  34. modes1=$(echo "$mon_data" | sed -e "/$output1/,/$output2/d" | grep -o -E "[0-9]{3,4}x[0-9]{3,4}")
  35. modes2=$(echo "$mon_data" | sed -n "/$output2/,\$p" | grep -o -E "[0-9]{3,4}x[0-9]{3,4}")
  36.  
  37.  
  38. [[ ! "$modes1" || ! "$modes2" ]] && { echo "err 2-1"; exit; }
  39.  
  40.  
  41. xrandr --output $output1 --right-of $output2
  42.  
  43. count="0"
  44. exit_status="1"
  45. while [ "$exit_status" != "0" ]; do
  46.     count=$(($count + 1))
  47.     xrandr --output $output1 --mode `echo "$modes1" | sed "$count!d"` --rotate $rotate1 > /dev/null 2>&1
  48.     exit_status="$?"
  49.    
  50.     [ "$count" == "10" ] && { echo "err 3"; exit; }
  51.  
  52. done
  53.  
  54. echo "${output1}> `echo "$modes2" | sed "$count!d"`"
  55.  
  56. count="0"
  57. exit_status="1"
  58. while [ "$exit_status" != "0" ]; do
  59.     count=$(($count + 1))
  60.     xrandr --output $output2 --mode `echo "$modes2" | sed "$count!d"` --rotate $rotate2 > /dev/null 2>&1
  61.     exit_status="$?"
  62.     [ "$count" == "10" ] && { echo "err 4"; exit; }
  63. done
  64.  
  65. echo "${output2}> `echo "$modes2" | sed "$count!d"`"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement