Last Updated: February 25, 2016
· sheerun

Close all terminal tabs except the current one (iTerm2 et al.)

Just append following snippet to your .zshrc (or .bashrc):

:only() {
  PROG='!'"/^$$|ack/&&/$(basename $SHELL)"'$/{print$2}'
  ps -ao pid,ppid,comm= | awk "$PROG" | xargs kill

if [[ "$SHELL" == *zsh ]]; then
  zle -N :only
  bindkey "^Wo" :only
  bindkey "^W^O" :only

Now you can use both :only command and C-w o shourtcut to close all windows except current one.

Disclaimer: shortcut won't work on bash because I didn't find way to bind such sequence of characters (C-w o). You can use some simpler binding (C-o doesn't work for me anyway):

bind '"\C-w": ":only && clear\n"'

btw. it works for panels too