More ratmenu tips

I see I’ve been getting a lot of hits in the past few days for searches related to ratmen, ratmenu, and 9menu. As I’ve written before, these work very similarly. In a nutshell, you use these to create shell scripts to provide menus for ratpoison or other window managers.

What can you do with these menus? Whatever you want. You can use standard application-centric menus to open whatever application. You can customize them so you open specific files in certain applications. You can start or stop processes (mind your permissions; gksu/gksudo are beneficial if you’re going to start/stop/restart daemons like sshd, cupsd, httpd, etc.). These can then be launched via keybindings set up in .ratpoisonrc or whatever configuration file your chosen window manager uses (a few years ago, I used ratmen with oroborus since oroborus lacks a menu; I set keybindings for ratmen in my .oroborusrc).

This example is more ratpoison-specific because some of the commands in this particular menu (~/bin/ pipe out to the ratpoison status message area. I wanted a menu with system commands and to get information quickly even if I’m not sitting in front of an open terminal, so, for instance, I can see what’s happening or running while working in or gimp or a browser. If you’re using ratmen(u)/9menu in other window managers, you could send to xmessage or zenity or whatever you want.


ratmenu -fg "#ffa500" -bg "#444444" -align center -style dreary \
"netstat" "ratpoison -c 'echo $(netstat -a | head -n 18)'" \
"top" "ratpoison -c 'echo $(top -b -n 1 | head -n 24)'" \
"w" "ratpoison -c 'echo $(w)'" \
"free" "ratpoison -c 'echo $(free -mt)'" \
"mount" "ratpoison -c 'echo $(mount)'" \
"ssh?" "ratpoison -c 'echo $(ps aux | grep -i ssh)'" \
"screen -list" "ratpoison -c 'echo $(screen -list)'" \
"screen(s) ps?" "ratpoison -c 'echo $(ps aux | grep -i screen)'" \
"mount sda1" "pmount /dev/sda1" \
"umount sda1" "pumount /dev/sda1" \
"who" "ratpoison -c 'echo $(who)'" \
"last -20" "ratpoison -c 'echo $(last -20)'" \
"temperature" "ratpoison -c 'echo $(cat /proc/acpi/thermal_zone/THM/temperature)'" \
"battery" "ratpoison -c 'echo $(cat /proc/acpi/battery/BAT0/state)'" \
"cpu info" "ratpoison -c 'echo $(cat /proc/cpuinfo)'" \
"uname" "ratpoison -c 'echo $(uname -a)'"

The first line, of course, is the shebang. The next line runs ratmenu (or ratmen or 9menu), and I have this menu set up with a light orange on dark grey background with the “dreary” menu style allowed in ratmenu (the difference between dreary and snazzy is how the menu selection works; in snazzy, the menu choices scroll up or down to a fixed reversed selection, while in dreary the choices are fixed or static and the reversed selection choice scrolls up or down as you navigate it with the up/down arrows). Then come your menu options. As this is a shell script, it can be written in one line or in multiple lines as above. If it’s in multiple lines, separate them with backslashes so the script is read by the shell as one line (no backslash on the last line).

I also use a separate menu for work documents so they can be opened in either emacs or OOo or gimp as needed. My previous ratpoison entry (ratpoison, xnest, jwm, GIMP) noted that I chose to start using GIMP under another window manager using xnest. I sometimes use GIMP to clean up charts and such for work. In order to keep all the work stuff together and to not have to toggle between the xnest window and everything else, I have separate options in my work menu to open things in the X display with my alternate window manager (currently oroborus). In other words, that menu allows me to stay within oroborus (or jwm or twm or whatever) so I can see, for example, how charts look in documents, while ratpoison continues managing everything else. I still have entries that open things in more standard fashion so that it’s all under ratpoison rather contained in another xnest’ed window manager.

Finally, if you’re using Debian and want to override the recommended 9menu when you install ratpoison and use ratmenu instead, use aptitude (as root or via sudo):

aptitude install -R ratpoison ratmenu

For what it’s worth, I have “sudo aptitude install -R” aliased in my .bashrc (alias debinstall=”sudo aptitude install -R”) so I don’t end up installing more than I absolutely have to.

Finally, understanding how to use a powerful text editor like emacs or vim comes in very handy when editing menus like these, especially if you’re setting up to open specific files with identical or similar commands. I’ll usually go through a process of getting a file list from a directory and then recording a macro to insert text down each line to set up the menu. It’s easier and much faster to either pipe a list of files or insert them within the editor (in emacs: C-u M-! ls /path/to/dir — or, my preference, C-u M-! find ~/ -name “*.m3u”to get full paths) and then do the most repetitive things, such as add commands and shell punctuation, via macro.

It took me less than a minute to do a 100+ line ratmenu for my playlists since every command option is the same (“mocp -cap /path/to/file.m3u” \).

The important thing is to set things up so it’s easy to use and uses the least amount of work.

Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: