Map keys in lynx to run shell-command

command-line, keyboard-shortcuts, lynx, shell

Solution

I actually ended up finding a couple ways to handle this. Some are more ideal than others. It took some digging through the default configuration file.

The following are Two ways via shell command from lynx:

OPTION A: Run an shell command. Add new variable `EXTERNAL:` to the `/etc/lynx.cfg` file, some examples:

.h2 EXTERNAL   
# EXTERNAL:<url>:<command> %s:<norestriction>:<allow_for_activate>[:environment]

# Example 0: use xclip to set clipboard text
EXTERNAL:http:echo %s | xclip -selection clip-board:TRUE

# Example 1: send the url to `open <url>` to open default browser
EXTERNAL:http:open %s:TRUE

# Example 2: download with wget if ftp page
EXTERNAL:ftp:wget %s &:TRUE

# By default ',' and '.' map to running EXTERNAL on the page and link respectively

NOTE: Lynx can only send the URL (cannot send title or any other information from the webpage without parsing a lynx dump itself)

OPTION B: Launch a browser with a custom sh script. Add new variable `PRINTER:` to the `/etc/lynx.cfg` file, an example:

.h2 PRINTER
# PRINTER:<name>:<command>:<option>:<lines/page>[:<environment>]
PRINTER:openurl:/Users/username/bin/openurl.sh %s:TRUE 

Then create a separate sh script `/Users/username/bin/openurl.sh` that is called when PRINTER is triggered.

#!/bin/sh
# /Users/username/bin/openurl.sh
url=$LYNX_PRINT_URL
title=$LYNX_PRINT_TITLE 
# other variables exist like the date etc... look them up :)
# http://osr600doc.sco.com/en/INT_lynxDoc/keystrokes/environments.html

# opens the url in a default browser.
/usr/bin/open $url

There may be other ways like using the lynxified proxies: `lynxexec`, `lynxprog`, and `lynxcgi`, but I was unable to successfully pass variables with these methods in my own tests.

If you know a way to get title and url information from these methods I would be interested in hearing it. EXTERNAL and PRINTER methods are achieved with a single key press. Unlike print screen options which would need several keystrokes.

Problem

Is it possible to add a custom keymap to lynx (in the config file ~/.lynxrc), which sends information (e.g. the current URL, html, title, etc.) to a shell command? An example use case: I am on OSX and the shell has a command `open`, which attempts to open anything given to it in a default fashion. So, if I am in lynx and want to move the current webpage to the default browser I would want to call `open current-url` from the shell. Another: Collating an organized bookmark file by sending URL and title to a shell script (or something else). Using the default keymap `!` opens up the default shell, but it doesn't give me the URL nor does it run a single command and exit back to lynx as I would want for this. Any ideas would be greatly appreciated.

Original source