| 1 | #! /bin/sh -ex |
| 2 | |
| 3 | dir=west bogus=nil |
| 4 | usage () { echo "usage: $0 [-ensw] HOST:RDPY/LDPY"; } |
| 5 | while getopts "hensw" opt; do |
| 6 | case $opt in |
| 7 | h) usage; exit ;; |
| 8 | e) dir=east ;; |
| 9 | n) dir=north ;; |
| 10 | s) dir=south ;; |
| 11 | w) dir=west ;; |
| 12 | *) bogus=t ;; |
| 13 | esac |
| 14 | done |
| 15 | shift $(( $OPTIND - 1)) |
| 16 | case $bogus,$#,$1 in nil,1,*:*/*) ;; *) usage >&2; exit 2 ;; esac |
| 17 | host=${1%:*} dpy=${1##*:}; rdpy=${dpy%%/*} ldpy=${dpy#*/} |
| 18 | control=ControlPath=~/.ssh/sock-%l/control-%r@%h.x2x |
| 19 | ssh -o$control -L"/tmp/.X11-unix/X$ldpy:/tmp/.X11-unix/X$rdpy" -Nafx "$host" |
| 20 | sleep 1 |
| 21 | trap 'trap - INT QUIT HUP EXIT; ssh -o$control -Oexit "$host"; rm -f "/tmp/.X11-unix/X$ldpy"' INT QUIT HUP EXIT |
| 22 | x2x -$dir -to ":$ldpy" |