Using urxvt with zsh as a program launcher

There’s a number of window manager independant program launchers out there, but if you need to run arbitrary commands or want shell completion you might find yourself falling back to spawning a terminal every time. It’s easy to create a dmenu replacement by adding this to your ~/.zshrc:

case "$ACT_AS" in
    floating-terminal)
        PS1=""

        HISTFILE=~/.histfile_float
        accept-line-custom () {
            BUFFER_ORIG="$BUFFER"
            BUFFER="(setsid $SHELL -c \"$BUFFER\" &); exit"
            zle .accept-line
        };
        zle -N accept-line-custom
        bindkey '^M' accept-line-custom

        zshaddhistory() {
            print -sr -- ${BUFFER_ORIG%%$'\n'}
            fc -p
        }

        return
    ;;
esac

Entering this condition has a number of effects:

It can do much more than what is available with other launchers:

To run this you may call urxvt like so:

env ACT_AS=floating-terminal urxvtc -geometry x1

If you need to tell your window manager to do something special about the placement of the window as well, you may set a name to make it identifiable:

env ACT_AS=floating-terminal urxvtc -name floating_terminal -geometry x1

For awesome v3.5.9 you would use this rule to center the window and bring it to the top:

{
  rule = { instance = "floating_terminal" },
  properties = { floating = true, above = true, ontop = true },
  callback = function (c) awful.placement.centered(c, nil) end
}