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