Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to have a shell bound to a key, on my gentoo fluxbox. The idea is having a shell that would show or hide each time I press F11, but keeping the same shell, not creating a new one each time.

For now, I somehow managed to do it.

I've inserted I my .fluxbox/keys :

F11 :ExecCommand /home/me/script/toogle-sticky-shell

where the called script is simply :

pid=$(ps -ef | grep surxv | head -n -1 | head -c 14 | tail -c 5)
if [ $pid ]
    kill $pid
    urxvt -name surxvt -e screen -RD StickyShell &

And adapted my .fluxbox/apps with :

[app] (name=surxvt)
  [Hidden]  {yes}
  [Layer]   {2}
  [Position]    (WINCENTER) {0 0}
  [Deco]    {BORDER}
  [Tab]     {no}
  [FocusNewWindow] {yes}
  [Sticky]  {yes}

So basically, in order to keep my shell alive, I'm using screen. But I feel like it's not a 'clean' solution.

So my question is : Is there a cleaner way to achieve this ?

For example, is it possible to selectively hide/show a window with fluxbox by pressing a key ?

share|improve this question
Do you mean to ask if a window can be minimized with a fluxbox command from shell script (or ~/.fluxbox/keys)? Something more exotic? Do you need the shell to stay alive after fluxbox dies? – Ярослав Рахматуллин Jul 23 '13 at 20:53
@ЯрославРахматуллин if a fluxbox command in .fluxbox/keys can minimize or maximize a particular window, it would be exactly what I'm looking for, and hadn't found so far. I don't care whether the shell dies or not with fluxbox. – Levans Jul 23 '13 at 21:01
up vote 1 down vote accepted
  1. Install wmctrl

      Description:  command line tool to interact with an EWMH/NetWM compatible
                    X Window Manager
  2. Start a "named" terminal

    urxvt -name moo

  3. Write your toggle-minimize script using

    wmctrl -x -r moo.URxvt -b toggle,hidden

  4. and call if from the keys file.

    F11 :ExecCommand /home/me/script/toogle-hidden moo

If you need more tips, I'll be glad to help.

By the way, I don't think your previous approach is bad. Apart from the way you find the pid and some caveats of screen (non-critical), there is nothing wrong with it.


The screen draw-back is not really an issue because you can do scrolling (in copy mode, by pressing ^A + [) and because X can be reached by setting DISPLAY. Some people will have you believe that tmux is the next best thing to enlightenment, but I tend to write them off as I do with the zsh zealots...

The other thing is unsound because you look for the pid at specific string offsets (head -c) and because the grep keyword is bound to give you a wrong pid (several lines) at some point. for example:

$ ps -ef | grep moo
jaroslav 20089     1  0 Jul23 ?       00:00:00 SCREEN -dR moo
jaroslav 26545 26420  0 08:21 pts/10  00:00:01 rxvt-unicode -name moo
jaroslav 27702 26981  0 08:52 pts/12  00:00:00 /usr/bin/perl /usr/bin/cowsay moo
jaroslav 27704 26771  0 08:52 pts/7   00:00:00 grep --colour=auto moo

This would kill the screen and not the terminal emulator. It's "unsafe" to pre-suppose that ps produces a specific amount of lines or that some colums are of a given width (I think you assumed 3 lines with headers and 14 characters for the first two columns).

I'd go with something like this instead:

ps `pidof rxvt-unicode` | grep -m1 -e '-nam[e] moo' | awk '{ print $1 }'


ps ax  | awk '$0 ~ /rxvt-unicode.*-nam[e] moo/ {print $1; exit}'

With both of these, at least I'm fairly certain that the pid belongs to a rxvt terminal that it was started with -name moo as two of its arguments. And absolutely sure that the output will have at most one pid. The -nam[e] is an old trick to avoid matching the ps | grep command in the output.

All this is nitpicking... The rules of thumb are.

  1. don't assume output of a program to be x chars wide or y lines long.
  2. long regular expressions (more strict) are almost always better than short ones.
share|improve this answer
Thanks, I'll try this out. I guess with wmctrl -l I'll be able to handle the situations where I killed the shell by mistake (^D comes so easily..). Just being curious, how may the things you mention be improved in my approach ? – Levans Jul 24 '13 at 5:26

Your Answer


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.