# Smart Terminal - not client 

For some time I have been using what is referred to as a plumber
program. This is a program which decides which application to open a
file with based on its URI type and file extension. For example
gopher:// links open in my chosen gopher client, http:// links in my
chosen web browser, image files in my chosen image viewer etc...

Used in combination with a terminal application which supports URI
matching, like URXVT, it has effectively given me the ability to open
links in any terminal application. This also has the added benefit of
making ordinary text files into interactive documents[2].


## Putting it together

1) Download and install the plumber[1] program.

2) For URXVT add the following to your ~.Xresources file:

	URxvt.perl-ext-common: default,matcher
	URxvt.matcher.button: 2
	URxvt.matcher.launcher: p $0
	URxvt.matcher.pattern.1: \\b(\\w+\\:\\/\\/\\S+)\\b
	URxvt.matcher.launcher.1: p $1
	URxvt.keysym.Mod1-Shift-M: perl:matcher:list
    
Line 4 above adds matching of any URI to URXVT. Line 5 passes the
matched URI in $1 to p which is a symlink to the plumb script. 

Button 2 is middle click and can be used to click on links to cause
them to open using the plumber; alternatively you can use alt+shift+m
to display a numeric menu of links that can be selected by pressing
the respective number of the link.


## Update 12/07/2023

I had written a few patches for the plumber in the past but after
this last install I wasn't particularly happy with calls to unknown
programs being hidden away in the opener files. In an attempt to
improve this I wrote a patch to require specifying the more common
programs as environment variables.

.xsession:

    ...

    # plumber programs
    export XTERM='urxvtc'
    export PLUMB_IMAGE='feh -F --auto-rotate'
    export PLUMB_MEDIA='mpv'
    export PLUMB_GOPHER='gopher'
    export PLUMB_TXTGOPHER='gopher'
    export PLUMB_PDF='xpdf'
    export PLUMB_FILEMANAGER='ranger'
    export PLUMB_WEB='lynx'
    export PLUMB_TXTWEB='lynx'

    ...


[1](git://r-36.net/plumber)
[2](gopher://gopher.icu/I/images/interactive.png)