From 3c6855e2f382001577d0cc850f8be636dee25f0d Mon Sep 17 00:00:00 2001 From: stuebinm Date: Mon, 24 Jul 2023 17:14:20 +0200 Subject: htmlq is nice (thanks to the shork for the hint!) --- home/home.nix | 8 +++++--- home/packages.nix | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) (limited to 'home') diff --git a/home/home.nix b/home/home.nix index 0a5072f..49b5713 100644 --- a/home/home.nix +++ b/home/home.nix @@ -101,6 +101,7 @@ agenda = "CLICOLOR_FORCE=1 almanac month ~/.cache/feedsync/* | less"; xmlpretty = "xmllint --format - | bat -l xml"; wormhole = "wormhole-rs"; + noms = "curl https://www.bahn.de/service/zug/db_lounge -s | htmlq --attribute href a | grep Speisen | xargs curl -s | pdftotext - /dev/stdout | less"; }; functions.fetchpdf.body = '' set url $argv[1] @@ -108,12 +109,13 @@ echo "No url given" return end - set choice (curl -L $url | rg -e ']*href="([^"]*\.pdf)"[^>]*>([^<]*)' -o | sed 's/]*href="\([^"]*\)"[^>]*>\(.*\)<\/a>/"\1" "\2"/g' | fzf) + set anchors (curl -L $url | sd '\n' "" | htmlq a | rg .pdf) + set choice (paste (printf '%s\n' $anchors | htmlq -t a | psub) (printf '%s\n' $anchors | htmlq --attribute href a | psub) | fzf) if test "$status" != 0 return end - set docurl (echo $choice | sed 's/"\(.*\)" ".*"/\1/g') - set docname (echo $choice | sed 's/".*" "\(.*\)"/\1/g') + set docurl (echo $choice | cut -f 2) + set docname (echo $choice | cut -f 1) echo Fetching $docname from $docurl curl "$docurl" > ~/Downloads/news/"$docname".pdf zathura ~/Downloads/news/"$docname".pdf diff --git a/home/packages.nix b/home/packages.nix index 998f205..49d7a02 100644 --- a/home/packages.nix +++ b/home/packages.nix @@ -43,7 +43,7 @@ in (agda.withPackages (p: [ p.standard-library p.cubical ])) # html, js & co jq html-tidy nodePackages.stylelint nodePackages.js-beautify zola - libxml2 fq + libxml2 fq htmlq # purescript spago purescript # nodePackages.purescript-language-server nodejs # rust -- cgit v1.2.3