Right click to plumb

Pretty much like plan9's acme and plumber: right-click some selected text to send it to the plumbing program of your choosing:

The shell current working directory is set by the shell via OSC 7 (borrowed from vte, see /etc/profile.d/vte.sh if you have it installed).

For zsh :

__vte_urlencode() (
    # This is important to make sure string manipulation is handled
    # byte-by-byte.
    while [ -n "$str" ]; do
        printf "%s" "$safe"
        if [ -n "$str" ]; then
            printf "%%%02X" "'$str"

__vte_osc7 () {
    printf "\033]7;%s%s\a" "${HOSTNAME:-}" "$(__vte_urlencode "${PWD}")"
[ -n "$ZSH_VERSION" ] && precmd_functions+=(__vte_osc7)

The patch itself only adds a cwd global and a button3 entry that will run a shell, change directory to cwd and run the plumber with the primary selection. Maybe I should use pass cwd as an argument too, like plan9 plumber does.

The plumbing program can be defined via config.h:

static char plumber[] = "plumb.sh";



A simpler plumb patch

The plumbing command is run in the working directory of the shell, with as parameter the text selected with the mouse.

Configuration is done in config.h and an example is supplied in config.def.h:

static char *plumb_cmd = "plumb";

I made this version since I had a hard time understanding how the OSC 7 stuff works and I preferred a full C implementation of a plumbing patch.



A simpler, more flexible plumb patch

A further development on the previous patch to allow for specifying the command line

static char *plumb_cmd[] = {"plumb", "-m", NULL, NULL};

My plumb utility takes on the stdin by default, and requires another option to be passed input on the command line, so I made this to allow for that. It can be applied on its own, without the other patches. It replaces the first NULL with the current selection.



Double click to plumb

Adds additional functionality to the simple_plumb patch that allows the user to plumb a selected word via double clicking while a mask key is held down.

This patch should be applied after simple_plumb.