dotfiles

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

fzf-urls.cgi (953B)


      1 #!/bin/sh
      2 # This script requires:
      3 # - pup: for HTML parsing
      4 # - jq: for JSON parsing
      5 # - fzf: for selection
      6 # 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
      7 
      8 checkdeps() {
      9   for com in "$@"; do
     10     command -v "$com" >/dev/null 2>&1 \
     11       || { printf '%s not found.\n' "$com" >&2 && exit 1; }
     12   done
     13 }
     14 
     15 case "$(file --mime-type /tmp/w3m_source.html -bL)" in
     16   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;;
     17   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;;
     18 esac
     19 
     20 </tmp/w3m_source.html pup 'a json{}' \
     21   | jq -r '.[] | [.text, .href] | @tsv' \
     22   | fzf  --prompt "Choose a link > " --layout=reverse \
     23   | cut -f2 > /tmp/w3m_target_url
     24 
     25 rm /tmp/w3m_source.html