favicon here hometagsblogmicrobio cvtech cvatuin server

Nushell Script for Fuzzy Finding Lobster Posts



Soc Virnyl Estela | 2023-09-11 | reading time: ~3min

#!/usr/bin/nu
alias MENU = fuzzel -d
let sections = [ "active", "recent", "comments" ]
$env.CACHE_PATH = ("~/.cache/lobsters" | path expand)
$env.ACTIVE_RSS = ( $env.CACHE_PATH  | path join "active.xml")
$env.COMMENTS_RSS = ( $env.CACHE_PATH  | path join "comments.xml")
$env.RECENT_RSS = ( $env.CACHE_PATH  | path join "recent.xml")
if ($env.CACHE_PATH | path exists) { } else { mkdir $env.CACHE_PATH }
if (ls $env.CACHE_PATH | is-empty) or (ls $env.CACHE_PATH | get -i size | any { |s| $s == 0KB })  {
  for section in $sections {
    http get "https://lobste.rs/rss"          | save -f $env.ACTIVE_RSS
    http get "https://lobste.rs/newest.rss"   | save -f $env.RECENT_RSS
    http get "https://lobste.rs/comments.rss" | save -f $env.COMMENTS_RSS
  }
} else if (ls $env.CACHE_PATH | get -i modified | all { |i| $i < (date now) } ) { 
    http get "https://lobste.rs/rss"          | save -f $env.ACTIVE_RSS
    http get "https://lobste.rs/newest.rss"   | save -f $env.RECENT_RSS
    http get "https://lobste.rs/comments.rss" | save -f $env.COMMENTS_RSS
} else {}

let section = ($sections | to text | str trim | MENU -p "choose lobsters section>")
let active_list                 = ( open --raw $env.ACTIVE_RSS   | query xml //item | get //item )
let comment_list               = ( open --raw $env.COMMENTS_RSS | query xml //item | get //item ) 
let recent_list                 = ( open --raw $env.RECENT_RSS   | query xml //item | get //item )


if ($section | is-empty) {
   exit 1
}

# line 2 -> link to post
# line 6 -> link to comment
if ($section =~ "active") {
   let TITLES = ($active_list | each {|it| $it | lines | str trim | get 1} | uniq)
   let LINKS = ($active_list | each {|it| $it | lines | str trim | get 2})
   let POSTS = ($active_list | each {|it| $it | lines | str trim | get 6})
   let TITLE = ($TITLES | to text | MENU -p "active section list>")
   if ($TITLE | is-empty) {
      exit 1
   }
   let options = [ "link to comment" "link to title" ]
   let option = ($options | to text | str trim | MENU -p "select option>" )
   if ($option =~ "link to title") {
      for $title in $TITLES --numbered {
         if $TITLE =~ $title.item {
            xdg-open $"($LINKS | get $title.index)"
         }
      }
   } else if ($option =~ "link to comment") {
     for $title in $TITLES --numbered {
         if $TITLE =~ $title.item {
            xdg-open $"($POSTS | get $title.index)"
         }
     }
   }
} else if ($section =~ "comments") {
   # line to title -> 1
   # line to link comments -> 2
   let TITLES = ($comment_list | each {|it| $it | lines | str trim | get 1} | uniq)
   let TITLE = ($TITLES | to text | MENU -p "active section list>")
   if ($TITLE | is-empty) {
      exit 1
   }
   let link = ($comment_list | each {|item| $item | lines | str trim  | to text } | where ($it =~ $"($TITLE)") | each {|link| $link | lines | get 2 } | to text | MENU -p "link
   to comments>")
   xdg-open $"($link)"
} else if ($section =~ "recent") {
   let TITLES = ($recent_list | each {|it| $it | lines | str trim | get 1} | uniq)
   let LINKS = ($recent_list | each {|it| $it | lines | str trim | get 2})
   let POSTS = ($recent_list | each {|it| $it | lines | str trim | get 6})
   let TITLE = ($TITLES | to text | MENU -p "active section list>")
   if ($TITLE | is-empty) {
      exit 1
   }
   let options = [ "link to comment" "link to title" ]
   let option = ($options | to text | str trim | MENU -p "select option>" )
   if ($option =~ "link to title") {
      for $title in $TITLES --numbered {
         if $TITLE =~ $title.item {
            xdg-open $"($LINKS | get $title.index)"
         }
      }
   } else if ($option =~ "link to comment") {
     for $title in $TITLES --numbered {
         if $TITLE =~ $title.item {
            xdg-open $"($POSTS | get $title.index)"
         }
     }
   }
} else {
  exit 1
}

Articles from blogs I follow around the net

Synergy Greg

Synergy Greg would like to see you in His office, it is the one down the hall, past the cubicles and dreary faces, uplifted only when He deigns to venture forth. You will know Him when you see Him, He is the one composed, of a thousand writhing forms,…

via LudicityJune 22, 2024

Status update, June 2024

Hi all! This status update will be shorter than usual because I had a lot less free time for my open-source projects than usual this month. Indeed, I recently joined SNCF Réseau (the company responsible for the French railway infrastructure) to work on OSR…

via emersionJune 18, 2024

SolarWinds Serv-U (CVE-2024-28995) exploitation: We see you!

On June 5, 2024, SolarWinds published an advisory detailing CVE-2024-28995 - a path-traversal vulnerability in Serv-U, discovered by Hussein Daher. The affected versions are: SolarWinds Serv-U 15.4.2 HF 1 and earlier are affected SolarWinds Serv-U 15.4.2 …

via GreyNoise LabsJune 18, 2024

Why People are Angry over Go 1.23 Iterators

NOTE: This is based on, but completely rewritten, from a Twitter post: https://x.com/TheGingerBill/status/1802645945642799423 TL;DR It makes Go feel too “functional” rather than being an unabashed imperative language. I recently saw a post on Twitter showi…

via Articles on gingerBillJune 17, 2024

Programming at the edge with Fastly Compute

So you’ve heard about computing at the edge, and you’ve heard that Fastly let’s you run JavaScript, Go, Rust and any other language that compiles to Wasm at the edge… well, let’s take a look and while we’re at it let’s try and understand how caching works …

via Posts on integralistJune 12, 2024

israeli national police found trying to purchase stalkerware - #FuckStalkerware pt. 7

they're in pleasant company with other governments, intelligence companies, and data brokers

via maia blogJune 09, 2024

Generated by openring-rs