[Bug]: syntax error in hooks.sh when using fish
Current Behavior (bug) Since updating to 0.8.6 this morning, I'm now getting:
/Users/jason/workspace/local-ops/.devbox/gen/scripts/.hooks.sh:15: syntax error: unexpected end of file
I'm using Fish as my shell.
This is consistent across all my projects, and has been replicated by my co-worker @jay-aye-see-kay's mac also, though he had to delete his .devbox directory in the project to start seeing the error.
This prevents any commands from starting, for example:
> devbox run setup
/Users/jason/workspace/cultureamp/std-demographics-next/.devbox/gen/scripts/.hooks.sh: line 15: syntax error: unexpected end of file
Error: error running script "setup" in Devbox: exit status 2
Expected Behavior (fix)
There shouldn't be a syntax error when running devbox commands on a fish shell.
Notably, @jay-aye-see-kay pointed out the file is a .sh file with no shebang, but contains fish syntax.
If I run ./devbox/gen/scripts/.hooks.sh I get the error, but if I source it with . ./devbox/gen/scripts/.hooks.sh it works as expected.
Additional context
Please include the output of devbox version -v
Version: 0.8.6
Platform: darwin_amd64
Commit: af58be9b50c1a3d19bc21485bcbb77eb8ed8076a
Commit Time: 2024-01-18T18:36:03Z
Go Version: go1.21.5
Launcher: 0.2.1
A copy of your devbox.json file:
{
"packages": ["flake:nixpkgs#nodejs_18", "flake:nixpkgs#nodejs_18.pkgs.pnpm"],
"env": {
"STD_DEMOGRAPHICS_PORT": "4267"
},
"shell": {
"scripts": {
"setup": "pnpm install"
}
}
}
Fish version: 3.6.1
Just saw version 0.8.7 was release with a fix. That's working for me thank you! 🙇
Yep this was fixed in https://github.com/jetpack-io/devbox/pull/1741
Thanks!
I still have it wth 0.8.7, I actually only got this issue after updating to 0.8.7 yesterday.
~/.local/share/devbox/global/default/.devbox/gen/scripts/.hooks.sh (line 2): Missing end to balance this if statement
if [ -n "$__DEVBOX_INIT_HOOK_754bd1fdfe79eaf22b29d5091b2f5218a24516e27e49d4a4e3793baf5286faff" ]; then
^^
from sourcing file ~/.local/share/devbox/global/default/.devbox/gen/scripts/.hooks.sh
called on line 152 of file -
from sourcing file -
called on line 7 of file ~/.config/fish/config.fish
from sourcing file ~/.config/fish/config.fish
called during startup
.: Error while reading file '/home/rithvij/.local/share/devbox/global/default/.devbox/gen/scripts/.hooks.sh'
~ ⚹ (nix-shell-env) ⚬ devbox version 08:54:41
0.8.7
~ ⚹ (nix-shell-env) ⚬ devbox version update 08:54:54
Version: 0.8.7
Platform: linux_amd64
Commit: 525bb17ed665bb3066fbd3fb9bccec0aa961ecb7
Commit Time: 2024-01-23T19:15:31Z
Go Version: go1.21.5
Launcher: 0.2.1
Success: already at Devbox version 0.8.7
~ ⚹ (nix-shell-env) ⚬cat ~/.config/fish/config.fish
if status is-interactive
# Commands to run in interactive sessions can go here
end
set -U fish_greeting
devbox global shellenv --init-hook | source
I ran refresh-global, devbox global shellenv --recompute | source many times
I too was getting the Missing end to balance this if statement error with devbox 0.8.7 and fish. I was able to revert to 0.8.5 by adding set -gx DEVBOX_USE_VERSION 0.8.5 to my ~/.config/fish/config.fish.
Yeah, just updated to 0.8.7 and am getting this error as well.
This error disappeared for me on 0.8.7 but is back on 0.9-pre
❯ export DEVBOX_USE_VERSION=0.9.0-pre
❯ devbox version update
❯ cd my_repo
/Users/jack/my_repo/.devbox/gen/scripts/.hooks.fish.sh:10: syntax error: unexpected end of file
❯ cat /Users/jack/my_repo/.devbox/gen/scripts/.hooks.fish.sh
if set -q __DEVBOX_INIT_HOOK_d33728c8509c4b79ffd3d480e90fd6cade20b6364cb3667ac7814ebf3eb42e9b; then
exit 0
end
export __DEVBOX_INIT_HOOK_d33728c8509c4b79ffd3d480e90fd6cade20b6364cb3667ac7814ebf3eb42e9b=true
set -e __DEVBOX_INIT_HOOK_d33728c8509c4b79ffd3d480e90fd6cade20b6364cb3667ac7814ebf3eb42e9b
I've tried removing .devbox/ and re-installing it with 0.9-pre to be sure but the issue's still there
Still getting this error in the 0.9.0 release
@jay-aye-see-kay Shot in the dark, but... does rm -rf .devbox and restarting devbox shell fix it?
@jay-aye-see-kay Shot in the dark, but... does
rm -rf .devboxand restarting devbox shell fix it?
Unfortunately not
https://github.com/jetpack-io/devbox/pull/1771 should address this
@jay-aye-see-kay and everyone in this thread -- We've published a pre-release that should fix the init_hook syntax error, but want to test it before publishing a full release. Can you confirm that the Fish issue is resolved in 0.9.1?
To try the pre-release, set the following environment variable in your shell:
export DEVBOX_USE_VERSION=0.9.1
or
set -x DEVBOX_USE_VERSION 0.9.1
This will automatically download the pre-release the next time you run Devbox
@Lagoja just gave it a shot and everything appears to be working. Thank you!
Same here, working as normal again 😄. Thanks!
Chiming in for completeness, working no problems here too. Thank you very much!
The 'latest' version still throws this error for me:
$ devbox version -v
Version: 0.10.2
Platform: darwin_arm64
Commit: 63981b041029d9eb2288f26e39dc6b4fce81eca1
Commit Time: 2024-03-28T20:26:27Z
Go Version: go1.22.1
Launcher: 0.2.1
$ devbox global shellenv --init-hook | source
- (line 129): Missing end to balance this if statement
if ! type refresh-global >/dev/null 2>&1; then
^^
from sourcing file -
source: Error while reading file '<stdin>'
$ devbox global shellenv --init-hook --recompute | source
- (line 129): Missing end to balance this if statement
if ! type refresh-global >/dev/null 2>&1; then
^^
from sourcing file -
source: Error while reading file '<stdin>'
While I've had issues with updating in the past (see #1691) I thought I've gotten past that. I deleted my .cache/devbox and reinstalling the devbox scripts in /usr/local/bin. It appears that I'm on a newer version.
If anyone is in the same place I was- just needing to get this working here is my hack:
thenisn't a keyword in fish, remove.- fish uses
endinstead offi
So I put this in my .config/fish/config.fish:
devbox global shellenv --init-hook --recompute | sed -e 's/; then/;/'| sed -e 's/^fi\$/end/' | source
It's fragile and will break, but good enough until I have time to find out what's actually wrong.
So I put this in my .config/fish/config.fish:
devbox global shellenv --init-hook --recompute | sed -e 's/; then/;/'| sed -e 's/^fi\$/end/' | sourceIt's fragile and will break, but good enough until I have time to find out what's actually wrong.
Thanks for the idea, I updated the command for version 0.10.5:
devbox global shellenv --init-hook --recompute | sed -e 's/; then/;/'| sed -e 's/^fi/end/' | sed -e 's/hash -r//' | source
What's weird is this works fine in iTerm but it fails in Terminal.app and Alacritty. Tested on devbox 0.10.7
What's weird is this works fine in iTerm but it fails in Terminal.app and Alacritty. Tested on devbox 0.10.7
That's strange. Fwiw, I was using kitty on macos.
Just to follow up on my previous comment, it appears that using a custom shell in Terminal.app doesn't set $SHELL so e.g. devbox global shellenv --recompute seems unaware that it's running within fish shell. iTerm sets $SHELL to the full path of the custom shell command.