favicon here hometagsblogmicrobio cvtech cvgpg keys

Nushell Script for Fuzzy Finding Lobster Posts

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

#!/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

Status update, November 2024

Hi all! This month I’ve spent a lot of time triaging Sway and wlroots issues following the Sway 1.10 release. There are a few regressions, some of which are already fixed (thanks to all contributors for sending patches!). Kenny has added support for softwa…

via emersionNovember 21, 2024

Key Transparency and the Right to be Forgotten

This post is the first in a new series covering some of the reasoning behind decisions made in my project to build end-to-end encryption for direct messages on the Fediverse. (Collectively, Fedi-E2EE.) Although the reasons for specific design decisions sho…

via Dhole MomentsNovember 21, 2024

The Ethereum MEV Bots are a scam

Several months ago, I wrote this article: The Fascinating Ethereum MEV Bot Scam, where I dived deep into the technical aspects of a scam that has been circulating for years on platforms like X.com and YouTube. These scams revolve around deploying smart…

via Christian Visintin BlogNovember 19, 2024

hyper in curl Needs a Champion

tl;dr - hyper in curl is nearly complete, but it needs a champion. Without a partner actively engaged that wants to enable and ship, it’s now on the path for being deprecated and removed. It needs a champion, a backing vendor or distro. Will that be you? …

via seanmonstarNovember 19, 2024

Swift observations from a reluctant Rustacean

Recently I've been thinking about Swift in terms of Rust, & have appreciated anew some of the choices made. In Rust. There's been a proliferation of X vs Y posts on the web, especially since the advent of LLM AI, so I try to resist the format. It's often e…

via Mike KreuzerNovember 16, 2024

Go Concurrency Patterns

Goroutines Channels Select Statement Wait Groups Mutex Conditions Atomic Operations Once Context Map Real Examples Goroutines The go keyword is used to start a goroutine. A goroutine is a lightweight, managed thread used by the Go runtime to run functions …

via Posts on integralistNovember 15, 2024

Generated by openring-rs

favicon here hometagsblogmicrobio cvtech cvgpg keys