Repository: jetpack-io/devbox (go)

Issue:
[Bug]: prompt hint from devbox mess up my multi line prompt in fish
**Current Behavior (bug)**
A clear and concise description of what the bug is.
![image](https://user-images.githubusercontent.com/16734391/228701971-a79e7637-1d1e-49f0-a75f-71d93854468f.png)

**Expected Behavior (fix)**
A clear and concise description of what you expected to happen.
Maybe some kind like that?
![image](https://user-images.githubusercontent.com/16734391/228704116-7fd39d1b-a26a-4e7e-9252-d708ab9e02cc.png)

Actually, I would prefer just to disable the built-in hint since I have my prompt theme. An [issue](https://github.com/jetpack-io/devbox/issues/108) about that has been opened before. It seems to be discussed in the [issue](https://github.com/jetpack-io/devbox/issues/74) but the relevant [pull request](https://github.com/jetpack-io/devbox/pull/145) was closed and seems no any new and the code is still [here](https://github.com/jetpack-io/devbox/blob/f8d286d9095571554eeb0e62987f4f36c547377e/internal/impl/shellrc.tmpl#L41) and [here](https://github.com/jetpack-io/devbox/blob/f8d286d9095571554eeb0e62987f4f36c547377e/internal/impl/shellrc_fish.tmpl#L43)

**Additional context**
Please include the output of `devbox version -v` and
a copy of your `devbox.json` file.
```
Version:     0.4.5
Platform:    linux_amd64
Commit:      64d31f597940166ba55efa9cacf8bd6ceca392c5
Commit Time: 2023-03-27T21:50:28Z
Go Version:  go1.19.7
```
```
{
  "packages": [],
  "shell": {
    "init_hook": null
  },
  "nixpkgs": {
    "commit": "f80ac848e3d6f0c12c52758c0f25c10c97ca3b62"
  }
}
```

Pull request description:
Option to disable modification of the user's prompt.
## 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
```

Patch:
diff --git a/internal/devbox/shellrc.tmpl b/internal/devbox/shellrc.tmpl
index 24a314e1..6f0e5f52 100644
--- a/internal/devbox/shellrc.tmpl
+++ b/internal/devbox/shellrc.tmpl
@@ -38,8 +38,11 @@ ignore the existing value of HISTFILE.
 HISTFILE="{{ .HistoryFile }}"
 {{- end }}
 
-# Prepend to the prompt to make it clear we're in a devbox shell.
-export PS1="(devbox) $PS1"
+# If the user hasn't specified they want to handle the prompt themselves,
+# prepend to the prompt to make it clear we're in a devbox shell.
+if [ -z "$DEVBOX_NO_PROMPT" ]; then
+  export PS1="(devbox) $PS1"
+fi
 
 {{- if .ShellStartTime }}
 # log that the shell is ready now!
diff --git a/internal/devbox/shellrc_fish.tmpl b/internal/devbox/shellrc_fish.tmpl
index daf252ad..a50b3fb2 100644
--- a/internal/devbox/shellrc_fish.tmpl
+++ b/internal/devbox/shellrc_fish.tmpl
@@ -38,10 +38,13 @@ enough approximation for now.
 set fish_history devbox
 {{- end }}
 
-# Prepend to the prompt to make it clear we're in a devbox shell.
-functions -c fish_prompt __devbox_fish_prompt_orig
-function fish_prompt
-    echo "(devbox)" (__devbox_fish_prompt_orig)
+# If the user hasn't specified they want to handle the prompt themselves,
+# prepend to the prompt to make it clear we're in a devbox shell.
+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
 
 {{- if .ShellStartTime }}


Test patch:
diff --git a/internal/devbox/testdata/shellrc/basic/shellrc.golden b/internal/devbox/testdata/shellrc/basic/shellrc.golden
index ac2c2b2d..9e110a4a 100644
--- a/internal/devbox/testdata/shellrc/basic/shellrc.golden
+++ b/internal/devbox/testdata/shellrc/basic/shellrc.golden
@@ -8,8 +8,11 @@ export simple="value";
 export space="quote me";
 export special="\$\`\"\\";
 
-# Prepend to the prompt to make it clear we're in a devbox shell.
-export PS1="(devbox) $PS1"
+# If the user hasn't specified they want to handle the prompt themselves,
+# prepend to the prompt to make it clear we're in a devbox shell.
+if [ -z "$DEVBOX_NO_PROMPT" ]; then
+  export PS1="(devbox) $PS1"
+fi
 
 # End Devbox Post-init Hook
 
diff --git a/internal/devbox/testdata/shellrc/noshellrc/shellrc.golden b/internal/devbox/testdata/shellrc/noshellrc/shellrc.golden
index 10f6de23..e7ac3d7b 100644
--- a/internal/devbox/testdata/shellrc/noshellrc/shellrc.golden
+++ b/internal/devbox/testdata/shellrc/noshellrc/shellrc.golden
@@ -2,8 +2,11 @@
 
 
 
-# Prepend to the prompt to make it clear we're in a devbox shell.
-export PS1="(devbox) $PS1"
+# If the user hasn't specified they want to handle the prompt themselves,
+# prepend to the prompt to make it clear we're in a devbox shell.
+if [ -z "$DEVBOX_NO_PROMPT" ]; then
+  export PS1="(devbox) $PS1"
+fi
 
 # End Devbox Post-init Hook