home tags blog microbio cv tech cv

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

Agile is a tainted term

Oh no, not another agile article. But at least this one isn't attempting to teach or reconcile. I'm not going to talk about the difference between agile and Agile™ nor will I try to convince you of my favorite flavor of Agile™. Instead, I'm here to assert …

via pcloadletter February 16, 2024

You Must Read At Least One Book To Ride

Two things are true. The first is going to sound bad in a culture where engineers are encouraged to apologize for existing while it is totally acceptable for a grifter that can't code to insist that they're a "thought leader". It is that, in my immediate p…

via Ludicity February 15, 2024

Code injection or backdoor: A new look at Ivanti’s CVE-2021-44529

This is yet another, “Ron got nerdsniped by a thing and wasted enough time that he needs something to show for it” blog. Which, come to think of it, are pretty much all my blogs. :) Recently, a tweet from Steven Seeley (ϻг_ϻε) caught my eye - an exploit fo…

via GreyNoise Labs February 15, 2024

Generated by openring-rs