Skip to content

Commit 0bead52

Browse files
authored
[Bug] Fix bash regression for PATH (#207)
## Summary Fixing zsh shell regression as the following: ``` bash: command substitution: line 37: syntax error near unexpected token `newline' bash: command substitution: line 37: ` $NIX_STORE/*' ``` Closes #196 Closes #186 ## How was it tested? devbox shell go test ./...
1 parent e9a38d2 commit 0bead52

File tree

5 files changed

+5
-141
lines changed

5 files changed

+5
-141
lines changed

nix/shell_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func TestWriteDevboxShellrc(t *testing.T) {
5252
userShellrcPath: test.shellrcPath,
5353
UserInitHook: test.hook,
5454
planInitHook: `echo "Welcome to the devbox!"`,
55-
profileDir: "./devbox/profile",
55+
profileDir: "./.devbox/profile",
5656
}
5757
gotPath, err := s.writeDevboxShellrc()
5858
if err != nil {

nix/shellrc.tmpl

Lines changed: 1 addition & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -28,41 +28,7 @@ content readable.
2828

2929
# Begin Devbox Post-init Hook
3030

31-
# TODO: this can likely be simplified, because we no longer expect any NIX_STORE paths.
32-
# These are replaced by having the NixProfilePath. However, refactoring
33-
# this is a bit risky due to the diff behavior of various shells, so not doing just yet.
34-
#
35-
# We need to do some processing on the PATH to ensure that any NIX_STORE paths
36-
# stay at the front.
37-
#
38-
# Use IFS to split the PATH by ':' and then loop over each directory. Do the
39-
# splitting in a subshell so that the change to IFS is temporary.
40-
#
41-
# The first case pattern matches a path that has the Nix store as a prefix, in
42-
# which case we append it to nix_path. The second case pattern matches
43-
# everything else and appends to non_nix_path. At the end, we join them with
44-
# nix_path at the front.
45-
#
46-
# Some notes:
47-
# - We do `for ... in $(echo $PATH)` instead of `for ... in $PATH` because
48-
# zsh doesn't do word splitting on unquoted variables.
49-
# - The syntax `${nix_path:+$nix_path:}` means, "if nix_path is already
50-
# set, write `$nix_path:` (with the colon) instead." This ensures we
51-
# don't start with a colon on the first append.
52-
# - You can't have comments in a subshell, hence this one long comment at
53-
# the top.
54-
# - Keep this as POSIX as possible to maximize compatibility with
55-
# different shells.
56-
PATH="$(
57-
IFS=:
58-
for path_dir in $(echo "$PATH"); do
59-
case "$path_dir" in
60-
$NIX_STORE/*) nix_path="${nix_path:+$nix_path:}${path_dir}" ;;
61-
*) non_nix_path="${non_nix_path:+$non_nix_path:}${path_dir}" ;;
62-
esac
63-
done
64-
echo "{{ .ProfileBinDir }}:${non_nix_path}"
65-
)"
31+
PATH="{{ .ProfileBinDir }}:$PATH"
6632

6733
{{- if .HistoryFile }}
6834
HISTFILE={{.HistoryFile}}

nix/testdata/shellrc/basic/shellrc.golden

Lines changed: 1 addition & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -42,41 +42,7 @@ zstyle ':completion:*:kill:*' command 'ps -u $USER -o pid,%cpu,tty,cputime,cmd'
4242

4343
# Begin Devbox Post-init Hook
4444

45-
# TODO: this can likely be simplified, because we no longer expect any NIX_STORE paths.
46-
# These are replaced by having the NixProfilePath. However, refactoring
47-
# this is a bit risky due to the diff behavior of various shells, so not doing just yet.
48-
#
49-
# We need to do some processing on the PATH to ensure that any NIX_STORE paths
50-
# stay at the front.
51-
#
52-
# Use IFS to split the PATH by ':' and then loop over each directory. Do the
53-
# splitting in a subshell so that the change to IFS is temporary.
54-
#
55-
# The first case pattern matches a path that has the Nix store as a prefix, in
56-
# which case we append it to nix_path. The second case pattern matches
57-
# everything else and appends to non_nix_path. At the end, we join them with
58-
# nix_path at the front.
59-
#
60-
# Some notes:
61-
# - We do `for ... in $(echo $PATH)` instead of `for ... in $PATH` because
62-
# zsh doesn't do word splitting on unquoted variables.
63-
# - The syntax `${nix_path:+$nix_path:}` means, "if nix_path is already
64-
# set, write `$nix_path:` (with the colon) instead." This ensures we
65-
# don't start with a colon on the first append.
66-
# - You can't have comments in a subshell, hence this one long comment at
67-
# the top.
68-
# - Keep this as POSIX as possible to maximize compatibility with
69-
# different shells.
70-
PATH="$(
71-
IFS=:
72-
for path_dir in $(echo "$PATH"); do
73-
case "$path_dir" in
74-
$NIX_STORE/*) nix_path="${nix_path:+$nix_path:}${path_dir}" ;;
75-
*) non_nix_path="${non_nix_path:+$non_nix_path:}${path_dir}" ;;
76-
esac
77-
done
78-
echo "./devbox/profile/bin:${non_nix_path}"
79-
)"
45+
PATH="./.devbox/profile/bin:$PATH"
8046

8147
# Prepend to the prompt to make it clear we're in a devbox shell.
8248
export PS1="(devbox) $PS1"

nix/testdata/shellrc/nohook/shellrc.golden

Lines changed: 1 addition & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -42,41 +42,7 @@ zstyle ':completion:*:kill:*' command 'ps -u $USER -o pid,%cpu,tty,cputime,cmd'
4242

4343
# Begin Devbox Post-init Hook
4444

45-
# TODO: this can likely be simplified, because we no longer expect any NIX_STORE paths.
46-
# These are replaced by having the NixProfilePath. However, refactoring
47-
# this is a bit risky due to the diff behavior of various shells, so not doing just yet.
48-
#
49-
# We need to do some processing on the PATH to ensure that any NIX_STORE paths
50-
# stay at the front.
51-
#
52-
# Use IFS to split the PATH by ':' and then loop over each directory. Do the
53-
# splitting in a subshell so that the change to IFS is temporary.
54-
#
55-
# The first case pattern matches a path that has the Nix store as a prefix, in
56-
# which case we append it to nix_path. The second case pattern matches
57-
# everything else and appends to non_nix_path. At the end, we join them with
58-
# nix_path at the front.
59-
#
60-
# Some notes:
61-
# - We do `for ... in $(echo $PATH)` instead of `for ... in $PATH` because
62-
# zsh doesn't do word splitting on unquoted variables.
63-
# - The syntax `${nix_path:+$nix_path:}` means, "if nix_path is already
64-
# set, write `$nix_path:` (with the colon) instead." This ensures we
65-
# don't start with a colon on the first append.
66-
# - You can't have comments in a subshell, hence this one long comment at
67-
# the top.
68-
# - Keep this as POSIX as possible to maximize compatibility with
69-
# different shells.
70-
PATH="$(
71-
IFS=:
72-
for path_dir in $(echo "$PATH"); do
73-
case "$path_dir" in
74-
$NIX_STORE/*) nix_path="${nix_path:+$nix_path:}${path_dir}" ;;
75-
*) non_nix_path="${non_nix_path:+$non_nix_path:}${path_dir}" ;;
76-
esac
77-
done
78-
echo "./devbox/profile/bin:${non_nix_path}"
79-
)"
45+
PATH="./.devbox/profile/bin:$PATH"
8046

8147
# Prepend to the prompt to make it clear we're in a devbox shell.
8248
export PS1="(devbox) $PS1"

nix/testdata/shellrc/noshellrc/shellrc.golden

Lines changed: 1 addition & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,6 @@
11
# Begin Devbox Post-init Hook
22

3-
# TODO: this can likely be simplified, because we no longer expect any NIX_STORE paths.
4-
# These are replaced by having the NixProfilePath. However, refactoring
5-
# this is a bit risky due to the diff behavior of various shells, so not doing just yet.
6-
#
7-
# We need to do some processing on the PATH to ensure that any NIX_STORE paths
8-
# stay at the front.
9-
#
10-
# Use IFS to split the PATH by ':' and then loop over each directory. Do the
11-
# splitting in a subshell so that the change to IFS is temporary.
12-
#
13-
# The first case pattern matches a path that has the Nix store as a prefix, in
14-
# which case we append it to nix_path. The second case pattern matches
15-
# everything else and appends to non_nix_path. At the end, we join them with
16-
# nix_path at the front.
17-
#
18-
# Some notes:
19-
# - We do `for ... in $(echo $PATH)` instead of `for ... in $PATH` because
20-
# zsh doesn't do word splitting on unquoted variables.
21-
# - The syntax `${nix_path:+$nix_path:}` means, "if nix_path is already
22-
# set, write `$nix_path:` (with the colon) instead." This ensures we
23-
# don't start with a colon on the first append.
24-
# - You can't have comments in a subshell, hence this one long comment at
25-
# the top.
26-
# - Keep this as POSIX as possible to maximize compatibility with
27-
# different shells.
28-
PATH="$(
29-
IFS=:
30-
for path_dir in $(echo "$PATH"); do
31-
case "$path_dir" in
32-
$NIX_STORE/*) nix_path="${nix_path:+$nix_path:}${path_dir}" ;;
33-
*) non_nix_path="${non_nix_path:+$non_nix_path:}${path_dir}" ;;
34-
esac
35-
done
36-
echo "./devbox/profile/bin:${non_nix_path}"
37-
)"
3+
PATH="./.devbox/profile/bin:$PATH"
384

395
# Prepend to the prompt to make it clear we're in a devbox shell.
406
export PS1="(devbox) $PS1"

0 commit comments

Comments
 (0)