select-window -t:foo

But note that foo will follow the normal rules to match window names, so
if you want it to be only exact match you will need to have a script to
find it from lsw like what you have, although I suggest you use
#{window_id} not #{window_index}.

If you don't care about exact matching you can just do eg

tmux selectw -t:foo 2>/dev/null || tmux neww -nfoo




On Wed, Feb 20, 2013 at 02:59:41PM -0800, Anthony Molinaro wrote:
> Hi,
> 
> I was trying to figure out if there is a way to select a window by its
> name programmatically.  Specifically, I want a shell script that does
> the following
> 
> #!/bin/sh
> 
> window=$1
> 
> if <some command to determine if the named window exists> ; then
>   <some command to connect to window>
> else
>   tmux new-window -n $window
> fi
> 
> It seems like for the first command, I can use tmux list-windows with a
> format which includes window name like this
> 
> window_id=`tmux list-windows -F "#{window_index} #{window_name}" | grep 
> $window |
> cut -f 1`
> if test -n "$window_id" ; then
>   <some command to connect to window>
> else
>   tmux new-window -n $window
> fi
> 
> But I still don't know if there's away to switch to a window by id.  The
> closest command I can find is select-window but that seems to only allow
> selection by last, next and previous.
> 
> I also see find-window which seems like what I would want but it needs
> to be run interactively and I'd like to do this with a script.
> 
> Thanks,
> 
> -Anthony
> 
> -- 
> ------------------------------------------------------------------------
> Anthony Molinaro                           <antho...@alumni.caltech.edu>
> 
> ------------------------------------------------------------------------------
> Everyone hates slow websites. So do we.
> Make your web apps faster with AppDynamics
> Download AppDynamics Lite for free today:
> http://p.sf.net/sfu/appdyn_d2d_feb
> _______________________________________________
> tmux-users mailing list
> tmux-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/tmux-users

------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_feb
_______________________________________________
tmux-users mailing list
tmux-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tmux-users

Reply via email to