#!/usr/bin/env bash export MOSH_TITLE_NOPREFIX=true # check if username was supplied if [ "$1" = "${1/@/}" ]; then input="$USER@$1" else input="$1" fi openurxvt () { cmd="$@" urxvt ++iso14755 ++iso14755_52 -title "$tmuxtitle" -e /bin/sh -c "$cmd" & } if [ "$input" = "swhitton@local" ]; then tmuxtitle="$USER@$(hostname -s)" launchcmd="tmux attach" else if [ "$input" = "spw@ma" ]; then tmuxtitle="$input" launchcmd="ssh -t $input /usr/pkg/bin/tmux attach" else tmuxtitle="$input" launchcmd="ssh -t $input tmux attach" fi fi currwin=$(xprop -id $(xprop -root _NET_ACTIVE_WINDOW | cut -d ' ' -f 5) WM_NAME | cut -d '"' -f 2) # if we're already looking at tmux, maximise it if [ "$currwin" = "$tmuxtitle" ]; then sleep 0.2 wmctrl -r :ACTIVE: -b add,maximized_vert,maximized_horz else # We're not looking at tmux. Try to raise it. If that fails, launch it.b if ! wmctrl -a "$tmuxtitle"; then openurxvt $launchcmd fi fi