repositories / dotfiles

dotfiles

bugabingas dorkfiles

owned by bugabinga

Update Nushell utilities

e0539dcba6cbc079f91a9d9c19cc052e33d057f1

Oliver Jan Krylow <oliver@bugabinga.net> ·

unsigned

Browse filesCompare with HEAD

Changed files (13)

nugu/ghostty.nu

Added
new file mode 100644
1 +use palette.nu
3 +# Generate a ghostty theme file from nugu palette.
4 +# Ghostty theme files are flat key=value configs with palette indices 0-15.
5 +#
6 +# Mapping follows the same semantic roles as wezterm/nugu/init.lua:
7 +#
8 +# ANSI 0-7 (standard): content.* + global semantic colors
9 +# ANSI 8-15 (bright): ui.* + content.important_global
10 +# 16-19: indexed extras
12 +export def theme [mode: string] {
13 + let nugu = (palette nugu $mode)
14 + let p = $nugu.palette
16 + # ANSI standard 0-7
17 + let std = [
18 + $p.content.backdrop # 0: BLACK (darkest = background)
19 + $p.error # 1: RED (error)
20 + $p.content.focus # 2: GREEN (active attention)
21 + $p.warning # 3: YELLOW (warning)
22 + $p.content.important_local # 4: BLUE (prominent content)
23 + $p.content.accent # 5: MAGENTA (brand identity)
24 + $p.content.unfocus # 6: CYAN (deepest visible, dim)
25 + $p.content.normal # 7: WHITE (brightest = foreground)
26 + ]
28 + # ANSI bright 8-15
29 + let bri = [
30 + $p.content.minor # 8: BRIGHT BLACK (receded content)
31 + $p.info # 9: BRIGHT RED (info)
32 + $p.ui.unfocus # 10: BRIGHT GREEN (UI dim borders)
33 + $p.ui.backdrop # 11: BRIGHT YELLOW (UI panel backgrounds)
34 + $p.content.important_global # 12: BRIGHT BLUE (most visible content)
35 + $p.ui.accent # 13: BRIGHT MAGENTA (UI brand accent)
36 + $p.ui.important_local # 14: BRIGHT CYAN (UI highlights)
37 + $p.ui.important_global # 15: BRIGHT WHITE (prominent UI)
38 + ]
40 + # Indexed 16-19: nugu semantic extras
41 + let idx = [
42 + $p.debug # 16: debug
43 + $p.ui.normal # 17: ui.normal
44 + $p.ui.minor # 18: ui.minor
45 + $p.ui.focus # 19: ui.focus
46 + ]
48 + let palettes = ($std | enumerate | each {|e|
49 + $"palette=($e.index)=($e.item)"
50 + }) ++ ($bri | enumerate | each {|e|
51 + $"palette=(($e.index + 8))=($e.item)"
52 + }) ++ ($idx | enumerate | each {|e|
53 + $"palette=(($e.index + 16))=($e.item)"
54 + })
56 + let header = [
57 + $"foreground=($p.content.normal)"
58 + $"background=($p.content.backdrop)"
59 + $"cursor-color=($p.ui.accent)"
60 + $"cursor-text=($p.ui.backdrop)"
61 + $"selection-foreground=($p.ui.backdrop)"
62 + $"selection-background=($p.ui.focus)"
63 + ]
65 + ($header ++ $palettes) | str join "\n"

nugu/justfile

Modified
11 11 open site.nu | nu-check --as-module --debug site.nu
12 12 open helix.nu | nu-check --as-module --debug helix.nu
13 13 open wezterm.nu | nu-check --as-module --debug wezterm.nu
14 + open ghostty.nu | nu-check --as-module --debug ghostty.nu
15 16 fmt: lint
16 17 taplo fmt
54 55 cp {{output}}/wezterm/palette_dark.lua ~/.config/wezterm/bugabinga/nugu/palette_dark.lua
55 56 cp {{output}}/wezterm/palette_light.lua ~/.config/wezterm/bugabinga/nugu/palette_light.lua
57 -install: helix wezterm
58 +ghostty: build
59 + rm --force --recursive {{output}}/ghostty
60 + mkdir {{output}}/ghostty
61 + use ghostty.nu; ghostty theme dark | save --raw {{output}}/ghostty/nugu-dark
62 + use ghostty.nu; ghostty theme light | save --raw {{output}}/ghostty/nugu-light
63 + mkdir ../ghostty/themes
64 + cp {{output}}/ghostty/nugu-dark ../ghostty/themes/nugu-dark
65 + cp {{output}}/ghostty/nugu-light ../ghostty/themes/nugu-light
67 +install: helix wezterm ghostty

nushell/.pi/remember.jsonl

Added
new file mode 100644
1 +{"op":"add","id":"RM016","ts":"2026-05-04T07:11:50.481Z","tags":["nushell","dotfiles","carapace","completion"],"fact":"Nushell dotfiles generate ~/.config/nushell/carapace.nu in env.nu via `carapace _carapace nushell`; carapace is sourced from login.nu, not config.nu.","reason":"Discovered while diagnosing Nushell completion behavior; matters because generated carapace config is overwritten on shell startup and only loaded for login shells unless moved/sourced elsewhere."}
2 +{"op":"add","id":"RM017","ts":"2026-05-04T07:22:25.818Z","tags":["nushell","dotfiles","carapace","completion"],"fact":"Nushell dotfiles no longer generate/source ~/.config/nushell/carapace.nu; login.nu sources modules/completion.nu, which installs a wrapped Carapace external completer returning null on empty non-flag results for Nushell path fallback.","reason":"Changed completion setup to fix Carapace suppressing file completion for commands like java; matters for future completion debugging."}

nushell/.pi/remember.md

Added
new file mode 100644
1 +# Project Facts
3 +2 remembered fact(s).
5 +| ID | Tags | Fact | Reason |
6 +|-----|------|------|--------|
7 +| RM016 | nushell, dotfiles, carapace, completion | Nushell dotfiles generate ~/.config/nushell/carapace.nu in env.nu via `carapace _carapace nushell`; carapace is sourced from login.nu, not config.nu. | Discovered while diagnosing Nushell completion behavior; matters because generated carapace config is overwritten on shell startup and only loaded for login shells unless moved/sourced elsewhere. |
8 +| RM017 | nushell, dotfiles, carapace, completion | Nushell dotfiles no longer generate/source ~/.config/nushell/carapace.nu; login.nu sources modules/completion.nu, which installs a wrapped Carapace external completer returning null on empty non-flag results for Nushell path fallback. | Changed completion setup to fix Carapace suppressing file completion for commands like java; matters for future completion debugging. |

nushell/config.nu

Modified
1 -$env.config = {
2 - edit_mode: vi
3 - show_banner: false
4 - buffer_editor: "nvim"
5 - table: {
6 - mode: markdown
7 - }
8 - rm: {
9 - always_trash: (not $env.TERMUX)
10 - }
11 - cursor_shape: {
12 - vi_insert: line
13 - vi_normal: block
14 - }
16 - float_precision: 3
17 - shell_integration: {
18 - osc9_9: false
19 - # unfortunatelly, this seems to be buggy on win32 with wezterm
20 - osc133: ($nu.os-info.family | str contains "unix")
21 - }
23 - highlight_resolved_externals : true
24 - use_kitty_protocol : (not $env.WIN32)
26 - color_config: {
27 - # -- primitives (data types) --
28 - int: green
29 - float: green
30 - bool: green_bold
31 - string: blue
32 - nothing: dark_gray
33 - binary: dark_gray
34 - duration: green
35 - range: dark_gray
36 - cell-path: dark_gray
38 - # -- table / presentation --
39 - separator: light_green
40 - header: light_blue_bold
41 - row_index: light_green
42 - leading_trailing_space_bg: dark_gray
43 - hints: cyan
44 - empty: dark_gray
45 - search_result: green_bold
47 - # -- shapes (syntax highlighting, Nugu philosophy) --
48 - # human meaning → prominent (important_local / focus)
49 - shape_string: blue
50 - shape_raw_string: blue
51 - shape_string_interpolation: green_bold
52 - shape_int: green_bold
53 - shape_float: green_bold
54 - shape_bool: green_bold
55 - shape_filepath: green
56 - shape_directory: green
57 - shape_globpattern: green
58 - shape_glob_interpolation: green_bold
59 - shape_record: green
60 - shape_list: green
61 - shape_table: green
62 - shape_datetime: green_bold
63 - shape_match_pattern: blue
64 - shape_signature: blue
65 - shape_literal: white
66 - shape_custom: magenta_bold
67 - shape_closure: blue_bold
68 - shape_block: blue_bold
69 - shape_range: dark_gray
71 - # structural / plumbing → receded (minor)
72 - shape_keyword: dark_gray
73 - shape_operator: dark_gray
74 - shape_pipe: dark_gray
75 - shape_redirection: dark_gray
76 - shape_flag: light_cyan
77 - shape_binary: dark_gray
78 - shape_nothing: dark_gray
79 - shape_matching_brackets: dark_gray_bold
80 - shape_vardecl: white
81 - shape_variable: white
83 - # externals
84 - shape_external: light_magenta
85 - shape_externalarg: green_bold
86 - shape_external_resolved: magenta_bold
87 - shape_internalcall: light_cyan_bold
89 - # errors
90 - shape_garbage: { fg: white, bg: red, attr: b }
91 - }
93 - history: {
94 - file_format: "sqlite"
95 - isolation: true
96 - }
97 -}
1 +$env.config = {
2 + edit_mode: vi
3 + show_banner: false
4 + buffer_editor: "nvim"
5 + table: {
6 + mode: markdown
7 + }
8 + rm: {
9 + always_trash: (not $env.TERMUX)
10 + }
11 + cursor_shape: {
12 + vi_insert: line
13 + vi_normal: block
14 + }
16 + float_precision: 3
17 + shell_integration: {
18 + osc9_9: true
19 + # unfortunately, this seems to be buggy on win32 with wezterm
20 + # osc133: ($nu.os-info.family | str contains "unix")
21 + osc133: true
22 + }
24 + highlight_resolved_externals : true
25 + use_kitty_protocol : (not $env.WIN32)
27 + color_config: {
28 + # -- primitives (data types) --
29 + int: green
30 + float: green
31 + bool: green_bold
32 + string: blue
33 + nothing: dark_gray
34 + binary: dark_gray
35 + duration: green
36 + range: dark_gray
37 + cell-path: dark_gray
39 + # -- table / presentation --
40 + separator: light_green
41 + header: light_blue_bold
42 + row_index: light_green
43 + leading_trailing_space_bg: dark_gray
44 + hints: cyan
45 + empty: dark_gray
46 + search_result: green_bold
48 + # -- shapes (syntax highlighting, Nugu philosophy) --
49 + # human meaning → prominent (important_local / focus)
50 + shape_string: blue
51 + shape_raw_string: blue
52 + shape_string_interpolation: green_bold
53 + shape_int: green_bold
54 + shape_float: green_bold
55 + shape_bool: green_bold
56 + shape_filepath: green
57 + shape_directory: green
58 + shape_globpattern: green
59 + shape_glob_interpolation: green_bold
60 + shape_record: green
61 + shape_list: green
62 + shape_table: green
63 + shape_datetime: green_bold
64 + shape_match_pattern: blue
65 + shape_signature: blue
66 + shape_literal: white
67 + shape_custom: magenta_bold
68 + shape_closure: blue_bold
69 + shape_block: blue_bold
70 + shape_range: dark_gray
72 + # structural / plumbing → receded (minor)
73 + shape_keyword: dark_gray
74 + shape_operator: dark_gray
75 + shape_pipe: dark_gray
76 + shape_redirection: dark_gray
77 + shape_flag: light_cyan
78 + shape_binary: dark_gray
79 + shape_nothing: dark_gray
80 + shape_matching_brackets: dark_gray_bold
81 + shape_vardecl: white
82 + shape_variable: white
84 + # externals
85 + shape_external: light_magenta
86 + shape_externalarg: green_bold
87 + shape_external_resolved: magenta_bold
88 + shape_internalcall: light_cyan_bold
90 + # errors
91 + shape_garbage: { fg: white, bg: red, attr: b }
92 + }
94 + history: {
95 + file_format: "sqlite"
96 + isolation: true
97 + }

nushell/env.nu

Modified
10 10 $env.NOTES = ("~/Notes" | path expand)
11 11 $env.TOOLS = ("~/Tools" | path expand)
12 12 $env.CARGO_HOME = ( "~/.cargo" | path expand )
13 -if (which sccache | is-not-empty) { $env.RUSTC_WRAPPER = "sccache" }
14 13 $env.GO_HOME = ( "~/.go" | path expand )
14 +$env.DOT_LOCAL = ( "~/.local" | path expand )
15 15 $env.DIFFTOOL = "zeditor --wait --diff"
16 16 $env.OPENCODE_HOME = ( "~/.opencode" | path expand)
17 -$env.OPENCODE_EXPERIMENTAL_LSP_TOOL = true
18 18 if (not $env.WIN32) {
19 19 # make sure to start ssh-agent user service: userctl enable --now ssh-agent
20 20 $env.SSH_AUTH_SOCK = $"($env.XDG_RUNTIME_DIR)/ssh-agent.socket"
23 +$env.PI_SKIP_VERSION_CHECK = true
24 +$env.PI_TELEMETRY = true
25 +# this seems to be ignored! duplicated in settings for now...
26 +$env.PI_CODING_AGENT_SESSION_DIR = "~/.local/state/pi/sessions" | path expand
27 +$env.PI_CACHE_RETENTION = "long"
29 +if (which sccache | is-not-empty) { $env.RUSTC_WRAPPER = "sccache" }
23 31 if $env.WIN32 {
24 32 $env.Path = (
25 33 $env.Path
38 46 | append ($env.GO_HOME | path join bin)
39 47 | append ($env.TOOLS | path join bin)
40 48 | append ($env.OPENCODE_HOME | path join bin)
49 + | append ($env.DOT_LOCAL | path join bin)
41 50 | uniq # filter so the paths are unique
87 96 '' | save -f $zoxide_config_path
90 -# generate carapace hooks for sourcing later on
91 -# $env.CARAPACE_BRIDGES = 'zsh,fish,bash,inshellisense' # optional
99 +# Carapace bridges available on this system: bash.
100 +# fish/zsh/inshellisense executables are not installed, so those bridges add no completions.
101 +$env.CARAPACE_BRIDGES = 'bash'
92 102 $env.CARAPACE_LENIENT = 1
93 -let carapace_config_path = $nu.default-config-dir | path join 'carapace.nu'
94 -if not (which carapace | is-empty) {
95 - carapace _carapace nushell | save --force $carapace_config_path
96 -} else {
97 - '' | save -f $carapace_config_path
100 104 if not (which mise | is-empty) {
101 105 mkdir ($nu.vendor-autoload-dirs | last)

nushell/gen-secrets.nu

Modified
29 29 secret GITHUB_PAT_TOKEN_LLM
30 30 secret MINIMAX_USAGE_API_KEY
31 31 secret ZAI_USAGE_API_KEY
32 +secret MINIMAX_API_KEY
33 +secret ZAI_API_KEY
34 +secret MINIMAX_WORK_API_KEY
35 +secret ZAI_WORK_API_KEY

nushell/login.nu

Modified
1 1 use prompt.nu
2 2 use sy.nu
3 +use wezterm_integration.nu
3 4 use md.nu
4 5 use todo.nu
5 6 use ssh.nu *
26 27 source ($nu.default-config-dir | path join 'aliases.nu')
27 28 source ($nu.default-config-dir | path join 'secrets.nu')
28 29 source ($nu.default-config-dir | path join "zoxide.nu")
29 -source ($nu.default-config-dir | path join "carapace.nu")
30 +source ($nu.default-config-dir | path join "modules" "completion.nu")

nushell/modules/completion.nu

Added
new file mode 100644
1 +# Interactive completion setup.
2 +# Carapace is wrapped so empty results fall back to Nushell path completion.
4 +# Helpers expected by some Carapace env-aware completions.
5 +def --env get-env [name: string] { $env | get -o $name }
6 +def --env set-env [name: string, value: any] { load-env { $name: $value } }
7 +def --env unset-env [name: string] { hide-env $name }
9 +let carapace_completer = {|spans: list<string>|
10 + load-env {
11 + CARAPACE_SHELL_BUILTINS: (help commands | where category != "" | get name | each { split row " " | first } | uniq | str join "\n")
12 + CARAPACE_SHELL_FUNCTIONS: (help commands | where category == "" | get name | each { split row " " | first } | uniq | str join "\n")
13 + }
15 + let expanded_alias = (scope aliases | where name == $spans.0 | get -o 0.expansion)
16 + let spans = if $expanded_alias != null {
17 + $spans | skip 1 | prepend ($expanded_alias | split row " " | take 1)
18 + } else {
19 + $spans
20 + }
22 + let result = (do --ignore-errors {
23 + ^carapace $spans.0 nushell ...$spans | from json
24 + })
26 + if ($result | is-empty) {
27 + let current = ($spans | last | default "")
28 + if ($current | str starts-with "-") { [] } else { null }
29 + } else {
30 + $result
31 + }
34 +let external = ($env.config.completions.external? | default {})
35 +$env.config.completions.external = ($external | merge {
36 + enable: true
37 + completer: $carapace_completer
38 +})

nushell/modules/git.nu

Added
new file mode 100644
1 +# Git worktree helpers.
2 +# Layout:
3 +# <root>/.git bare repository
4 +# <root>/<repo>.<branch> worktrees
6 +const WT_REPO_NAME = "wt.repo-name"
7 +const WT_MAIN_BRANCH = "wt.main-branch"
8 +const WT_SOURCE_PATH = "wt.source-path"
10 +# Run git and fail with stderr as Nushell error.
11 +def gitx [args: list<any>, cwd?: path] {
12 + let res = if ($cwd == null) {
13 + ^git ...$args | complete
14 + } else {
15 + ^git -C $cwd ...$args | complete
16 + }
18 + if $res.exit_code != 0 {
19 + let msg = ($res.stderr | str trim)
20 + error make {msg: (if ($msg | is-empty) { $"git failed: git ($args | str join ' ')" } else { $msg })}
21 + }
23 + $res.stdout | str trim
26 +# Run git, return completion record.
27 +def gitc [args: list<any>, cwd?: path] {
28 + if ($cwd == null) {
29 + ^git ...$args | complete
30 + } else {
31 + ^git -C $cwd ...$args | complete
32 + }
35 +# Branch name -> path-safe suffix.
36 +def branch-slug [branch: string] {
37 + $branch
38 + | str replace --all --regex '[^A-Za-z0-9._-]+' '-'
39 + | str trim --char '-'
42 +# URL/path -> repo name.
43 +def repo-name-from [source: string] {
44 + let base = ($source | path basename)
45 + $base | str replace --regex '\.git$' ''
48 +# Current layout record. Fails outside co/wt layout.
49 +def layout [] {
50 + let common = (gitx ["rev-parse" "--path-format=absolute" "--git-common-dir"])
51 + let bare = (gitc ["--git-dir" $common "config" "--bool" "--get" "core.bare"])
53 + if (($bare.stdout | str trim) != "true") {
54 + error make {msg: "not inside co/wt layout: git common dir is not bare"}
55 + }
57 + let root = ($common | path dirname)
58 + let repo_res = (gitc ["--git-dir" $common "config" "--get" $WT_REPO_NAME])
59 + let repo = if $repo_res.exit_code == 0 {
60 + $repo_res.stdout | str trim
61 + } else {
62 + $root | path basename | str replace --regex '\.wt$' ''
63 + }
65 + let main_res = (gitc ["--git-dir" $common "config" "--get" $WT_MAIN_BRANCH])
66 + let main = if $main_res.exit_code == 0 { $main_res.stdout | str trim } else { "main" }
68 + {root: $root, git_dir: $common, repo: $repo, main: $main}
71 +# Computed worktree path for branch.
72 +def wt-path [branch: string] {
73 + let l = (layout)
74 + [$l.root $"($l.repo).(branch-slug $branch)"] | path join
77 +# Parse `git worktree list --porcelain` into records.
78 +def parse-worktree-list [text: string] {
79 + $text
80 + | split row "\n\n"
81 + | where {|block| not (($block | str trim) | is-empty) }
82 + | each {|block|
83 + mut rec = {path: null, head: null, branch: null, detached: false, bare: false, locked: false, lock_reason: null, prunable: false}
85 + for line in ($block | lines) {
86 + if ($line | str starts-with "worktree ") {
87 + $rec = ($rec | upsert path ($line | str replace "worktree " ""))
88 + } else if ($line | str starts-with "HEAD ") {
89 + $rec = ($rec | upsert head ($line | str replace "HEAD " ""))
90 + } else if ($line | str starts-with "branch ") {
91 + let b = ($line | str replace "branch " "" | str replace "refs/heads/" "")
92 + $rec = ($rec | upsert branch $b)
93 + } else if $line == "detached" {
94 + $rec = ($rec | upsert detached true)
95 + } else if $line == "bare" {
96 + $rec = ($rec | upsert bare true)
97 + } else if ($line | str starts-with "locked") {
98 + let reason = ($line | str replace "locked" "" | str trim)
99 + $rec = ($rec | upsert locked true | upsert lock_reason (if ($reason | is-empty) { null } else { $reason }))
100 + } else if ($line | str starts-with "prunable") {
101 + $rec = ($rec | upsert prunable true)
105 + $rec
109 +# Worktree table, no dirty check.
110 +def worktrees-basic [] {
111 + let l = (layout)
112 + parse-worktree-list (gitx ["--git-dir" $l.git_dir "worktree" "list" "--porcelain"])
115 +# Find actual worktree path by branch; fallback to convention path.
116 +def path-for-branch [branch: string] {
117 + let found = (worktrees-basic | where branch == $branch | first)
118 + if ($found == null) { wt-path $branch } else { $found.path }
121 +# Create branch + worktree, or add existing branch.
122 +def create-worktree [branch: string, base: string] {
123 + let l = (layout)
124 + let path = (wt-path $branch)
126 + if ($path | path exists) {
127 + error make {msg: $"path exists: ($path)"}
130 + let exists = ((gitc ["--git-dir" $l.git_dir "show-ref" "--verify" "--quiet" $"refs/heads/($branch)"]).exit_code == 0)
132 + if $exists {
133 + gitx ["--git-dir" $l.git_dir "worktree" "add" $path $branch] | ignore
134 + } else {
135 + gitx ["--git-dir" $l.git_dir "worktree" "add" "-b" $branch $path $base] | ignore
138 + $path
141 +# Current branch, refusing detached HEAD.
142 +def current-branch [] {
143 + let b = (gitx ["rev-parse" "--abbrev-ref" "HEAD"])
144 + if $b == "HEAD" { error make {msg: "detached HEAD is not supported"} }
145 + $b
148 +# Remove worktree, maybe branch, and cd away if removing current worktree.
149 +def --env remove-worktree [branch: string, delete_branch: bool, force: bool] {
150 + let l = (layout)
151 + let target = (path-for-branch $branch | path expand)
152 + let cwd_top = (try { gitx ["rev-parse" "--show-toplevel"] } catch { "" } | path expand)
154 + if $target == $cwd_top {
155 + if $branch == $l.main {
156 + cd $l.root
157 + } else {
158 + let main_path = (path-for-branch $l.main)
159 + if ($main_path | path exists) { cd $main_path } else { cd $l.root }
163 + let remove_args = if $force {
164 + ["--git-dir" $l.git_dir "worktree" "remove" "--force" $target]
165 + } else {
166 + ["--git-dir" $l.git_dir "worktree" "remove" $target]
168 + gitx $remove_args | ignore
170 + if $delete_branch {
171 + let branch_flag = if $force { "-D" } else { "-d" }
172 + gitx ["--git-dir" $l.git_dir "branch" $branch_flag $branch] | ignore
175 + $target
178 +# Create fresh layout from remote/local repo URL/path.
179 +def --env co-fresh [source: string, name?: string, branch?: string, dir?: path] {
180 + let repo = if ($name == null) { repo-name-from $source } else { $name }
181 + let parent = if ($dir == null) { "." } else { $dir }
182 + let root = ([$parent $repo] | path join | path expand)
183 + let git_dir = ([$root ".git"] | path join)
185 + if ($root | path exists) {
186 + error make {msg: $"target exists: ($root)"}
189 + mkdir $root
190 + gitx ["clone" "--bare" $source $git_dir] | ignore
192 + let chosen_branch = if (($branch == null) or ($branch | is-empty)) {
193 + gitx ["--git-dir" $git_dir "symbolic-ref" "--short" "HEAD"]
194 + } else {
195 + $branch
198 + gitx ["--git-dir" $git_dir "config" $WT_REPO_NAME $repo] | ignore
199 + gitx ["--git-dir" $git_dir "config" $WT_MAIN_BRANCH $chosen_branch] | ignore
201 + let worktree = ([$root $"($repo).(branch-slug $chosen_branch)"] | path join)
202 + gitx ["--git-dir" $git_dir "worktree" "add" $worktree $chosen_branch] | ignore
203 + cd $worktree
205 + {root: $root, worktree: $worktree, branch: $chosen_branch}
208 +# Migrate current checkout into sibling .wt layout; original untouched.
209 +def --env co-current [name?: string, branch?: string, plan: bool = false, dirty: string = "refuse"] {
210 + let src = (gitx ["rev-parse" "--show-toplevel"] | path expand)
211 + let src_name = ($src | path basename)
212 + let repo = if ($name == null) { $src_name } else { $name }
213 + let parent = ($src | path dirname)
214 + let root = ([$parent $"($repo).wt"] | path join | path expand)
215 + let git_dir = ([$root ".git"] | path join)
216 + let current = (current-branch)
217 + let chosen_branch = if (($branch == null) or ($branch | is-empty)) { $current } else { $branch }
218 + let target = ([$root $"($repo).(branch-slug $chosen_branch)"] | path join)
219 + let status_before = (gitx ["status" "--porcelain=v1"] $src)
220 + let is_dirty = (not ($status_before | is-empty))
221 + let stash_res = (gitc ["stash" "list"] $src)
222 + let stash_count = if $stash_res.exit_code == 0 { ($stash_res.stdout | lines | length) } else { 0 }
224 + if not ($dirty in ["refuse" "copy"]) {
225 + error make {msg: "--dirty must be one of: refuse, copy"}
228 + let migration = {
229 + mode: "current-checkout"
230 + source: $src
231 + target_root: $root
232 + target_git_dir: $git_dir
233 + target_worktree: $target
234 + repo: $repo
235 + branch: $chosen_branch
236 + dirty: $is_dirty
237 + dirty_mode: $dirty
238 + stashes: $stash_count
239 + destructive: false
242 + if $plan { return $migration }
244 + if ($root | path exists) {
245 + error make {msg: $"target exists: ($root)"}
248 + if $is_dirty and $dirty == "refuse" {
249 + error make {msg: "working tree has changes; rerun with `co . --dirty copy` or commit/stash first"}
252 + if $stash_count > 0 {
253 + print -e $"warning: ($stash_count) stash(es) remain only in original checkout: ($src)"
256 + let tmp = (mktemp -d)
257 + let staged_patch = ([$tmp "staged.patch"] | path join)
258 + let unstaged_patch = ([$tmp "unstaged.patch"] | path join)
260 + if $is_dirty {
261 + ^git -C $src diff --binary --cached | save --force $staged_patch
262 + ^git -C $src diff --binary | save --force $unstaged_patch
265 + mkdir $root
266 + gitx ["clone" "--bare" $src $git_dir] | ignore
267 + gitx ["--git-dir" $git_dir "config" $WT_REPO_NAME $repo] | ignore
268 + gitx ["--git-dir" $git_dir "config" $WT_MAIN_BRANCH $chosen_branch] | ignore
269 + gitx ["--git-dir" $git_dir "config" $WT_SOURCE_PATH $src] | ignore
270 + gitx ["--git-dir" $git_dir "worktree" "add" $target $chosen_branch] | ignore
272 + if $is_dirty {
273 + if (not ((open --raw $staged_patch) | is-empty)) {
274 + gitx ["apply" "--index" $staged_patch] $target | ignore
276 + if (not ((open --raw $unstaged_patch) | is-empty)) {
277 + gitx ["apply" $unstaged_patch] $target | ignore
280 + let rsync = (which rsync | length) > 0
281 + if $rsync {
282 + gitx ["-C" $src "status"] | ignore # cheap sanity: source still repo
283 + ^rsync -a --ignore-existing --exclude .git $"($src)/" $"($target)/" | complete | ignore
284 + } else {
285 + ^cp -a -n $"($src)/." $target | complete | ignore
288 + let status_after = (gitx ["status" "--porcelain=v1"] $target)
289 + if $status_before != $status_after {
290 + error make {msg: $"dirty-copy verification failed; original untouched at ($src), target left for inspection at ($root)"}
294 + rm -rf $tmp
295 + cd $target
297 + $migration
300 +# Bootstrap checkout.
301 +export def --env co [
302 + source: string = "." # URL/path, or `.` to migrate current checkout
303 + name?: string # repo/root name
304 + --branch (-b): string = "" # branch to check out; default remote/current HEAD
305 + --dir (-d): path = "." # parent dir for fresh checkout
306 + --plan # with `co .`: preview only
307 + --dirty: string = "refuse" # `refuse` | `copy`
308 +] {
309 + if $source == "." {
310 + co-current $name $branch $plan $dirty
311 + } else {
312 + if $plan { error make {msg: "--plan only applies to `co .`"} }
313 + if $dirty != "refuse" { error make {msg: "--dirty only applies to `co .`"} }
314 + co-fresh $source $name $branch $dir
318 +# Summary.
319 +export def wt [] { wt ls }
321 +export def "wt root" [] { (layout).root }
322 +export def "wt repo" [] { (layout).repo }
323 +export def "wt path" [branch: string] { wt-path $branch }
325 +export def "wt ls" [] {
326 + let cwd_top = (try { gitx ["rev-parse" "--show-toplevel"] } catch { "" } | path expand)
328 + worktrees-basic | where bare == false | each {|row|
329 + let p = ($row.path | path expand)
330 + let dirty = if (($p | path exists) and (not $row.bare) and ($row.branch != null)) {
331 + not ((gitx ["status" "--porcelain=v1"] $p) | is-empty)
332 + } else {
333 + false
336 + $row
337 + | upsert current ($p == $cwd_top)
338 + | upsert dirty $dirty
342 +export def --env "wt new" [
343 + branch: string
344 + --base (-b): string = "HEAD"
345 + --switch (-s)
346 +] {
347 + let p = (create-worktree $branch $base)
348 + if $switch { cd $p }
349 + $p
352 +export def --env "wt go" [
353 + branch: string
354 + --create (-c)
355 + --base (-b): string = "HEAD"
356 +] {
357 + let p = (path-for-branch $branch)
358 + if (not ($p | path exists)) {
359 + if $create {
360 + create-worktree $branch $base | ignore
361 + } else {
362 + error make {msg: $"no worktree for branch `($branch)`; rerun with --create"}
365 + cd $p
366 + $p
369 +export def --env "wt rm" [
370 + name?: string
371 + --branch (-b) # also delete git branch
372 + --force (-f)
373 +] {
374 + let b = if ($name == null) { current-branch } else { $name }
375 + remove-worktree $b $branch $force
378 +export def --env "wt done" [
379 + branch?: string
380 + --force (-f)
381 +] {
382 + let b = if ($branch == null) { current-branch } else { $branch }
383 + remove-worktree $b true $force
386 +export def "wt prune" [] {
387 + let l = (layout)
388 + gitx ["--git-dir" $l.git_dir "worktree" "prune"] | ignore
391 +export def "wt repair" [] {
392 + let l = (layout)
393 + gitx ["--git-dir" $l.git_dir "worktree" "repair"] | ignore
396 +# Thin native aliases for muscle memory / git parity.
397 +export def --env "wt add" [branch: string, --base (-b): string = "HEAD", --switch (-s)] {
398 + wt new $branch --base $base --switch=$switch
401 +export def "wt list" [] { wt ls }
403 +export def "wt lock" [branch?: string, reason?: string] {
404 + let b = if ($branch == null) { current-branch } else { $branch }
405 + let p = (path-for-branch $b)
406 + let l = (layout)
407 + if ($reason == null) {
408 + gitx ["--git-dir" $l.git_dir "worktree" "lock" $p] | ignore
409 + } else {
410 + gitx ["--git-dir" $l.git_dir "worktree" "lock" "--reason" $reason $p] | ignore
414 +export def "wt unlock" [branch?: string] {
415 + let b = if ($branch == null) { current-branch } else { $branch }
416 + let p = (path-for-branch $b)
417 + let l = (layout)
418 + gitx ["--git-dir" $l.git_dir "worktree" "unlock" $p] | ignore
421 +export def "wt move" [branch: string, dest: path] {
422 + let p = (path-for-branch $branch)
423 + let l = (layout)
424 + gitx ["--git-dir" $l.git_dir "worktree" "move" $p $dest] | ignore
425 + $dest
428 +export def --env "wt remove" [name?: string, --branch (-b), --force (-f)] {
429 + wt rm $name --branch=$branch --force=$force

nushell/modules/zai.nu

Modified
1 -# Uses the Z.AI REST API to show current usage of the Coding Plan.
2 -# Needs the ZAI_USAGE_API_KEY environment variable.
1 +# Z.AI API usage module.
2 +# Requires ZAI_USAGE_API_KEY env var.
4 +# Main entry point - show usage summary
5 +export def main [] { usage }
7 +# Show usage summary
3 8 export def usage [] {
4 - let token = $env | get --optional ZAI_USAGE_API_KEY
5 - if ($token | is-empty) {
6 - error make {
7 - msg: "Token for Z.AI missing in environment"
8 - label: {
9 - text: $"Set ZAI_USAGE_API_KEY in your secrets.nuon file"
10 - }
11 - }
12 - }
13 - let headers = {
14 - Authorization: $'Bearer ($token)'
15 - Content-Type: 'application/json'
16 - }
17 - let response = http get --headers $headers 'https://api.z.ai/api/monitor/usage/quota/limit'
9 + let token = $env | get --optional ZAI_USAGE_API_KEY | if ($in | is-empty) { null } else { $in }
10 + if $token == null { error make { msg: "Missing ZAI_USAGE_API_KEY", label: { text: "Set in secrets.nuon" } } }
19 - if ($response.code) != 200 {
20 - error make {
21 - msg: $response.msg
22 - label: {
23 - text: $"Z.AI API error — check ZAI_USAGE_API_KEY"
24 - }
25 - }
12 + let res = try { http get --headers { Authorization: $'Bearer ($token)', Content-Type: application/json } https://api.z.ai/api/monitor/usage/quota/limit } catch { |_| error make { msg: "API error", label: { text: "check ZAI_USAGE_API_KEY" } } }
14 + let name = { 3: "5 Hours", 5: "Monthly", 6: "Weekly" }
16 + let limits = $res.data.limits | each {|r|
17 + let ts = $r | get --optional nextResetTime | default null
18 + { kind: $r.type, period: ($name | get --optional ($r.unit | into string) | default $r.unit), pct: ($r | get --optional percentage | default 0), current: ($r | get --optional currentValue | default null), usage: ($r | get --optional usage | default null), resets: (if $ts != null { $ts / 1000 | math round | into int | into string | into datetime -f "%s" | format date "%Y-%m-%d" } else { null }) }
28 - let unit_label = { 3: daily, 5: weekly, 6: monthly }
21 + let details = $res.data.limits | each {|r| $r | get --optional usageDetails } | compact | flatten | each {|d| {model: $d.modelCode, usage: $d.usage}}
30 - $response.data.limits
31 - | each { |row|
32 - let period_key = ($row.unit | into string)
33 - let period = ($unit_label | get -o $period_key | default $row.unit)
34 - let used_opt = ($row | get --optional usage)
35 - let used = if ($used_opt | is-empty) { $row.number } else { $used_opt }
36 - let reset = ($row.nextResetTime // 1000 | into datetime --timezone u --format '%s')
37 - {
38 - type: $row.type
39 - period: $period
40 - used: $used
41 - total: $row.number
42 - pct: $row.percentage
43 - resets: $reset
44 - }
23 + show $res.data.level $limits $details
26 +# Return raw limits table
27 +export def "usage limits" [] {
28 + let token = $env | get --optional ZAI_USAGE_API_KEY | if ($in | is-empty) { null } else { $in }
29 + if $token == null { error make { msg: "Missing ZAI_USAGE_API_KEY", label: { text: "Set in secrets.nuon" } } }
31 + let res = try { http get --headers { Authorization: $'Bearer ($token)', Content-Type: application/json } https://api.z.ai/api/monitor/usage/quota/limit } catch { |_| error make { msg: "API error", label: { text: "check ZAI_USAGE_API_KEY" } } }
33 + let name = { 3: "5 Hours", 5: "Monthly", 6: "Weekly" }
35 + $res.data.limits | each {|r|
36 + let ts = $r | get --optional nextResetTime | default null
37 + { kind: $r.type, period: ($name | get --optional ($r.unit | into string) | default $r.unit), pct: ($r | get --optional percentage | default 0), current: ($r | get --optional currentValue | default null), usage: ($r | get --optional usage | default null), resets: (if $ts != null { $ts / 1000 | math round | into int | into string | into datetime -f "%s" | format date "%Y-%m-%d" } else { null }) }
41 +# Return raw details table
42 +export def "usage details" [] {
43 + let token = $env | get --optional ZAI_USAGE_API_KEY | if ($in | is-empty) { null } else { $in }
44 + if $token == null { error make { msg: "Missing ZAI_USAGE_API_KEY", label: { text: "Set in secrets.nuon" } } }
46 + let res = try { http get --headers { Authorization: $'Bearer ($token)', Content-Type: application/json } https://api.z.ai/api/monitor/usage/quota/limit } catch { |_| error make { msg: "API error", label: { text: "check ZAI_USAGE_API_KEY" } } }
48 + $res.data.limits | each {|r| $r | get --optional usageDetails } | compact | flatten | each {|d| {model: $d.modelCode, usage: $d.usage}}
51 +def show [plan: string, limits: table, details: table] {
52 + let c = (ansi c)
53 + let m = (ansi m)
54 + let b = (ansi b)
55 + let d = (ansi d)
56 + let e = (ansi rst)
58 + print $"($c)($plan | str upcase) Plan($e)"
60 + let tokens = $limits | where kind == TOKENS_LIMIT
61 + if $tokens != [] { print ""; print $"($c)Tokens($e) LLM quota"; $tokens | each {|r| show_limit $r $d null } }
63 + let calls = $limits | where kind == TIME_LIMIT
64 + if $calls != [] { print ""; print $"($m)Service Calls($e)"; $calls | each {|r| show_limit $r $d $r.usage } }
66 + if $details != [] { print ""; print $"($b)By Service($e)"; $details | each {|d| print $" ($d.model)($e) ($d.usage)" } }; null
69 +def show_limit [row: record, dim: string, total: any] {
70 + let bar = bar $row.pct
71 + let used = if $total != null { $" ($row.current)/($total)" } else { "" }
72 + let resets = if $row.resets != null { $" ($dim)resets ($row.resets)($dim)" } else { "" }
73 + print $" ($bar) ($dim)($row.period)($used)($resets)"
76 +def bar [pct: int] {
77 + let n = ($pct / 10 | math round | into int | if $in > 10 { 10 } else { if $in < 0 { 0 } else { $in } })
78 + let g = (ansi g)
79 + let d = (ansi d)
80 + let y = (ansi y)
81 + let r = (ansi r)
82 + let e = (ansi rst)
83 + let color = if $pct < 50 { $g } else if $pct < 80 { $y } else { $r }
84 + let filled = 1..$n | each { $"($g)▓" } | str join
85 + let empty = 1..(10 - $n) | each { $"($d)░" } | str join
86 + $"($filled)($empty)($e) ($color)($pct)%($e)"

nushell/wezterm_integration.nu

Added
new file mode 100644
1 +# WezTerm Shell Integration for Nushell
2 +# =====================================
3 +# Emits OSC 1337 (user vars) and OSC 7 (cwd) so wezterm can:
4 +# - Track the running command via WEZTERM_PROG
5 +# - Know the current working directory (new tabs spawn in the right place)
6 +# - Surface arbitrary data from nushell into the wezterm status bar
7 +#
8 +# OSC 133 (prompt zones) is NOT enabled — nushell's implementation
9 +# has known bugs with wezterm (scrolling on keypress).
10 +# See: https://github.com/wezterm/wezterm/discussions/5859
12 +# To install: add `use wezterm_integration.nu` to your config.nu
14 +# ---------------------------------------------------------------------------
15 +# Core: set a user var via OSC 1337
16 +# ---------------------------------------------------------------------------
17 +# Values must be base64-encoded. The BEL (\x07) terminates the sequence.
18 +# Mirrors __wezterm_set_user_var() from the bash/zsh wezterm.sh integration.
19 +export-env {
20 + def __wezterm_set_user_var [name: string, value: string] {
21 + let b64 = ($value | encode base64)
22 + let osc = (ansi --osc $"1337;SetUserVar=($name)=($b64)=")
23 + print -n ($osc + (char bel))
24 + }
26 + # Emit OSC 7 so wezterm knows the current working directory.
27 + # New tabs opened from this pane will use this as their cwd.
28 + def __wezterm_osc7 [] {
29 + let hostname = (hostname)
30 + let cwd = ($env.PWD | str replace --all '\\' '/')
31 + let osc = (ansi --osc $"7;file://($hostname)($cwd)")
32 + print -n ($osc + (char bel))
33 + }
35 + # -------------------------------------------------------------------------
36 + # pre_execution hook: tell wezterm what command is running
37 + # -------------------------------------------------------------------------
38 + # Fires just before each command executes. Sets WEZTERM_PROG so wezterm
39 + # knows what is happening in the pane. Cleared in pre_prompt after completion.
40 + $env.config.hooks.pre_execution = (
41 + $env.config.hooks.pre_execution
42 + | default []
43 + | append {
44 + condition: { true }
45 + code: {
46 + let cmd = (commandline)
47 + __wezterm_set_user_var "WEZTERM_PROG" $cmd
48 + }
49 + }
50 + )
52 + # -------------------------------------------------------------------------
53 + # pre_prompt hook: clean up and update cwd
54 + # -------------------------------------------------------------------------
55 + # Fires after every command completes, before the next prompt is shown.
56 + # Clears WEZTERM_PROG (shell is idle) and emits OSC 7 for the cwd.
57 + $env.config.hooks.pre_prompt = (
58 + $env.config.hooks.pre_prompt
59 + | default []
60 + | append {
61 + condition: { true }
62 + code: {
63 + __wezterm_set_user_var "WEZTERM_PROG" ""
64 + __wezterm_osc7
65 + }
66 + }
67 + )
69 + # -------------------------------------------------------------------------
70 + # env_change.PWD hook: update cwd on cd
71 + # -------------------------------------------------------------------------
72 + # Fires when $PWD changes (e.g. via `cd`, `z`, nushell's block cd).
73 + # Refreshes OSC 7 so wezterm always knows the current directory.
74 + let current_pwd_hooks = ($env.config.hooks.env_change | get --optional PWD | default [])
75 + $env.config.hooks.env_change = ($env.config.hooks.env_change | merge {
76 + PWD: ($current_pwd_hooks | append {
77 + condition: { true }
78 + code: { __wezterm_osc7 }
79 + })
80 + })

rbw/config.json

Added
new file mode 100644
1 +{
2 + "email":"oliver@bugabinga.net",
3 + "sso_id":null,
4 + "base_url":null,
5 + "identity_url":null,
6 + "ui_url":null,
7 + "notifications_url":null,
8 + "lock_timeout":10800,
9 + "sync_interval":3600,
10 + "pinentry":"pinentry-curses",
11 + "client_cert_path":null