Skip to content

Commit 11bb6f0

Browse files
authored
[fish] Fix fish init hook (#1711)
## Summary Fixes an issue with #1709 Also, adds a `FISH_VERSION` check which seems more reliable? (See fish-shell/fish-shell#374) I think longer term it may be better to generate different init hooks (e.g. `.hooks.fish`) instead. ## How was it tested? ``` SHELL=fish devbox shell refresh ```
1 parent 2ce087f commit 11bb6f0

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

internal/devbox/shell.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,5 +402,6 @@ func filterPathList(pathList string, keep func(string) bool) string {
402402
}
403403

404404
func isFishShell() bool {
405-
return filepath.Base(os.Getenv("SHELL")) == "fish"
405+
return filepath.Base(os.Getenv("SHELL")) == "fish" ||
406+
os.Getenv("FISH_VERSION") != ""
406407
}

internal/shellgen/scripts.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,8 @@ func writeInitHookFile(devbox devboxer, body string) (err error) {
108108
"InitHookHash": "__DEVBOX_INIT_HOOK_" + devbox.ProjectDirHash(),
109109
// TODO put IsFish() in common place so we can call here and in devbox package
110110
// without adding more stuff to interface
111-
"IsFish": filepath.Base(os.Getenv("SHELL")) == "fish",
111+
"IsFish": filepath.Base(os.Getenv("SHELL")) == "fish" ||
112+
os.Getenv("FISH_VERSION") != "",
112113
})
113114
}
114115

internal/shellgen/tmpl/init-hook.tmpl

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,22 @@
11

22
{{/* if hash is set, we're in recursive loop, just exit */ -}}
3+
4+
{{ if .IsFish }}
5+
if set -q {{ .InitHookHash }}; then
6+
return
7+
end
8+
{{ else }}
39
if [ -n "${{ .InitHookHash }}" ]; then
410
return
511
fi
12+
{{ end }}
613

714
export {{ .InitHookHash }}=true
815

916
{{ .Body }}
1017

1118
{{ if .IsFish }}
12-
set -e {{ .InitHookHash }}
19+
set -e {{ .InitHookHash }}
1320
{{ else }}
14-
unset {{ .InitHookHash }}
21+
unset {{ .InitHookHash }}
1522
{{ end }}

0 commit comments

Comments
 (0)