Skip to content

Commit 92d0143

Browse files
committed
Generalize Nx shell tooling and harden templates
1 parent baff678 commit 92d0143

File tree

11 files changed

+171
-39
lines changed

11 files changed

+171
-39
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ Run <code>zsh-check-deps</code> to verify required tools (starship, fzf) and opt
203203
│ │ ├── 20-plugins.zsh # antidote + starship init
204204
│ │ ├── 30-completion.zsh # fzf-tab, bookmarks
205205
│ │ ├── 40-tools.zsh # mise activation, fzf, zoxide
206-
│ │ ├── 50-functions.zsh.tmpl # yazi, nx wrapper
206+
│ │ ├── 50-functions.zsh.tmpl # yazi, workspace-aware nx wrapper
207207
│ │ ├── 70-keybindings.zsh # Ctrl+y, arrow keys
208208
│ │ └── 99-local.zsh.tmpl # machine-specific
209209
│ ├── zed/settings.json.tmpl # zed editor (biome, catppuccin)

dot_attio.gitconfig.tmpl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
{{- $gpgKeyWorkEmail := get . "gpgKeyWorkEmail" -}}
12
[user]
23
name = {{ .gitName }}
34
email = {{ .workEmail }}
4-
{{- if ne .gpgKeyWorkEmail "" }}
5-
signingkey = {{ .gpgKeyWorkEmail }}
5+
{{- if ne $gpgKeyWorkEmail "" }}
6+
signingkey = {{ $gpgKeyWorkEmail }}
67
{{- end }}

dot_config/fish/completions/nx.fish

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,17 @@
33
# =============================================================================
44

55
function __braden_nx_completion_enabled
6-
set -l phoenix_root "$HOME/Development/Phoenix"
7-
test -x "$phoenix_root/node_modules/.bin/nx"
6+
set -l workspace_root (__braden_nx_workspace_root)
7+
test -n "$workspace_root"; or return 1
8+
__braden_nx_local_bin "$workspace_root" >/dev/null
89
end
910

1011
function __braden_nx_cache_dir
11-
echo "$HOME/.cache/fish/nx"
12+
set -l workspace_root (__braden_nx_workspace_root)
13+
or return 1
14+
15+
set -l workspace_key (string replace -ar '[^A-Za-z0-9._-]' '_' -- "$workspace_root")
16+
echo "$HOME/.cache/fish/nx/$workspace_key"
1217
end
1318

1419
function __braden_nx_cache_is_fresh --argument-names file_path
@@ -24,6 +29,9 @@ end
2429
function __braden_nx_refresh_completion_cache
2530
__braden_nx_completion_enabled; or return 1
2631

32+
set -l workspace_root (__braden_nx_workspace_root)
33+
or return 1
34+
2735
set -l cache_dir (__braden_nx_cache_dir)
2836
set -l projects_file "$cache_dir/projects.txt"
2937
set -l targets_file "$cache_dir/targets.txt"
@@ -35,7 +43,6 @@ function __braden_nx_refresh_completion_cache
3543
return 0
3644
end
3745

38-
set -l phoenix_root "$HOME/Development/Phoenix"
3946
set -l helper_script "$HOME/.config/fish/completions/_braden_nx_workspace.js"
4047

4148
mkdir -p "$cache_dir"
@@ -45,11 +52,15 @@ function __braden_nx_refresh_completion_cache
4552
set -l temp_targets (mktemp)
4653
set -l temp_mapping (mktemp)
4754

48-
env PATH="$PATH" HOME="$HOME" bash -c '
49-
cd "$1" || exit 1
50-
shift
51-
node "$@"
52-
' bash "$phoenix_root" "$helper_script" >"$temp_json" 2>/dev/null
55+
if command -q mise
56+
env PATH="$PATH" HOME="$HOME" mise exec -C "$workspace_root" -- node "$helper_script" >"$temp_json" 2>/dev/null
57+
else
58+
env PATH="$PATH" HOME="$HOME" bash -c '
59+
cd "$1" || exit 1
60+
shift
61+
node "$@"
62+
' bash "$workspace_root" "$helper_script" >"$temp_json" 2>/dev/null
63+
end
5364
or begin
5465
rm -f "$temp_json" "$temp_projects" "$temp_targets" "$temp_mapping"
5566
return 1

dot_config/fish/conf.d/30-abbr.fish

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,5 @@
33
# =============================================================================
44

55
# Approximate zsh named-directory shortcuts in fish.
6-
abbr --add --position anywhere -- '~dev' ~/Developer
76
abbr --add --position anywhere -- '~dl' ~/Downloads
87
abbr --add --position anywhere -- '~cfg' ~/.config

dot_config/fish/conf.d/50-functions.fish.tmpl

Lines changed: 72 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -123,23 +123,88 @@ function yazi_cd
123123
commandline -f repaint
124124
end
125125

126+
function __braden_nx_is_workspace_root --argument-names dir
127+
test -n "$dir"; or return 1
128+
test -f "$dir/nx.json"; and return 0
129+
test -x "$dir/node_modules/.bin/nx"
130+
end
131+
132+
function __braden_nx_find_workspace_root --argument-names start_dir
133+
test -n "$start_dir"; or return 1
134+
135+
set -l dir (path resolve "$start_dir" 2>/dev/null)
136+
or set dir "$start_dir"
137+
138+
while true
139+
if __braden_nx_is_workspace_root "$dir"
140+
echo "$dir"
141+
return 0
142+
end
143+
144+
if test "$dir" = "/"
145+
return 1
146+
end
147+
148+
set dir (path dirname "$dir")
149+
end
150+
end
151+
152+
function __braden_nx_workspace_root
153+
set -l workspace_root (__braden_nx_find_workspace_root "$PWD")
154+
if test -n "$workspace_root"
155+
echo "$workspace_root"
156+
return 0
157+
end
158+
159+
if set -q BRADEN_NX_DEFAULT_WORKSPACE
160+
set -l default_workspace (path resolve "$BRADEN_NX_DEFAULT_WORKSPACE" 2>/dev/null)
161+
or set default_workspace "$BRADEN_NX_DEFAULT_WORKSPACE"
162+
163+
if __braden_nx_is_workspace_root "$default_workspace"
164+
echo "$default_workspace"
165+
return 0
166+
end
167+
end
168+
169+
return 1
170+
end
171+
172+
function __braden_nx_local_bin --argument-names workspace_root
173+
test -n "$workspace_root"; or return 1
174+
175+
set -l nx_bin "$workspace_root/node_modules/.bin/nx"
176+
test -x "$nx_bin"; or return 1
177+
178+
echo "$nx_bin"
179+
end
180+
126181
function nx
127-
set -l phoenix_root "{{ .chezmoi.homeDir }}/Development/Phoenix"
128-
set -l nx_bin "$phoenix_root/node_modules/.bin/nx"
182+
set -l workspace_root (__braden_nx_workspace_root)
183+
184+
if test -z "$workspace_root"
185+
if command -q nx
186+
command nx $argv
187+
return $status
188+
end
189+
190+
echo "No Nx workspace found from $PWD. Set BRADEN_NX_DEFAULT_WORKSPACE to enable nx outside a repo." >&2
191+
return 1
192+
end
129193

130-
if not test -x "$nx_bin"
131-
echo "nx is not available at $nx_bin" >&2
194+
set -l nx_bin (__braden_nx_local_bin "$workspace_root")
195+
if test -z "$nx_bin"
196+
echo "nx is not available at $workspace_root/node_modules/.bin/nx" >&2
132197
return 1
133198
end
134199

135-
if string match -q -- "$phoenix_root*" "$PWD"
136-
"$nx_bin" $argv
200+
if command -q mise
201+
mise exec -C "$workspace_root" -- "$nx_bin" $argv
137202
else
138203
env PATH="$PATH" HOME="$HOME" bash -c '
139204
cd "$1" || exit 1
140205
shift
141206
"$@"
142-
' bash "$phoenix_root" "$nx_bin" $argv
207+
' bash "$workspace_root" "$nx_bin" $argv
143208
end
144209
end
145210

dot_config/fish/conf.d/99-local.fish.tmpl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
# To enable 1Password integration, uncomment and adjust the op:// URI below.
77
# Requires `op` CLI to be installed and configured.
88
# set -gx NGROK_AUTHTOKEN (op read 'op://Private/ngrok/credential' --account {{ .onePasswordAccount }})
9+
# Optional: set a default Nx workspace if you want `nx` to work outside a repo.
10+
# set -gx BRADEN_NX_DEFAULT_WORKSPACE "$HOME/Development/Phoenix"
911

1012
if status is-interactive
1113
if set -q __BRADEN_SHELL_START_REAL

dot_config/zsh/30-completion.zsh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ zstyle ':plugin:ez-compinit' 'compstyle' 'ohmy'
1616
# FZF-tab preview for cd
1717
zstyle ':fzf-tab:complete:cd:*' fzf-preview 'eza -Gax --icons=always --group-directories-first --git'
1818

19-
# Directory bookmarks (usage: cd ~dev, cd ~dl, cd ~cfg)
20-
hash -d dev=~/Developer
19+
# Directory bookmarks (usage: cd ~dl, cd ~cfg)
2120
hash -d dl=~/Downloads
2221
hash -d cfg=~/.config

dot_config/zsh/50-functions.zsh.tmpl

Lines changed: 61 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,21 +36,73 @@ zle -N yazi_cd
3636
# Dependency check (run manually with: zsh-check-deps)
3737
# -----------------------------------------------------------------------------
3838
# -----------------------------------------------------------------------------
39-
# Phoenix repo nx wrapper
39+
# Nx workspace wrapper
4040
# -----------------------------------------------------------------------------
41+
__braden_nx_is_workspace_root() {
42+
[[ -n "$1" ]] || return 1
43+
[[ -f "$1/nx.json" || -x "$1/node_modules/.bin/nx" ]]
44+
}
45+
46+
__braden_nx_find_workspace_root() {
47+
local dir="${1:A}"
48+
49+
while true; do
50+
if __braden_nx_is_workspace_root "$dir"; then
51+
print -r -- "$dir"
52+
return 0
53+
fi
54+
55+
[[ "$dir" == "/" ]] && return 1
56+
dir="${dir:h}"
57+
done
58+
}
59+
60+
__braden_nx_workspace_root() {
61+
local workspace_root
62+
63+
workspace_root="$(__braden_nx_find_workspace_root "$PWD")" && {
64+
print -r -- "$workspace_root"
65+
return 0
66+
}
67+
68+
if [[ -n "${BRADEN_NX_DEFAULT_WORKSPACE:-}" ]] && __braden_nx_is_workspace_root "$BRADEN_NX_DEFAULT_WORKSPACE"; then
69+
print -r -- "${BRADEN_NX_DEFAULT_WORKSPACE:A}"
70+
return 0
71+
fi
72+
73+
return 1
74+
}
75+
76+
__braden_nx_local_bin() {
77+
local workspace_root="$1"
78+
local nx_bin="$workspace_root/node_modules/.bin/nx"
79+
80+
[[ -x "$nx_bin" ]] || return 1
81+
print -r -- "$nx_bin"
82+
}
83+
4184
nx() {
42-
local phoenix_root="{{ .chezmoi.homeDir }}/Development/Phoenix"
43-
local nx_bin="$phoenix_root/node_modules/.bin/nx"
85+
local workspace_root nx_bin
4486

45-
if [[ ! -x "$nx_bin" ]]; then
46-
echo "nx is not available at $nx_bin" >&2
87+
workspace_root="$(__braden_nx_workspace_root)" || {
88+
if (( $+commands[nx] )); then
89+
command nx "$@"
90+
return
91+
fi
92+
93+
echo "No Nx workspace found from $PWD. Set BRADEN_NX_DEFAULT_WORKSPACE to enable nx outside a repo." >&2
4794
return 1
48-
fi
95+
}
96+
97+
nx_bin="$(__braden_nx_local_bin "$workspace_root")" || {
98+
echo "nx is not available at $workspace_root/node_modules/.bin/nx" >&2
99+
return 1
100+
}
49101

50-
if [[ "$PWD" == "$phoenix_root"* ]]; then
51-
"$nx_bin" "$@"
102+
if (( $+commands[mise] )); then
103+
mise exec -C "$workspace_root" -- "$nx_bin" "$@"
52104
else
53-
(cd "$phoenix_root" && "$nx_bin" "$@")
105+
(cd "$workspace_root" && "$nx_bin" "$@")
54106
fi
55107
}
56108

dot_config/zsh/99-local.zsh.tmpl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ fi
1515
# To enable 1Password integration, uncomment and adjust the op:// URIs below.
1616
# Requires `op` CLI to be installed and configured.
1717
# export NGROK_AUTHTOKEN="$(op read 'op://Private/ngrok/credential' --account {{ .onePasswordAccount }})"
18+
# Optional: set a default Nx workspace if you want `nx` to work outside a repo.
19+
# export BRADEN_NX_DEFAULT_WORKSPACE="$HOME/Development/Phoenix"
1820

1921
# Safe-chain initialization
2022
[[ -f ~/.safe-chain/scripts/init-posix.sh ]] && source ~/.safe-chain/scripts/init-posix.sh

dot_gitconfig.tmpl

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{{- $gpgKeyPersonalEmail := get . "gpgKeyPersonalEmail" -}}
12
[alias]
23
shit = commit --amend --no-edit
34
fuck = "!f(){ git shit && git push -f; };f"
@@ -10,8 +11,8 @@
1011
[user]
1112
name = {{ .gitName }}
1213
email = {{ .personalEmail }}
13-
{{- if ne .gpgKeyPersonalEmail "" }}
14-
signingkey = {{ .gpgKeyPersonalEmail }}
14+
{{- if ne $gpgKeyPersonalEmail "" }}
15+
signingkey = {{ $gpgKeyPersonalEmail }}
1516
{{- end }}
1617
{{ if eq .machineType "work" -}}
1718
[includeIf "gitdir:~/Development/Phoenix/"]
@@ -23,7 +24,7 @@
2324
defaultBranch = master
2425
[push]
2526
default = current
26-
{{- if ne .gpgKeyPersonalEmail "" }}
27+
{{- if ne $gpgKeyPersonalEmail "" }}
2728
[commit]
2829
gpgsign = true
2930
[gpg]

0 commit comments

Comments
 (0)