#!/usr/bin/env nu def main [--url(-u): string, --download(-d)] { let clipboard = xclip -o let url = $url. | default $clipboard match ($url | str contains "reddit.com") { true => ($url | get_url) false => ("URL is not a valid Reddit URL"; exit 1) } | download_url $download } # Documentation for handle_url def download_url [download: bool] { let input = $in match $download { true => (wget $input) false => (kitten icat $input) } } def get_url [] { let input = $in let decoded = $input | url decode match ($decoded | str contains "preview") { true => ( ($decoded | parse "{reddit}={imageUrl}?{params}").imageUrl.0 | str replace "preview" "i" ) false => ($decoded | parse "{reddit}={imageUrl}").imageUrl.0 } }