Skip to content

Instantly share code, notes, and snippets.

@shaoyanji
Created December 10, 2025 14:53
Show Gist options
  • Select an option

  • Save shaoyanji/dbc5d6e8fe8abb338226a28cd5f8d6cd to your computer and use it in GitHub Desktop.

Select an option

Save shaoyanji/dbc5d6e8fe8abb338226a28cd5f8d6cd to your computer and use it in GitHub Desktop.
let privatekeylocation = "key.txt"
let publicage = open $privatekeylocation | split row ": " | get 2 | split row "\n" | first
let pantryid = ""
let pantryurl = "https://getpantry.cloud/apiv1/pantry"
# 100 baskets (JSON objects)
# each with a max size of 1.44mb per basket
# API requests are limited to 2 calls per second. -from the FAQ
# https://getpantry.cloud/
# User and basket information
export def nupantry [] {
http get $"($pantryurl)/($pantryid)"
}
# fuzzy finder used for TUI
export def "nupantry fuzzy" [] {
nupantry | get baskets | input list -f -d name
}
# fetch or get using API
export def "nupantry get" [] {
http get $"($pantryurl)/($pantryid)/basket/(nupantry fuzzy | get name |url encode)"
}
# deleting a basket
export def "nupantry delete" [] {
http delete $"($pantryurl)/($pantryid)/basket/(nupantry fuzzy | get name |url encode)"
}
# create a new or post, Usage: pipe the data in
export def "nupantry post" [] {
$in | to json | http post -H [Content-type application/json] $"($pantryurl)/($pantryid)/basket/(input 'name the basket > ' | url encode)"
}
# partial append if needed, Usage: Pipe
export def "nupantry put" [] {
$in | to json | http put -H [Content-type application/json] $"($pantryurl)/($pantryid)/basket/(nupantry fuzzy | get name | url encode)"
}
# encrypt, Usage: Pipe and age
export def "nupantry encrypt" [] {
$in | age -r $publicage | encode base64 | {$"($publicage)": $"($in)"}
}
# decrypt, Usage: usually after dl but used in conjunction with nupantry get | nupantry decrypt
export def "nupantry decrypt" [] {
$in | get $publicage | decode base64 | age -d -i $privatekeylocation
}
# uploads a encrypted file that is base64 encoded, it has to be somewhat of a tiny file 1.44 MB
export def "nupantry up" [] {
{data: $"($in | encode base64)" } | to json | nupantry encrypt | nupantry post
}
# uploads a file that is base64 encoded
export def "nupantry share" [] {
{data: $"($in | encode base64)" } | to json | nupantry post
}
# does some post processing handles either encrypted or unencrypted pantry data with the convention of the key name as data or age
export def "nupantry dl" [] {
let filename = nupantry fuzzy | get name
http get $"($pantryurl)/($pantryid)/basket/($filename |url encode)"
| items {|key, data| if ($key == "data") {
$data } else {
$data
| decode base64
| age -d -i $privatekeylocation
| from json
| get data
}
}
| get 0
| decode base64
| save $filename
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment