How to close other windows in tmux?

8

1

I write some functions in .bashrc to make tmux easy to use:

#!/bin/bash
# .bashrc

# vim            tmux
#-----  --------------------
tabc()  { tmux kill-window; }
tabe()  { tmux new-window; }
tabf()  { tmux find-window $@; }
tabn()  { tmux next-window; }
tabo()  { ; }                         # <-- How to `tabonly`?
tabp()  { tmux previous-window; }
qa()    { tmux kill-session; }
sp()    { tmux split-window; }
vsp()   { tmux split-window -h; }
on()    { tmux kill-pane -a; }

typeset -fx tab{c,e,f,n,o,p} {,v}sp qa on

I want to implement the tabonly command, but don't know how.

kev

Posted 2012-05-27T15:24:04.023

Reputation: 9 972

Answers

4

With the window you want to keep as the current window, just call next-window and kill-window repeatedly, until next-window fails:

while tmux next-window 2> /dev/null; do
    tmux kill-window
done

chepner

Posted 2012-05-27T15:24:04.023

Reputation: 5 645

5The next release of tmux (i.e. 1.7) will have kill-window -a to kill all windows except the current window. – Chris Johnsen – 2012-05-28T07:57:15.790

3

For easy copying, tmux >= 1.7:

tabo()  { tmux kill-window -a; }

Thanks Chris Johnsen.

Alexander

Posted 2012-05-27T15:24:04.023

Reputation: 258