Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Essentially, I'm looking for a way to keep one terminal open running tmux, and open new windows inside of the session rather than spawning new terminals.

On pushing a key sequence, I'd like to open a new terminal if there isn't one open. But if there is one open already, I'd like to switch to its desktop if necessary and focus the window, then send the command.

I found the documentation for the If action for windows and I was hoping there was a similar construct for global actions as well, but I'm not seeing it.

Edit: Solution

I ended up using a simplified version of jw013's script.

The original script was written for a quake terminal effect, but what I wanted was simpler: not to toggle a terminal, but simply to always open a window in a single tmux terminal session. The key component which I was missing was wmctrl, which I hadn't heard of.

Using jw013's script as a base, I simplified to:

# the variable name for the window (used in openbox rc.xml for the rule as well)
wmclass=tmux_terminal

# if we successfully focus the window then open a new tmux window inside
if wmctrl -a $wmclass -x; then
  tmux new-window

# otherwise the window hasn't been opened.  open it and attach to tmux.
else
  urxvt -name $wmclass -e tmux attach &
fi

I then bound this to W-space in openbox, and set up an application for name=tmux_terminal to open maximized on the 1st desktop. Now if the terminal is not opened, W-space will open it and attach to tmux, else, it will simply switch to the existing tmux session window and open a new window inside of it.

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

I don't think openbox can do exactly that, at least not yet, but would a quake-like drop-down style terminal that you can show/hide with a hotkey be an acceptable subsitute? Some like Tilda, Yakuake, Guake, etc. are terminal emulators especially designed to have the quake-like ability. In addition (shameless plug), there's this little script that I wrote for personal use that does something similar for xterm - I have Alt-` mapped to run it and the first thing I always do in that terminal is run screen (similar to tmux).

share|improve this answer
    
I'm pretty stuck on rxvt, but your script looks promising. I'll check it out after work and see if I can make it work for my needs. Thanks! –  numbers1311407 Aug 30 '11 at 13:38
    
I used to use rxvt myself - if I remember correctly rxvt and xterm take the same options so you just have to replace the instance of lxterm in the script with rxvt instead. –  jw013 Aug 30 '11 at 14:20
    
Thanks a lot for your help. I ended up taking your script (and simplifying it greatly to my purposes). Editing question to show the solution. –  numbers1311407 Aug 31 '11 at 4:40
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.