diff options
author | stuebinm | 2023-03-09 02:05:58 +0100 |
---|---|---|
committer | stuebinm | 2023-03-09 12:46:42 +0100 |
commit | fe1109934505013b3356def93c8a3be450dd5a24 (patch) | |
tree | 10eb7cf295c56bfbc60eace23996271a7e69e9e3 | |
parent | ef4e4fb6ab8d7c11885c40c82a6ffdf90fbea174 (diff) |
home/news: script to fetch pdfs from websites
-rw-r--r-- | home/home.nix | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/home/home.nix b/home/home.nix index 23e1abd..74f6bde 100644 --- a/home/home.nix +++ b/home/home.nix @@ -53,6 +53,30 @@ agenda = "CLICOLOR_FORCE=1 almanac month ~/.cache/feedsync/* | less"; xmlpretty = "xmllint --format - | bat -l xml"; }; + functions.fetchpdf.body = '' + set url $argv[1] + if test "$url" = "" + echo "No url given" + return + end + set choice (curl $url | rg -e '<a[^>]*href="([^"]*\.pdf)"[^>]*>([^<]*)</a>' -o | sed 's/<a[^>]*href="\([^"]*\)"[^>]*>\(.*\)<\/a>/"\1" "\2"/g' | fzf) + if test "$status" != 0 + return + end + set docurl (echo $choice | sed 's/"\(.*\)" ".*"/\1/g') + set docname (echo $choice | sed 's/".*" "\(.*\)"/\1/g') + echo Fetching $docname from $docurl + curl "$docurl" > ~/Downloads/news/"$docname".pdf + zathura ~/Downloads/news/"$docname".pdf + if test (read -P "move this file to archive? [y/N] ") = "y" + set filename (read -P "filename? [$docname] ") + if test "$filename" = "" + cp ~/Downloads/news/"$docname".pdf ~/archive/"$docname".pdf + else + cp ~/Downloads/news/"$docname".pdf ~/archive/$filename + end + end + ''; }; programs.kitty = { @@ -147,6 +171,7 @@ macro v set browser "kitty @launch --type tab mpv --ytdl-format='bv[height<=1100]+ba' %u > /dev/null" ; open-in-browser ; set browser "${config.programs.newsboat.browser} %u" macro f set browser "${pkgs.xdg_utils}/bin/xdg-open %u >/dev/null 2>&1 &" ; open-in-browser ; set browser "${config.programs.newsboat.browser} %u" + macro d set browser "kitty @launch --type tab fish -c 'fetchpdf %u'" ; open-in-browser ; set browser "${config.programs.newsboat.browser} %u" bind-key j down bind-key k up |