Flush and the FVWM

I’d like to announce my new project, flush. Flush is a shell with a difference, you’ll be able to execute simple commands like mv and rm, but there will be no support for scripting constructs, pipelines, globbing or substitution.

Introduction

I’m sure many of you were thinking what an absurd idea flush would be, don’t worry, I wasn’t being serious. However, you probably put up with these limitations in your window manager every day, think about the different operations you perform in your window manager, and how it compares to working with files in your shell.

You can probably do little more than Move, Resize and Close windows, how different is this to my hypothetical flush? This may work well for some people, but if you’re like me these limitations would be an unacceptable productivity roadblock. Consider file globbing, a simple feature that probably saves you hundreds of keystrokes daily, if you don’t recognise the term, file globbing is simply matching multiple files with a single pattern. You might use globbing like this:

bash$ rm *.txt

This simple glob matches all the files with the extension .txt.

How would this command look in flush, my hypothetical shell that doesnt support globbing? Probably something like this:

flush$ ls
<br>article.txt lists.txt diagram.txt
<br>file.txt email.txt usenet.txt image.gif
<br>flush$ rm article.txt lists.txt diagram.txt file.txt email.txt usenet.txt

You would have to identify all the text files manually, then enter each one as an argument to the rm command.

Compare this to how your window manager works, if you wanted to close all of your open xterms, you would browse every open application looking for xterms, then Close each one in turn. This probably sounds like a lot of work, a monotonous and repetitive task that computers should excel at, so why are users so happy to accept it?

The F(?) Virtual Window Manager

click for a larger view Allow me to introduce fvwm, a powerful, mature and highly configurable window manager which has been in active development for over a decade. fvwm is different, some of the features we take for granted on the command line could apply equally well to window management, and you can find many of these in fvwm.

How would I go about closing all xterms in fvwm? I’d use a command like this

All (XTerm) Close

Don’t be put off by the word command, although I could enter that command directly into an FvwmConsole (an fvwm module that allows fvwm commands to be entered directly using readline), if I used the command regularly, I could make a key or mouse binding, a menu entry, a mouse gesture or one of the many other options available.

Here are some more example of how globbing might apply to fvwm; open a new web browser if there isn’t one already:

None (Gecko) Exec firefox

A more complex example, Minimise the last gvim I used if my web browser is maximized:

Any (Gecko, Maximized) Prev (gvim) Iconify on

Functions

Shell functions are an important shell facility, allowing you to construct new comands from sequences of other commands. You probably use shell functions everyday in your ~/.profile to make complex command sequences easily available. Let’s try an example in a standard shell

bash$ function rmoldest() {
<br>&gt; oldest=$1; shift
<br>&gt; for i in $@; do
<br>&gt; if test $i -ot $oldest; then
<br>&gt; oldest=$i
<br>&gt; fi
<br>&gt; done
<br>&gt; rm -f $oldest
<br>&gt;}
<br>bash$ rmoldest *.txt

A simple function to perform a task that would otherwise be very complex, delete the oldest file from a list. Let’s see how this might be done in flush, which doesnt support functions or complex commands.

<br>flush$ ls -l
<br>-rw-r--r-- 1 taviso users 0 Feb 15 15:54 article.txt
<br>-rw-r--r-- 1 taviso users 0 Aug 26 15:06 diagram.txt
<br>-rw-r--r-- 1 taviso users 0 Feb 10 10:28 email.txt
<br>-rw-r--r-- 1 taviso users 0 Nov 13 22:46 file.txt
<br>-rw-r--r-- 1 taviso users 0 Feb 7 11:10 lists.txt
<br>-rw-r--r-- 1 taviso users 0 Nov 4 22:43 usenet.txt
<br>flush$ rm diagram.txt


You will manually have to check each file’s timestamp, and identify the oldest one, then pass that file to rm for deletion. I doubt many of you would put up with this for long in your shell, but think about how you would close the oldest window open, or the firefox window that hadnt been in Focus for longest.

Fvwm allows you to construct functions and access them just as you would any other command, once defined they can be used in keybindings, menus, or even in other functions. This example will Minimise all the xterms on your screen, then start a new one and Maximize it.

AddToFunc NewXterm
<br>+ I All (XTerm, CurrentPage, !Iconic) Iconify on
<br>+ I Exec xterm
<br>+ I Wait XTerm
<br>+ I Next (XTerm) Maximize

Command Substitution

Using command substitution and pipelines to build commands is an integral part of using the shell, you simply take the output of one command and use it to form another. Here’s a simple example of using substitution in a standard shell, the output from one command is used to form the next.

bash$ echo This is $(hostname)
<br>This is insomniac

The same thing would not be possible in flush, you would have to do this manually:

flush$ hostname
<br>insomniac
<br>flush$ echo This is insomniac
<br>This is insomniac

Imagine closing all windows with the same name as the window that has focus in your window manager, how would you accomplish this? Most likely the same way you would in flush, manually identify all the matching windows then close them in turn. Fvwm supports substitution in several forms, expansion is perfect for this operation:

Current All ($[w.name]) Close

Fvwm expands the string $[w.name] to the name of the current window, fvwm supports many types of expansion, such as $[w.name], $[w.iconname], $[w.x], $[w.y], $[w.width], $[w.height], $[pointer.x], $[pointer.y], and dozens more. Another form of substitution that can be very useful is PipeRead, fvwm will read commands from the output of shell commands, this allows you to create complex commands using shell constructs.

Conclusion

Fvwm has so many advanced features that several tomes could be filled on the subject, yet the modular design and high quality codebase make it one of the most efficient window managers available. There is no way for me to describe all the features here, but if you’ve read this far you might be interested to know that fvwm includes a scripting language called FvwmScript for building simple graphical programs that integrate with fvwm, a powerful module for building interfaces or desktop panels called FvwmButtons, and a perl library called perllib that lets developers create fvwm modules in perl.

  • You can read some more about FvwmButtons here and here
  • There’s an introduction to fvwm here
  • The official fvwm site is here
  • The FvwmWiki is here, and the FvwmForum is here

About the author
Tavis Ormandy has been a confirmed fvwm zealot for many years, advocating it to anyone who will listen. He maintains the fvwm package for Gentoo Linux where he also helps with alpha porting and security auditing. He can be found idling on #fvwm on irc.freenode.net. You can find his fvwm2rc here.


If you would like to see your thoughts or experiences with technology published, please consider writing an article for OSNews.

57 Comments

  1. 2005-02-21 11:13 am
  2. 2005-02-21 11:20 am
  3. 2005-02-21 11:22 am
  4. 2005-02-21 11:35 am
  5. 2005-02-21 11:59 am
  6. 2005-02-21 12:07 pm
  7. 2005-02-21 12:49 pm
  8. 2005-02-21 12:51 pm
  9. 2005-02-21 12:53 pm
  10. 2005-02-21 1:17 pm
  11. 2005-02-21 1:22 pm
  12. 2005-02-21 1:34 pm
  13. 2005-02-21 2:00 pm
  14. 2005-02-21 2:04 pm
  15. 2005-02-21 2:42 pm
  16. 2005-02-21 2:47 pm
  17. 2005-02-21 2:47 pm
  18. 2005-02-21 2:50 pm
  19. 2005-02-21 3:10 pm
  20. 2005-02-21 3:16 pm
  21. 2005-02-21 3:32 pm
  22. 2005-02-21 3:47 pm
  23. 2005-02-21 3:53 pm
  24. 2005-02-21 3:54 pm
  25. 2005-02-21 4:01 pm
  26. 2005-02-21 4:07 pm
  27. 2005-02-21 4:21 pm
  28. 2005-02-21 4:33 pm
  29. 2005-02-21 4:46 pm
  30. 2005-02-21 4:50 pm
  31. 2005-02-21 6:06 pm
  32. 2005-02-21 6:11 pm
  33. 2005-02-21 6:18 pm
  34. 2005-02-21 6:56 pm
  35. 2005-02-21 7:02 pm
  36. 2005-02-21 7:09 pm
  37. 2005-02-21 7:22 pm
  38. 2005-02-21 7:42 pm
  39. 2005-02-21 8:17 pm
  40. 2005-02-21 8:19 pm
  41. 2005-02-21 8:20 pm
  42. 2005-02-21 8:27 pm
  43. 2005-02-21 8:31 pm
  44. 2005-02-21 9:33 pm
  45. 2005-02-21 10:08 pm
  46. 2005-02-21 10:21 pm
  47. 2005-02-21 10:35 pm
  48. 2005-02-21 10:51 pm
  49. 2005-02-22 12:58 am
  50. 2005-02-22 8:54 am
  51. 2005-02-22 9:34 am
  • 2005-02-22 10:13 am
  • 2005-02-22 12:05 pm
  • 2005-02-22 12:32 pm
  • 2005-02-22 2:46 pm
  • 2005-02-22 10:21 pm
  • 2005-02-23 3:38 pm