$_ BSDHowTo.ch
How To... Why not..? Scripts Patches RSS logo

How to replace cwm menu-ssh by dmenu

Last update: 2019-05-12


If you use cwm(1) as your window manager you probably also use its feature menu-ssh. The maintainer of cwm(1) wants to get rid of this feature because it actually doesn’t belong into a window manager. In this article I show you a simple way to replace menu-ssh by dmenu.

What is all about?

The feature menu-ssh of cwm(1) reads all the host names in your ~/.ssh/known_hosts file and presents you a small prompt asking you to enter the name of the host you want to connect to using ssh(1). If you enter a host name or select one from the list cwm(1) will start the default terminal emulator and let it execute ssh(1) with the chosen host name as parameter. This is a handy feature, but it does not belong into the window manager. The ports collection contains several alternative menu applications. Combined with a shell script they can provide you with a similar feature. In this article I show my personal solution, using a small shell script and dmenu from suckless.org.

Installation and configuration

The application dmenu is in ports, so you can simply install it with this command:

$ doas pkg_add -i dmenu

dmenu reads the entries it should present from stdin and prints the chosen one to stdout. That makes it perfect to wrap it into a small shell script which uses base tools to read the host names from ~/.ssh/known_hosts. My script looks like this:


expr="s/^@[a-z-]* //;s/^\[//;s/[], ].*$//"
host=$(cat $file | sed "$expr" | sort -u | dmenu)
[[ -n "$host" ]] && xterm -T "[ssh] $host" -e ssh $host


The script reads every line and removes everything after the first comma in detects. It also removes the opening and closing square brackets ssh(1) places around a host name if uses a different port for connection.

Replacing the built-in menu-ssh in cwm(1) by this solution is as easy as redefining the key binding for Alt-. in ~/.cwmrc:

bind-key M-period bin/sshmenu.sh

You can now restart cwm(1) by pressing Ctrl-Alt-Shift-R so your new configuration becomes active.

Removing menu-ssh from cwm(1) actually

I’ve written a patch that removes menu-ssh completely from cwm(1):


Apply the patch and recompile cwm(1):

$ cd /usr/xenocara
$ patch < /home/user/cwm_ssh_rem.diff
$ cd app/cwm
$ make
$ doas make install
$ make clean

This requires you to have checked out the xenocara tree and made sure you can use it as a normal user. If you don’t know what this is about you read it here: Building OpenBSD from Source