Skip to content

Commit f4393f5

Browse files
committed
Fix and refactor the way devbox init_hook works
This is so that commands that the hook can be used to modify the actual devbox shell instead of just running the hook in a sub shell.
1 parent 46c860a commit f4393f5

File tree

6 files changed

+42
-26
lines changed

6 files changed

+42
-26
lines changed

.devboxrc.example

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Commands you put here will run every time you enter the `devbox shell` or
2+
# run other devbox commands (like `devbox run` or `devbox services`).
3+
4+
# IMPORTANT:
5+
# - don't use this file for environment variables; use .env instead.
6+
# - `devbox services` runs in a basic sh shell, so only put POSIX-compliant
7+
# shell commands here (e.g. no bash-specific syntax) (unless you check for bash).
8+
9+
10+
# Tab completion for tools managed by devbox
11+
# if [ -n "$BASH_VERSION" ]; then
12+
# eval "$(quarkus completion)"
13+
14+
# Some tools install their bash completions to this directory
15+
# if [ -d .devbox/nix/profile/default/share/bash-completion/completions ]; then
16+
# for completion in .devbox/nix/profile/default/share/bash-completion/completions/*; do
17+
# [ -f "$completion" ] && source "$completion"
18+
# done
19+
# fi
20+
21+
# NOTE: for tab completion of devbox itself, put the following in your ~/.bashrc, etc:
22+
# source <(devbox completion bash)
23+
# fi
24+
25+
26+
# Disable or workaround tools that might interfere with devbox
27+
# command -v mise >/dev/null && mise deactivate # interferes with PATH
28+
29+
30+
# Project-specific aliases
31+
# alias dup="devbox services up"

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,4 @@ node_modules/
7777

7878
.quarkus/
7979

80-
bin/devbox-init-hook
80+
.devboxrc

bin/devbox-init-hook.example

Lines changed: 0 additions & 14 deletions
This file was deleted.

bin/install-devbox

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,14 @@ fi
3030

3131
bin/ensure-root-env-file
3232

33-
print_status "🔍 Checking for existing bin/devbox-init-hook..."
34-
if [ -f "bin/devbox-init-hook.example" ] && [ ! -f "bin/devbox-init-hook" ]; then
35-
cp "bin/devbox-init-hook.example" "bin/devbox-init-hook"
36-
chmod +x "bin/devbox-init-hook"
37-
print_success "✓ Created bin/devbox-init-hook from example"
38-
elif [ -f "bin/devbox-init-hook" ]; then
39-
print_status "○ bin/devbox-init-hook already exists"
33+
print_status "🔍 Checking for existing .devboxrc..."
34+
if [ -f ".devboxrc.example" ] && [ ! -f ".devboxrc" ]; then
35+
cp ".devboxrc.example" ".devboxrc"
36+
print_success "✓ Created .devboxrc from example"
37+
elif [ -f ".devboxrc" ]; then
38+
print_status "○ .devboxrc already exists"
4039
else
41-
print_error "⚠ Error: bin/devbox-init-hook.example not found."
40+
print_error "⚠ Error: .devboxrc.example not found."
4241
exit 1
4342
fi
4443

bin/teardown

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,6 @@ echo -n "Backing up .env files"
3333
find . -type f -name ".env" -exec mv {} {}.backup-$(date -Iseconds) \;
3434
echo "...done"
3535

36-
echo -n "Backing up bin/devbox-init-hook"
37-
mv bin/devbox-init-hook bin/devbox-init-hook.backup-$(date -Iseconds)
36+
echo -n "Backing up .devboxrc"
37+
mv .devboxrc .devboxrc.backup-$(date -Iseconds)
3838
echo "...done"

devbox.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"env_from": ".env",
1212
"shell": {
1313
"init_hook": [
14-
"command -v bin/devbox-init-hook >/dev/null && bin/devbox-init-hook || true",
14+
"[ -f .devboxrc ] && . ./.devboxrc",
1515
"echo 'Welcome to devbox!'"
1616
],
1717
"scripts": {

0 commit comments

Comments
 (0)