@@ -123,23 +123,88 @@ function yazi_cd
123123 commandline -f repaint
124124end
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+
126181function 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
144209end
145210
0 commit comments