=== modified file 'tmux-autoattach' --- tmux-autoattach 2014-10-08 09:51:41 +0000 +++ tmux-autoattach 2014-04-30 20:16:50 +0000 @@ -3,12 +3,12 @@ pidof urxvtd &>/dev/null || urxvtd -q -f -o if [[ -n "$XDG_DATA_HOME" ]]; then - tmux_sesssion_dir=$XDG_DATA_HOME/tmux_session + tmux_sesssion_dir=$XDG_DATA_HOME/tmux_session else - tmux_sesssion_dir=$HOME/.local/share/tmux_session + tmux_sesssion_dir=$HOME/.local/share/tmux_session fi -typeset -A sessions attached +typeset -A sessions if [[ -f $tmux_sesssion_dir/$DISPLAY ]]; then while IFS=: read session workspace; do @@ -16,26 +16,12 @@ done <$tmux_sesssion_dir/$DISPLAY fi -# the "attached" flag of tmux is not reliable so we search window titles for -# session identifiers, which has the advantage of supporting multiple displays -attached=( - $(wmctrl -l | sed -n "/tmux::[^:]*:$USER@$HOST/{ s/.*tmux::\([^:]*\):$USER@$HOST.*/\1 1/; p }") -) - -tmux list-sessions -F "#{session_name}" | \ -while read session; do - if ! (($+attached[$session])); then - if (($+sessions[$session])); then - # not all windowmanagers support moving windows via wmctrl, so we - # switch to desired workspace before spawning the terminal - wmctrl -s $sessions[$session] - urxvtc -name "tmux_$session" -e tmux-workspace-attach $sessions[$session] $session - # wait until the window appears - N=120 - while ! wmctrl -l | grep tmux::${session}:$USER@$HOST; do - N=$(($N - 1)) - if (($N)); then sleep .01; else break; fi - done +tmux list-sessions -F "#{session_attached} #{session_name}" | \ +while read attached session; do + if ! (($attached)); then + if ((${+sessions[${session}]})); then + wmctrl -s ${sessions[${session}]} + urxvtc -name "tmux_$session" -e tmux-workspace-attach ${sessions[${session}]} $session else urxvtc -name "tmux_$session" -e tmux attach -t $session fi