diff --git a/home/nogui/jj.nix b/home/nogui/jj.nix index 16a3cee72d79ae11c39750f43ebed9b0c9e32f36..b77e6e987dd88e9e4e60e1472185b0ae492af8a9 100644 --- a/home/nogui/jj.nix +++ b/home/nogui/jj.nix @@ -16,7 +16,7 @@ "$right" ]; editor = "hx"; paginate = "never"; - default-command = "status"; + default-command = "log"; }; templates.git_push_bookmark = ''"change/" ++ change_id.short()''; signing = { diff --git a/home/nogui/nushell.nix b/home/nogui/nushell.nix index 50cea0aff93c601f564b17e22ff5b2003101227a..d3d25c351bc6b61b922bb4453f7a2f07af281e26 100644 --- a/home/nogui/nushell.nix +++ b/home/nogui/nushell.nix @@ -37,19 +37,13 @@ $env.NIXOS_OZONE_WL = "1" $env.NIX_PATH = "nixpkgs=${inputs.nixpkgs-unstable}" ''; }; - # Individually symlink all ./nushell scripts to ~/.config/nushell/autoload - xdg.configFile = - let - src = ./nushell/autoload; - files = builtins.attrNames (builtins.readDir src); - configFiles = builtins.listToAttrs ( - map (file: { - name = "nushell/autoload/${file}"; - value = { - source = src + "/${file}"; - }; - }) files - ); - in - configFiles; + xdg.configFile = { + "nushell/jolheiser.nu".source = ./nushell/jolheiser.nu; + "nushell/ssh.nu".source = ./nushell/ssh.nu; + "nushell/miniserve.nu".source = ./nushell/miniserve.nu; + "nushell/clone.nu".source = ./nushell/clone.nu; + "nushell/git-bug.nu".source = ./nushell/git-bug.nu; + "nushell/ohmyposh.nu".source = ./nushell/ohmyposh.nu; + "nushell/tangled.nu".source = ./nushell/tangled.nu; + }; } diff --git a/home/nogui/nushell/autoload/clone.nu b/home/nogui/nushell/autoload/clone.nu deleted file mode 100644 index e161ecb931336591f7932e5c8b33a5e48685efcd..0000000000000000000000000000000000000000 --- a/home/nogui/nushell/autoload/clone.nu +++ /dev/null @@ -1,33 +0,0 @@ -module clone { - def "forge types" [] { - ["github", "gitea", "jojodev", "codeberg"] - } - - export def main [ - repo: string # Repo name - --forge (-f) = "github": string@"forge types" # Forge type (github, gitea, jojodev, codeberg) - --owner (-o): string # Owner (default: current dir name) - ] { - mut id = 'gh' - if $forge == 'gitea' { - $id = 'gt' - } else if $forge == 'jojodev' { - $id = 'jj' - } else if $forge == 'codeberg' { - $id = 'cb' - } - mut namespace = ($env.PWD | path basename) - if $owner != '' { - $namespace = $owner - } - let origin = $'ssh:($id):jolheiser/($repo).git' - let upstream = $'($id):($namespace)/($repo).git' - ^git clone $origin - cd $repo - if $namespace != 'jolheiser' { - ^git remote add upstream $upstream - ^git fetch upstream - } - } -} -use clone * diff --git a/home/nogui/nushell/autoload/comma.nu b/home/nogui/nushell/autoload/comma.nu deleted file mode 100644 index 68cf4f997be6dbbe127266d5230bf5faae4e1964..0000000000000000000000000000000000000000 --- a/home/nogui/nushell/autoload/comma.nu +++ /dev/null @@ -1,14 +0,0 @@ -module comma { - # Run a command if known, otherwise run it with nix - export def , [ - cmd: string # The command to run - ...args: string # Command arguments; all flags MUST be quoted - ] { - if (not (which $cmd | is-empty)) { - ^$cmd ...$args - return - } - ^nix run $"nixpkgs#($cmd)" -- ...$args - } -} -use comma * diff --git a/home/nogui/nushell/autoload/dev.nu b/home/nogui/nushell/autoload/dev.nu deleted file mode 100644 index b331e67ee1d78a702ad4bcc6e7fa07b584ba9fae..0000000000000000000000000000000000000000 --- a/home/nogui/nushell/autoload/dev.nu +++ /dev/null @@ -1,9 +0,0 @@ -module dev { - export def main [ - --port (-p) = 8080: int # Port - ] { - print $"Listening on http://localhost:($port)" - ^ssh -N -T -R $"3389:localhost:($port)" dragonwell - } -} -use dev * diff --git a/home/nogui/nushell/autoload/fg.nu b/home/nogui/nushell/autoload/fg.nu deleted file mode 100644 index bfaf3775f98274913e576b44d20811e6a8bf96f4..0000000000000000000000000000000000000000 --- a/home/nogui/nushell/autoload/fg.nu +++ /dev/null @@ -1,7 +0,0 @@ -module fg { - export def main [args ...string] { - ^rg --ignore-case --color=always --line-number --no-heading $args - | ^fzf --ansi --color 'hl:-1:underline,hl+:-1:underline:reverse' --delimiter ':' --preview "bat --color=always {1} --theme='ctp-mocha' --highlight-line {2}" --preview-window 'up,60%,border-bottom,+{2}+3/3,~3' --bind $"enter:become\(($env.EDITOR) +{2} {1}\)" - } -} -use fg * diff --git a/home/nogui/nushell/autoload/git-bug.nu b/home/nogui/nushell/autoload/git-bug.nu deleted file mode 100644 index ceed7af175e073714fd8dad4e657aa6872ec5506..0000000000000000000000000000000000000000 --- a/home/nogui/nushell/autoload/git-bug.nu +++ /dev/null @@ -1,77 +0,0 @@ -module git-bug { - export def "git bug init" [] { - git bug pull - let id = ^git-bug user -f json | from json | where name == 'jolheiser' | get --optional human_id.0 - if ($id | is-not-empty) { - ^git-bug user adopt $id - } else { - ^git-bug user new --name 'jolheiser' --email 'git@jolheiser.com' --avatar 'https://www.libravatar.org/avatar/cc498b605dee7b6fb9e6422332691bb4' - } - } - - export def "git bug pull" [] { - ^git fetch origin refs/bugs/*:refs/bugs/* refs/identities/*:refs/identities/* - ^rm -rf $"(^git rev-parse --git-dir)/git-bug" - } - - export def "git bug push" [] { - ^git push origin refs/bugs/*:refs/bugs/* refs/identities/*:refs/identities/* - } - - def "bug-id" [] { - ^git-bug bug --format json | from json | each {|bug| { value: $bug.human_id, description: $bug.title }} - } - - export extern "git bug bug status" [ - bug_id: string@bug-id - ] - - export extern "git bug bug status open" [ - bug_id: string@bug-id - ] - - export extern "git bug bug status close" [ - bug_id: string@bug-id - ] - - export extern "git bug bug rm" [ - bug_id: string@bug-id - ] - - export extern "gitbug bug comment" [ - bug_id: string@bug-id - ] - - export extern "git bug bug comment new" [ - bug_id: string@bug-id - ] - - export extern "git bug bug label" [ - bug_id: string@bug-id - ] - - export extern "git bug bug label new" [ - bug_id: string@bug-id - ] - - export extern "git bug bug label rm" [ - bug_id: string@bug-id - ] - - export extern "git bug bug select" [ - bug_id: string@bug-id - ] - - export extern "git bug bug show" [ - bug_id: string@bug-id - ] - - export extern "git bug bug title" [ - bug_id: string@bug-id - ] - - export extern "git bug bug title edit" [ - bug_id: string@bug-id - ] -} -use git-bug * diff --git a/home/nogui/nushell/autoload/gomodsri.nu b/home/nogui/nushell/autoload/gomodsri.nu deleted file mode 100644 index 40663524a6ebe784ae2a618d4c1fea187e73b732..0000000000000000000000000000000000000000 --- a/home/nogui/nushell/autoload/gomodsri.nu +++ /dev/null @@ -1,11 +0,0 @@ -module gomodsri { - export def main [] { - let tmp = (mktemp -d) - go mod vendor -o $tmp - let sri = (go run tailscale.com/cmd/nardump@latest --sri $tmp) - $sri | save -f go.mod.sri - rm -rf $tmp - echo 'nixpkgs.lib.fileContents ./go.mod.sri' - } -} -use gomodsri * diff --git a/home/nogui/nushell/autoload/httpstatus.nu b/home/nogui/nushell/autoload/httpstatus.nu deleted file mode 100644 index 7f3a4f71d79f243e043017ec2f2605ffb44a80b0..0000000000000000000000000000000000000000 --- a/home/nogui/nushell/autoload/httpstatus.nu +++ /dev/null @@ -1,75 +0,0 @@ -module httpstatus { - # Print out all HTTP statuses, or a specific one for a given code - export def main [ - 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 - } - } -} -use httpstatus * diff --git a/home/nogui/nushell/autoload/jolheiser.nu b/home/nogui/nushell/autoload/jolheiser.nu deleted file mode 100644 index 9912faa3e1db1dade5a02dc735fae51c0ce2a283..0000000000000000000000000000000000000000 --- a/home/nogui/nushell/autoload/jolheiser.nu +++ /dev/null @@ -1,12 +0,0 @@ -module jolheiser { - export alias cat = bat - export alias find = fd - export alias df = duf - export alias du = dust -b -d 1 - export alias ll = eza -al -} - -$env.EDITOR = 'hx' -$env.SSH_AUTH_SOCK = '/run/user/1000/ssh-agent' - -use jolheiser * diff --git a/home/nogui/nushell/autoload/miniserve.nu b/home/nogui/nushell/autoload/miniserve.nu deleted file mode 100644 index 101750c75741afadcde150e186b79b330de29270..0000000000000000000000000000000000000000 --- a/home/nogui/nushell/autoload/miniserve.nu +++ /dev/null @@ -1,41 +0,0 @@ -module miniserve { - export def serve [ - path: path # The path to serve - --dir (-d): string # The base dir in miniserve for the path - --public (-p) # Send to http://pubserve (via http://privserve) rather than http://files - --verbose (-v) # Print uploads - ] { - let endpoint = if $public { "http://privserve" } else { "http://files" } - let url = if $public { "http://pubserve.serval-vibes.ts.net" } else { "http://files" } - let upload = $"($endpoint)/upload" - let baseName = $path | path basename - let cleanDir = if $dir != null { $"($dir | str trim --char '/')" } else { "" } - # When uploading, "" is invalid. It must either be "/" or relative "foo/bar/" - let uploadDir = $"($cleanDir)/" - let serveDir = if $cleanDir != "" { $uploadDir } else { "" } - if ($path | path type) == "dir" { - let prefix = $path | path expand - let baseDir = [$cleanDir, ($prefix | path basename | str trim --char '/')] | path join - glob -F $"($prefix)/**" | each {|g| - let b = $g | str replace $prefix "" | str trim --left --char '/' - let d = [$baseDir, $b] | path join - if $verbose { print $"Creating dir ($d)" } - ^curl -F $"mkdir=($d)" $"($upload)?path=/" | complete - } - glob -D $"($prefix)/**" | each {|g| - let f = $g | str replace $prefix "" | str trim --left --char '/' - let t = [$baseDir, $f] | path join - let p = $t | path dirname - if $verbose { print $"Uploading ($g) to ($t)" } - ^curl -F $"path=@($g)" $"($upload)?path=($p)" | complete - } - } else { - if $verbose { print $"Creating dir ($uploadDir)" } - ^curl -F $"mkdir=($uploadDir)" $"($upload)?path=/" | complete - if $verbose { print $"Uploading ($path | path expand) to ($serveDir)($baseName)" } - ^curl -F $"path=@($path)" $"($upload)?path=($uploadDir)" | complete - } - $"($url)/($serveDir)($baseName)" - } -} -use miniserve * diff --git a/home/nogui/nushell/autoload/mkcd.nu b/home/nogui/nushell/autoload/mkcd.nu deleted file mode 100644 index 8a54e74b45bd106cc085a3e57d0c6a943d7e0bb5..0000000000000000000000000000000000000000 --- a/home/nogui/nushell/autoload/mkcd.nu +++ /dev/null @@ -1,10 +0,0 @@ -module mkcd { - # Make a directory and cd in to it - export def --env main [ - dir: path # The directory to create - ]: nothing -> nothing { - mkdir $dir - cd $dir - } -} -use mkcd * diff --git a/home/nogui/nushell/autoload/nato.nu b/home/nogui/nushell/autoload/nato.nu deleted file mode 100644 index e9eed86b4d90582fb47fdc1fee3723136b127b0b..0000000000000000000000000000000000000000 --- a/home/nogui/nushell/autoload/nato.nu +++ /dev/null @@ -1,54 +0,0 @@ -module nato { - # Convert input string to NATO - export def main [ - ...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)" - } - } - } -} -use nato * diff --git a/home/nogui/nushell/autoload/ohmyposh.nu b/home/nogui/nushell/ohmyposh.nu rename from home/nogui/nushell/autoload/ohmyposh.nu rename to home/nogui/nushell/ohmyposh.nu index 7b29dc04349e7cbecfb0d070e071ebbcd0e1160b..f702bff725a15f5d653bde3c6a10018226979fac 100644 --- a/home/nogui/nushell/autoload/ohmyposh.nu +++ b/home/nogui/nushell/ohmyposh.nu @@ -19,7 +19,7 @@ # See https://github.com/nushell/nushell/discussions/6402#discussioncomment-3466687. let cmd_duration = if $env.CMD_DURATION_MS == "0823" { 0 } else { $env.CMD_DURATION_MS } let width = ((term size).columns | into string) - ^oh-my-posh print primary $"--config=($env.POSH_THEME)" --shell=nu $"--shell-version=($env.NU_VERSION)" $"--execution-time=($cmd_duration)" $"--status=($env.LAST_EXIT_CODE)" $"--terminal-width=($width)" + ^oh-my-posh print primary $"--config=($env.POSH_THEME)" --shell=nu $"--shell-version=($env.NU_VERSION)" $"--execution-time=($cmd_duration)" $"--error=($env.LAST_EXIT_CODE)" $"--terminal-width=($width)" } } diff --git a/home/nogui/nushell/autoload/ssh.nu b/home/nogui/nushell/autoload/ssh.nu deleted file mode 100644 index 5dff3fef413e6fb36ced677f430d95a4fcf3b5cd..0000000000000000000000000000000000000000 --- a/home/nogui/nushell/autoload/ssh.nu +++ /dev/null @@ -1,91 +0,0 @@ -module ssh { - export extern main [ - destination?: string@"nu-complete ssh-host" - -4 # Forces ssh to use IPv4 addresses only. - -6 # Forces ssh to use IPv6 addresses only. - -A # Enables forwarding of connections from an authentication agent such as ssh-agent(1). - -a # Disables forwarding of the authentication agent connection. - -B: string # bind_interface - -b: string # bind_address - -C # Requests compression of all data - -c: string # cipher_spec - -D # [bind_address:]port - -E: string # log_file - -e # escape_char - -F: string # configfile - -f # Requests ssh to go to background just before command execution. - -G # Causes ssh to print its configuration after evaluating Host and Match blocks and exit. - -g # Allows remote hosts to connect to local forwarded ports - -I: string # pkcs11 - -i: string@"nu-complete ssh-identity" # identity_file - -J: string # destination - -K # Enables GSSAPI-based authentication and forwarding(delegation) of GSSAPI credentials to the server. - -k # Disables forwarding (delegation) of GSSAPI credentials to the server. - -L: string # [bind_address:]port:host:hostport / [bind_address:]port:remote_socket / local_socket:host:hostport / local_socket:remote_socket - -l: string # login_name - -M # Places the ssh client into “master” mode for connection sharing. - -m: string # mac_spec - -N # Do not execute a remote command. - -n # Redirects stdin from /dev/null (5) for details. - -O: string # ctl_cmd - -o: string # option - ] - - def parse-host [file: string] { - let lines = $file | open | lines | str trim - - mut result = [] - for $line in $lines { - let data = $line | parse --regex '^Include\s+(?.+)' - if ($data | is-not-empty) { - let include = parse-host ($data.file | first) - $result = ($result | append $include) - continue - } - let data = $line | parse --regex '^Host\s+(?.+)' - if ($data | is-not-empty) { - let host = $data.host | first - if ($host == '*') { - continue - } - $result = ($result | append { 'value': $host, 'description': "" }) - continue; - } - let data = $line | parse --regex '^HostName\s+(?.+)' - if ($data | is-not-empty) { - let last = $result | last | update 'description' ($data.hostname | first) - $result = ($result | drop | append $last) - } - } - $result - } - - def "nu-complete ssh-host" [] { - mut files = [ - '/etc/ssh/ssh_config', - '~/.ssh/config' - ] | where { |file| $file | path exists } - - - $files | each { |file| - parse-host $file - } | flatten - } - - def "nu-complete ssh-identity" [] { - ls ~/.ssh/ - | where {|f| - ($f.name | path parse | get extension) == "pub" - } - | get name - | path parse - | each {|p| {'value': $'~/.ssh/($p.stem)', 'description': $p.stem} } - } - - export def ssh-add-all [] { - nu-complete ssh-identity - | each {|s| print $s.value; ^ssh-add ($s.value | path expand); print '' } - null - } -} -use ssh * diff --git a/home/nogui/nushell/autoload/tangled.nu b/home/nogui/nushell/autoload/tangled.nu deleted file mode 100644 index e30ba6756c1415a71edbddab307c29100c2b261c..0000000000000000000000000000000000000000 --- a/home/nogui/nushell/autoload/tangled.nu +++ /dev/null @@ -1,60 +0,0 @@ -module tangled { - # Strings CLI - # - # Examples: - # $ string main.go - # $ echo "Hey tanglers!" | string --title "tanglers.txt" --description "A file for all the tanglers" - export def string [ - file?: path # File to create string from, otherwise stdin - --title (-t): string # Title of the string (default is filename when file is provided, otherwise random uuid) - --description (-d): string # Description of the string - ]: [ - path -> string - nothing -> string - ] { - mut _content = $in - mut _title = (random uuid) - if ($file != null) { - $_content = ($file | open --raw | decode utf-8) - $_title = ($file | path basename) - } - if ($title != null) { - $_title = $title - } - mut _desc = "" - if ($description != null) { - $_desc = $description - } - - if ($_content == null or $_content == "") { - error make {msg: "Cannot create a string with no content"} - } - - let payload = ({ - "$type": "sh.tangled.string", - "contents": $_content, - "filename": $_title, - "createdAt": (date now | format date "%Y-%m-%dT%H:%M:%SZ"), - "description": $_desc - } | to json) - - let tmp = (mktemp --tmpdir sh.tangled.string.XXX) - - $payload | save --force $tmp - - mut out = "" - try { - let resp = (^goat record create --no-validate $tmp) - # at://did:plc:35kdk2ntcs626zs6cm62i7ih/sh.tangled.string/3lxuash7vvc2f bafyreifv7c6il2zsa67oa6umutb52izbgrnmz336wzbgti2we3tpw3bcj4 - # 0 1 2 3 4 5 6 7 8 - let plc = ($resp | split words | get 3) - let rkey = ($resp | split words | get 7) - $out = $"https://tangled.sh/strings/did:plc:($plc)/($rkey)" - } - - rm $tmp - - $out - } -} -use tangled * diff --git a/home/nogui/nushell/autoload/tmp.nu b/home/nogui/nushell/autoload/tmp.nu deleted file mode 100644 index 003cff4384e2dc97b1a9115c8d3a32f4f6ee2764..0000000000000000000000000000000000000000 --- a/home/nogui/nushell/autoload/tmp.nu +++ /dev/null @@ -1,8 +0,0 @@ -module tmp { - # Create a temporary directory and cd in to it - export def --env main []: nothing -> nothing { - let t = mktemp --directory - cd $t - } -} -use tmp * diff --git a/home/nogui/nushell/clone.nu b/home/nogui/nushell/clone.nu new file mode 100644 index 0000000000000000000000000000000000000000..1e686813aa3b0a5b5893706726bb8277dd8a928f --- /dev/null +++ b/home/nogui/nushell/clone.nu @@ -0,0 +1,31 @@ +def "forge types" [] { + ["github", "gitea", "jojodev", "codeberg"] +} + +export def clone [ + repo: string # Repo name + --forge (-f) = "github": string@"forge types" # Forge type (github, gitea, jojodev, codeberg) + --owner (-o): string # Owner (default: current dir name) +] { + mut id = 'gh' + if $forge == 'gitea' { + $id = 'gt' + } else if $forge == 'jojodev' { + $id = 'jj' + } else if $forge == 'codeberg' { + $id = 'cb' + } + mut namespace = ($env.PWD | path basename) + if $owner != '' { + $namespace = $owner + } + let origin = $'ssh:($id):jolheiser/($repo).git' + let upstream = $'($id):($namespace)/($repo).git' + ^git clone $origin + cd $repo + if $namespace != 'jolheiser' { + ^git remote add upstream $upstream + ^git fetch upstream + } +} + diff --git a/home/nogui/nushell/config.nu b/home/nogui/nushell/config.nu index fd80fb76eeb1611c39a707abb9cea522c4525a9f..c72b8ced4d62640c2a9a2e1e5eff809ef97c4dfb 100644 --- a/home/nogui/nushell/config.nu +++ b/home/nogui/nushell/config.nu @@ -667,3 +667,7 @@ event: { send: menu name: commands_with_description } } ] } + + +source ~/.config/nushell/jolheiser.nu + diff --git a/home/nogui/nushell/git-bug.nu b/home/nogui/nushell/git-bug.nu new file mode 100644 index 0000000000000000000000000000000000000000..c0f421229e60b912d8daa9b7bfaa86a7824e2934 --- /dev/null +++ b/home/nogui/nushell/git-bug.nu @@ -0,0 +1,74 @@ +export def "git bug init" [] { + git bug pull + let id = ^git-bug user -f json | from json | where name == 'jolheiser' | get --optional human_id.0 + if ($id | is-not-empty) { + ^git-bug user adopt $id + } else { + ^git-bug user new --name 'jolheiser' --email 'git@jolheiser.com' --avatar 'https://www.libravatar.org/avatar/cc498b605dee7b6fb9e6422332691bb4' + } +} + +export def "git bug pull" [] { + ^git fetch origin refs/bugs/*:refs/bugs/* refs/identities/*:refs/identities/* + ^rm -rf $"(^git rev-parse --git-dir)/git-bug" +} + +export def "git bug push" [] { + ^git push origin refs/bugs/*:refs/bugs/* refs/identities/*:refs/identities/* +} + +def "bug-id" [] { + ^git-bug bug --format json | from json | each {|bug| { value: $bug.human_id, description: $bug.title }} +} + +export extern "git bug bug status" [ + bug_id: string@bug-id +] + +export extern "git bug bug status open" [ + bug_id: string@bug-id +] + +export extern "git bug bug status close" [ + bug_id: string@bug-id +] + +export extern "git bug bug rm" [ + bug_id: string@bug-id +] + +export extern "gitbug bug comment" [ + bug_id: string@bug-id +] + +export extern "git bug bug comment new" [ + bug_id: string@bug-id +] + +export extern "git bug bug label" [ + bug_id: string@bug-id +] + +export extern "git bug bug label new" [ + bug_id: string@bug-id +] + +export extern "git bug bug label rm" [ + bug_id: string@bug-id +] + +export extern "git bug bug select" [ + bug_id: string@bug-id +] + +export extern "git bug bug show" [ + bug_id: string@bug-id +] + +export extern "git bug bug title" [ + bug_id: string@bug-id +] + +export extern "git bug bug title edit" [ + bug_id: string@bug-id +] diff --git a/home/nogui/nushell/jolheiser.nu b/home/nogui/nushell/jolheiser.nu new file mode 100644 index 0000000000000000000000000000000000000000..f7f32744ace6ee6a9447e4ae5f3ad8eb9911b08d --- /dev/null +++ b/home/nogui/nushell/jolheiser.nu @@ -0,0 +1,190 @@ +## Aliases ## +alias cat = bat +alias find = fd +alias df = duf +alias du = dust -b -d 1 +alias just = just --shell "nu" --shell-arg "-c" +alias ll = ls -al + +## Functions ## +def fg [args ...string] { + ^rg --ignore-case --color=always --line-number --no-heading $args + | ^fzf --ansi --color 'hl:-1:underline,hl+:-1:underline:reverse' --delimiter ':' --preview "bat --color=always {1} --theme='ctp-mocha' --highlight-line {2}" --preview-window 'up,60%,border-bottom,+{2}+3/3,~3' --bind $"enter:become\(($env.EDITOR) +{2} {1}\)" +} + +def gomodsri [] { + let tmp = (mktemp -d) + go mod vendor -o $tmp + let sri = (go run tailscale.com/cmd/nardump@latest --sri $tmp) + $sri | save -f go.mod.sri + rm -rf $tmp + echo 'nixpkgs.lib.fileContents ./go.mod.sri' +} + +def dev [ + --port (-p) = 8080: int # Port +] { + print $"Listening on http://localhost:($port)" + ^ssh -N -T -R $"3389:localhost:($port)" dragonwell +} + +# Run a command if known, otherwise run it with nix +def , [ + cmd: string # The command to run + ...args: string # Command arguments; all flags MUST be quoted + ] { + if (not (which $cmd | is-empty)) { + ^$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 ## +$env.EDITOR = 'hx' +$env.SSH_AUTH_SOCK = '/run/user/1000/ssh-agent' +source ~/.config/nushell/ohmyposh.nu +source ~/.config/nushell/ssh.nu +source ~/.config/nushell/miniserve.nu +source ~/.config/nushell/clone.nu +source ~/.config/nushell/git-bug.nu +source ~/.config/nushell/tangled.nu diff --git a/home/nogui/nushell/miniserve.nu b/home/nogui/nushell/miniserve.nu new file mode 100644 index 0000000000000000000000000000000000000000..5418c40d2f230ad245734dca5d12341f4efeeff7 --- /dev/null +++ b/home/nogui/nushell/miniserve.nu @@ -0,0 +1,38 @@ +export def serve [ + path: path # The path to serve + --dir (-d): string # The base dir in miniserve for the path + --public (-p) # Send to http://pubserve (via http://privserve) rather than http://files + --verbose (-v) # Print uploads +] { + let endpoint = if $public { "http://privserve" } else { "http://files" } + let url = if $public { "http://pubserve.serval-vibes.ts.net" } else { "http://files" } + let upload = $"($endpoint)/upload" + let baseName = $path | path basename + let cleanDir = if $dir != null { $"($dir | str trim --char '/')" } else { "" } + # When uploading, "" is invalid. It must either be "/" or relative "foo/bar/" + let uploadDir = $"($cleanDir)/" + let serveDir = if $cleanDir != "" { $uploadDir } else { "" } + if ($path | path type) == "dir" { + let prefix = $path | path expand + let baseDir = [$cleanDir, ($prefix | path basename | str trim --char '/')] | path join + glob -F $"($prefix)/**" | each {|g| + let b = $g | str replace $prefix "" | str trim --left --char '/' + let d = [$baseDir, $b] | path join + if $verbose { print $"Creating dir ($d)" } + ^curl -F $"mkdir=($d)" $"($upload)?path=/" | complete + } + glob -D $"($prefix)/**" | each {|g| + let f = $g | str replace $prefix "" | str trim --left --char '/' + let t = [$baseDir, $f] | path join + let p = $t | path dirname + if $verbose { print $"Uploading ($g) to ($t)" } + ^curl -F $"path=@($g)" $"($upload)?path=($p)" | complete + } + } else { + if $verbose { print $"Creating dir ($uploadDir)" } + ^curl -F $"mkdir=($uploadDir)" $"($upload)?path=/" | complete + if $verbose { print $"Uploading ($path | path expand) to ($serveDir)($baseName)" } + ^curl -F $"path=@($path)" $"($upload)?path=($uploadDir)" | complete + } + $"($url)/($serveDir)($baseName)" +} diff --git a/home/nogui/nushell/ssh.nu b/home/nogui/nushell/ssh.nu new file mode 100644 index 0000000000000000000000000000000000000000..5c38eadcca29ddd14b9ce99621010fd57f550322 --- /dev/null +++ b/home/nogui/nushell/ssh.nu @@ -0,0 +1,89 @@ +export extern "ssh" [ + destination?: string@"nu-complete ssh-host" + -4 # Forces ssh to use IPv4 addresses only. + -6 # Forces ssh to use IPv6 addresses only. + -A # Enables forwarding of connections from an authentication agent such as ssh-agent(1). + -a # Disables forwarding of the authentication agent connection. + -B: string # bind_interface + -b: string # bind_address + -C # Requests compression of all data + -c: string # cipher_spec + -D # [bind_address:]port + -E: string # log_file + -e # escape_char + -F: string # configfile + -f # Requests ssh to go to background just before command execution. + -G # Causes ssh to print its configuration after evaluating Host and Match blocks and exit. + -g # Allows remote hosts to connect to local forwarded ports + -I: string # pkcs11 + -i: string@"nu-complete ssh-identity" # identity_file + -J: string # destination + -K # Enables GSSAPI-based authentication and forwarding(delegation) of GSSAPI credentials to the server. + -k # Disables forwarding (delegation) of GSSAPI credentials to the server. + -L: string # [bind_address:]port:host:hostport / [bind_address:]port:remote_socket / local_socket:host:hostport / local_socket:remote_socket + -l: string # login_name + -M # Places the ssh client into “master” mode for connection sharing. + -m: string # mac_spec + -N # Do not execute a remote command. + -n # Redirects stdin from /dev/null (5) for details. + -O: string # ctl_cmd + -o: string # option +] + +def parse-host [file: string] { + let lines = $file | open | lines | str trim + + mut result = [] + for $line in $lines { + let data = $line | parse --regex '^Include\s+(?.+)' + if ($data | is-not-empty) { + let include = parse-host ($data.file | first) + $result = ($result | append $include) + continue + } + let data = $line | parse --regex '^Host\s+(?.+)' + if ($data | is-not-empty) { + let host = $data.host | first + if ($host == '*') { + continue + } + $result = ($result | append { 'value': $host, 'description': "" }) + continue; + } + let data = $line | parse --regex '^HostName\s+(?.+)' + if ($data | is-not-empty) { + let last = $result | last | update 'description' ($data.hostname | first) + $result = ($result | drop | append $last) + } + } + $result +} + +def "nu-complete ssh-host" [] { + mut files = [ + '/etc/ssh/ssh_config', + '~/.ssh/config' + ] | where { |file| $file | path exists } + + + $files | each { |file| + parse-host $file + } | flatten +} + +def "nu-complete ssh-identity" [] { + ls ~/.ssh/ + | where {|f| + ($f.name | path parse | get extension) == "pub" + } + | get name + | path parse + | each {|p| {'value': $'~/.ssh/($p.stem)', 'description': $p.stem} } +} + +export def ssh-add-all [] { + nu-complete ssh-identity + | each {|s| print $s.value; ^ssh-add ($s.value | path expand); print '' } + null +} + diff --git a/home/nogui/nushell/tangled.nu b/home/nogui/nushell/tangled.nu new file mode 100644 index 0000000000000000000000000000000000000000..3d09d3791aa5e53a56ad79bfb182c6c81d31c1c2 --- /dev/null +++ b/home/nogui/nushell/tangled.nu @@ -0,0 +1,57 @@ +# Strings CLI +# +# Examples: +# $ string main.go +# $ echo "Hey tanglers!" | string --title "tanglers.txt" --description "A file for all the tanglers" +export def string [ + file?: path # File to create string from, otherwise stdin + --title (-t): string # Title of the string (default is filename when file is provided, otherwise random uuid) + --description (-d): string # Description of the string +]: [ + path -> string + nothing -> string +] { + mut _content = $in + mut _title = (random uuid) + if ($file != null) { + $_content = ($file | open --raw | decode utf-8) + $_title = ($file | path basename) + } + if ($title != null) { + $_title = $title + } + mut _desc = "" + if ($description != null) { + $_desc = $description + } + + if ($_content == null or $_content == "") { + error make {msg: "Cannot create a string with no content"} + } + + let payload = ({ + "$type": "sh.tangled.string", + "contents": $_content, + "filename": $_title, + "createdAt": (date now | format date "%Y-%m-%dT%H:%M:%SZ"), + "description": $_desc + } | to json) + + let tmp = (mktemp --tmpdir sh.tangled.string.XXX) + + $payload | save --force $tmp + + mut out = "" + try { + let resp = (^goat record create --no-validate $tmp) + # at://did:plc:35kdk2ntcs626zs6cm62i7ih/sh.tangled.string/3lxuash7vvc2f bafyreifv7c6il2zsa67oa6umutb52izbgrnmz336wzbgti2we3tpw3bcj4 + # 0 1 2 3 4 5 6 7 8 + let plc = ($resp | split words | get 3) + let rkey = ($resp | split words | get 7) + $out = $"https://tangled.sh/strings/did:plc:($plc)/($rkey)" + } + + rm $tmp + + $out +} diff --git a/home/nogui/oh-my-posh.nix b/home/nogui/oh-my-posh.nix index 91c69b51f9e5e87e47eed514ef59375b79cae3ad..4e017c46ecead94b0a9b9d10cdb78c52d0d600f4 100644 --- a/home/nogui/oh-my-posh.nix +++ b/home/nogui/oh-my-posh.nix @@ -31,12 +31,11 @@ builtins.toString (descriptionMax - 1) }) ++ "…" ), "•", - change_id.shortest(6).prefix() ++ "(" ++ change_id.shortest(6).rest() ++ ")", + change_id.shortest(6).prefix() ++ "|" ++ change_id.shortest(6).rest(), if(empty, "(empty)"), if(conflict, "(conflict)"), if(divergent, "(divergent)"), if(hidden, "(hidden)"), - if(immutable, "🔒"), ) ' '';