Skip to main content
  1. Blog/

Working with tuc in Nushell

·427 words·3 mins

Workflow:

Getting the links

In my browser I have a shortcut which gives me the title and url as a link in markdown format to the current page, and copies the link to my clipboard.

The link could look like this:

[Casestory: Marie Bjerre, profil på en magt-djøfer](https://www.folkets.dk/node/5041)

The clipboard can hold any amount of such links.

When I have a collection of these links in my clipboard history, I can feed them to a “scraper” and the scraped result to an llm. All the while still keeping the titles and urls from the links.

This way I can “enrich” each link with the content from the linked page. Then with a llm I can further work with this content.

Let’s say I have a bunch of markdown links in my clipboard history. The following Nushell custom command will take these and enrich each of them with a summary:

# summarize
def 'q summarize' [
--number (-n): int = 1
...prompt
] { 
let Ttu = cliphist list | lines | each { cliphist decode | lines } | flatten | each { parse "[{title}]({url})" } | flatten | last $number
print "✍️  SUMMARIZING:" ($Ttu | get title | to text) " ..." "\n" 
sleep 3sec
let c = $Ttu | each {|row| ( reader -o $row.url | aichat summarize ($prompt | str join ' ') ) } | wrap content
let Ttuc = $Ttu | merge $c
$Ttuc | to json | wl-copy
$Ttuc
}

This command will print a table for each page with the title, the url and the summarized content.

It will also “save” a copy of the table as JSON in my clipboard history.

Often I do something else before running the command, though.

I define a variable to hold the result of the command, like so:

let r = q summarize

Now the result of the command is saved as the variable r instead of printing it to the screen.

The result can then easily be shown simply by writing

$r

on the command line.

And if I want the see for example a particular row in the resulting table, that is a specific record, I just specify the row number I want like so:

$r.0

If I want not only 1 specific row but several rows, I can do it this way:

$r | get 0 2 5

I can then save the relevant row as a new variable and process them further to create new content.

See also: tuc as text based data structure for online research · Kiils