diff --git a/home/nogui/nushell/jolheiser.nu b/home/nogui/nushell/jolheiser.nu index f7f32744ace6ee6a9447e4ae5f3ad8eb9911b08d..4bee4267c92f68640da62d8b638a49853b158dd2 100644 --- a/home/nogui/nushell/jolheiser.nu +++ b/home/nogui/nushell/jolheiser.nu @@ -21,6 +21,22 @@ rm -rf $tmp echo 'nixpkgs.lib.fileContents ./go.mod.sri' } +def q [ + --debug # Debug mode, only echo query + ...args: string + ] { + let input = $in + mut query = $args | str join ' ' + if ($input | is-not-empty) { + $query = $"($query)\n\n($input)" + } + if ($debug) { + print $query + return + } + ^llm -s "Answer in as few words as possible. Use a brief style with short replies." -m claude-3.5-sonnet $"($query)" +} + def dev [ --port (-p) = 8080: int # Port ] { @@ -38,145 +54,6 @@ ^$cmd ...$args return } ^nix run $"nixpkgs#($cmd)" -- ...$args -} - -# Create a temporary directory and cd in to it -def --env tmp []: nothing -> nothing { - let t = mktemp --directory - cd $t -} - -# Make a directory and cd in to it -def --env mkcd [ - dir: path # The directory to create -]: nothing -> nothing { - mkdir $dir - cd $dir -} - -# Convert input string to NATO -def nato [ - ...string: string # Input string -]: nothing -> string { - let m = { - "a": "Alpha", - "b": "Bravo", - "d": "Delta", - "e": "Echo", - "f": "Foxtrot", - "g": "Golf", - "h": "Hotel", - "i": "India", - "j": "Juliett", - "k": "Kilo", - "l": "Lima", - "m": "Mike", - "n": "November", - "o": "Oscar", - "p": "Papa", - "q": "Quebec", - "r": "Romeo", - "s": "Sierra", - "t": "Tango", - "u": "Uniform", - "v": "Victor", - "w": "Whiskey", - "x": "X-ray", - "y": "Yankee", - "z": "Zulu", - "1": "One", - "2": "Two", - "3": "Three", - "4": "Four", - "5": "Five", - "6": "Six", - "7": "Seven", - "8": "Eight", - "9": "Nine", - "0": "Zero" - } - - $string | str join " " | split chars | reduce --fold "" {|it, acc| - let word = $m | get --optional ($it | str downcase) - if $acc == "" { - $word - } else { - $"($acc) ($word)" - } - } -} - -# Print out all HTTP statuses, or a specific one for a given code -def httpstatus [ - code?: int # HTTP status code -]: nothing -> string { - let s = { - "100": "Continue", - "101": "Switching Protocols", - "102": "Processing", - "200": "OK", - "201": "Created", - "202": "Accepted", - "203": "Non-Authoritative Information", - "204": "No Content", - "205": "Reset Content", - "206": "Partial Content", - "207": "Multi-Status", - "208": "Already Reported", - "300": "Multiple Choices", - "301": "Moved Permanently", - "302": "Found", - "303": "See Other", - "304": "Not Modified", - "305": "Use Proxy", - "307": "Temporary Redirect", - "400": "Bad Request", - "401": "Unauthorized", - "402": "Payment Required", - "403": "Forbidden", - "404": "Not Found", - "405": "Method Not Allowed", - "406": "Not Acceptable", - "407": "Proxy Authentication Required", - "408": "Request Timeout", - "409": "Conflict", - "410": "Gone", - "411": "Length Required", - "412": "Precondition Failed", - "413": "Request Entity Too Large", - "414": "Request-URI Too Large", - "415": "Unsupported Media Type", - "416": "Request Range Not Satisfiable", - "417": "Expectation Failed", - "418": "I'm a teapot", - "420": "Blaze it", - "422": "Unprocessable Entity", - "423": "Locked", - "424": "Failed Dependency", - "425": "No code", - "426": "Upgrade Required", - "428": "Precondition Required", - "429": "Too Many Requests", - "431": "Request Header Fields Too Large", - "449": "Retry with", - "500": "Internal Server Error", - "501": "Not Implemented", - "502": "Bad Gateway", - "503": "Service Unavailable", - "504": "Gateway Timeout", - "505": "HTTP Version Not Supported", - "506": "Variant Also Negotiates", - "507": "Insufficient Storage", - "509": "Bandwidth Limit Exceeded", - "510": "Not Extended", - "511": "Network Authentication Required", - } - - if $code != null { - $s | get $"($code)" - } else { - $s | items {|key, value| echo $"($key) ($value)"} | to text - } } ## Other ##