dotfiles

My personal shell configs and stuff
git clone git://git.alex.balgavy.eu/dotfiles.git
Log | Files | Refs | Submodules | README | LICENSE

commit dd47aa2c3b9b5a3ce1c7c10a5622b72f4bfb7bc0
parent a628be6186f75ea9e1ec8476ad4437f807550609
Author: Alex Balgavy <alex@balgavy.eu>
Date:   Fri,  6 Aug 2021 23:10:51 +0200

w3m: fzf URLs on the page

It's a bit wonky but works decently.

Diffstat:
Aw3m/cgi-bin/fzf-urls.cgi | 25+++++++++++++++++++++++++
Mw3m/keymap | 5+++--
2 files changed, 28 insertions(+), 2 deletions(-)

diff --git a/w3m/cgi-bin/fzf-urls.cgi b/w3m/cgi-bin/fzf-urls.cgi @@ -0,0 +1,25 @@ +#!/bin/sh +# This script requires: +# - pup: for HTML parsing +# - jq: for JSON parsing +# - fzf: for selection +# It parses an HTML source at /tmp/source.html, lets you fuzzily select a url, and writes the selected URL to /tmp/w3m_target_url + +checkdeps() { + for com in "$@"; do + command -v "$com" >/dev/null 2>&1 \ + || { printf '%s not found.\n' "$com" >&2 && exit 1; } + done +} + +case "$(file --mime-type /tmp/w3m_source.html -bL)" in + application/x-gzip) mv /tmp/w3m_source.html /tmp/w3m_source.gzip && gunzip -f -c /tmp/w3m_source.gzip > /tmp/w3m_source.html && rm /tmp/w3m_source.gzip;; + application/x-bzip2) mv /tmp/w3m_source.html /tmp/w3m_source.bz2 && bunzip2 -f -c /tmp/w3m_source.bz2 > /tmp/w3m_source.html && rm /tmp/w3m_source.bz2;; +esac + +</tmp/w3m_source.html pup 'a json{}' \ + | jq -r '.[] | [.text, .href] | @tsv' \ + | fzf --prompt "Choose a link > " --layout=reverse \ + | cut -f2 > /tmp/w3m_target_url + +rm /tmp/w3m_source.html diff --git a/w3m/keymap b/w3m/keymap @@ -31,7 +31,7 @@ keymap ";" COMMAND keymap e EXTERN_LINK keymap ] EXTERN keymap M-e COMMAND 'SET_OPTION default_url=1 ; GOTO ; SET_OPTION default_url=0' -keymap M-f COMMAND 'READ_SHELL ~/.config/w3m/cgi-bin/surfraw-searx.cgi ; GOTO /cgi-bin/goto-target-url.cgi' +keymap M-f COMMAND 'READ_SHELL ~/.config/w3m/cgi-bin/surfraw-searx.cgi; GOTO /cgi-bin/goto-target-url.cgi' keymap M-k DEFINE_KEY keymap C-h HELP @@ -41,10 +41,10 @@ keymap M-b BOOKMARK keymap M-a ADD_BOOKMARK keymap M-g SELECT_MENU keymap M-o LIST_MENU +keymap U LIST keymap M-l LINK_MENU # Link info -keymap U LIST keymap C-g PEEK keymap I INFO keymap u PEEK_LINK @@ -66,6 +66,7 @@ keymap SPCr PIPE_SHELL 'go-readability $W3M_URL | w3m -config ~/.config/w3m/conf keymap SPCs EXEC_SHELL 'pocket save $W3M_URL' keymap SPCl EXEC_SHELL 'pocket save $W3M_CURRENT_LINK' keymap SPCv EXEC_SHELL 'linkhandler "$W3M_CURRENT_LINK"' +keymap SPCu COMMAND 'DOWNLOAD /tmp/w3m_source.html; READ_SHELL ~/.config/w3m/cgi-bin/fzf-urls.cgi; GOTO /cgi-bin/goto-target-url.cgi' keymap xs COMMAND 'READ_SHELL ~/.config/w3m/cgi-bin/surfraw.cgi ; GOTO /cgi-bin/goto-target-url.cgi' # ABORT Quit at once