Skip to content

Commit bd5a091

Browse files
authored
Option to disable modification of the user's prompt. (#1743)
## Summary Devbox prefixes the user's prompt (PS1) with `(devbox)` when inside the `devbox shell`. Unfortunately, this doesn't look great with prompts which have been customized (with starship for example). Disable prompt modification by setting either `DEVBOX_NO_PROMPT` or `devbox_no_prompt` (fish) in your shell. Now the user can detect devbox and display it on their PS1 using the method if their choosing. Fixes #845. ## How was it tested? ### bash and zsh I ran the command in these shells with `export DEVBOX_NO_PROMPT=true` and without the variable (`unset DEVBOX_NO_PROMPT`) and observed the results. ``` if [ -z "$DEVBOX_NO_PROMPT" ]; then export PS1="(devbox) $PS1" fi ``` ### fish Disclaimer, I'm not a fish user. I installed fish and read the documentation. I added `set devbox_no_prompt true` to my `.config/fish/config.fish`, then removed it and observed the results. ``` if not set -q devbox_no_prompt functions -c fish_prompt __devbox_fish_prompt_orig function fish_prompt echo "(devbox)" (__devbox_fish_prompt_orig) end end ```
1 parent 525bb17 commit bd5a091

File tree

4 files changed

+22
-10
lines changed

4 files changed

+22
-10
lines changed

internal/devbox/shellrc.tmpl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,11 @@ ignore the existing value of HISTFILE.
3838
HISTFILE="{{ .HistoryFile }}"
3939
{{- end }}
4040

41-
# Prepend to the prompt to make it clear we're in a devbox shell.
42-
export PS1="(devbox) $PS1"
41+
# If the user hasn't specified they want to handle the prompt themselves,
42+
# prepend to the prompt to make it clear we're in a devbox shell.
43+
if [ -z "$DEVBOX_NO_PROMPT" ]; then
44+
export PS1="(devbox) $PS1"
45+
fi
4346

4447
{{- if .ShellStartTime }}
4548
# log that the shell is ready now!

internal/devbox/shellrc_fish.tmpl

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,13 @@ enough approximation for now.
3838
set fish_history devbox
3939
{{- end }}
4040

41-
# Prepend to the prompt to make it clear we're in a devbox shell.
42-
functions -c fish_prompt __devbox_fish_prompt_orig
43-
function fish_prompt
44-
echo "(devbox)" (__devbox_fish_prompt_orig)
41+
# If the user hasn't specified they want to handle the prompt themselves,
42+
# prepend to the prompt to make it clear we're in a devbox shell.
43+
if not set -q devbox_no_prompt
44+
functions -c fish_prompt __devbox_fish_prompt_orig
45+
function fish_prompt
46+
echo "(devbox)" (__devbox_fish_prompt_orig)
47+
end
4548
end
4649

4750
{{- if .ShellStartTime }}

internal/devbox/testdata/shellrc/basic/shellrc.golden

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,11 @@ export simple="value";
88
export space="quote me";
99
export special="\$\`\"\\";
1010

11-
# Prepend to the prompt to make it clear we're in a devbox shell.
12-
export PS1="(devbox) $PS1"
11+
# If the user hasn't specified they want to handle the prompt themselves,
12+
# prepend to the prompt to make it clear we're in a devbox shell.
13+
if [ -z "$DEVBOX_NO_PROMPT" ]; then
14+
export PS1="(devbox) $PS1"
15+
fi
1316

1417
# End Devbox Post-init Hook
1518

internal/devbox/testdata/shellrc/noshellrc/shellrc.golden

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@
22

33

44

5-
# Prepend to the prompt to make it clear we're in a devbox shell.
6-
export PS1="(devbox) $PS1"
5+
# If the user hasn't specified they want to handle the prompt themselves,
6+
# prepend to the prompt to make it clear we're in a devbox shell.
7+
if [ -z "$DEVBOX_NO_PROMPT" ]; then
8+
export PS1="(devbox) $PS1"
9+
fi
710

811
# End Devbox Post-init Hook
912

0 commit comments

Comments
 (0)