fix(fish): do not use the iTerm segment

This commit is contained in:
Jan De Dobbeleer 2023-02-05 21:30:10 +01:00 committed by Jan De Dobbeleer
parent c76e9fd166
commit 565f53b117
3 changed files with 24 additions and 9 deletions

View file

@ -5,6 +5,7 @@ import (
"github.com/jandedobbeleer/oh-my-posh/src/platform"
"github.com/jandedobbeleer/oh-my-posh/src/properties"
"github.com/jandedobbeleer/oh-my-posh/src/shell"
)
type ITerm struct {
@ -21,6 +22,7 @@ func (i *ITerm) Template() string {
func (i *ITerm) Enabled() bool {
promptMark, err := i.getResult()
if err != nil {
i.env.Error(err)
return false
}
i.PromptMark = promptMark
@ -35,19 +37,17 @@ func (i *ITerm) getResult() (string, error) {
return "", errors.New("Only works with iTerm")
}
// Check to ensure the user has squelched the default mark
// Check to ensure the user has squelched the default mark for BASH and ZSH
if i.env.Getenv("ITERM2_SQUELCH_MARK") != "1" {
return "", errors.New("iTerm default mark enabled (set ITERM2_SQUELCH_MARK=1)")
return "", errors.New("iTerm default mark enabled (export ITERM2_SQUELCH_MARK=1)")
}
// Now, set the mark string based on shell (or error out)
switch i.env.Shell() {
case "zsh":
case shell.ZSH:
response = `%{$(iterm2_prompt_mark)%}`
case "bash":
case shell.BASH:
response = `\[$(iterm2_prompt_mark)\]`
case "fish":
response = `iterm2_prompt_mark`
default:
return "", errors.New("Shell isn't compatible with iTerm Shell Integration")
}

View file

@ -6,6 +6,7 @@ import (
"github.com/jandedobbeleer/oh-my-posh/src/mock"
"github.com/stretchr/testify/assert"
mock2 "github.com/stretchr/testify/mock"
)
func TestITermSegment(t *testing.T) {
@ -22,7 +23,7 @@ func TestITermSegment(t *testing.T) {
{Case: "default mark", TermProgram: "iTerm.app", Shell: "zsh", Template: "{{ .PromptMark }}", ExpectedDisabled: true},
{Case: "zsh", TermProgram: "iTerm.app", SquelchMark: "1", Shell: "zsh", Template: "{{ .PromptMark }}", ExpectedString: `%{$(iterm2_prompt_mark)%}`},
{Case: "bash", TermProgram: "iTerm.app", SquelchMark: "1", Shell: "bash", Template: "{{ .PromptMark }}", ExpectedString: `\[$(iterm2_prompt_mark)\]`},
{Case: "fish", TermProgram: "iTerm.app", SquelchMark: "1", Shell: "fish", Template: "{{ .PromptMark }}", ExpectedString: `iterm2_prompt_mark`},
{Case: "fish", TermProgram: "iTerm.app", SquelchMark: "1", Shell: "fish", Template: "{{ .PromptMark }}", ExpectedDisabled: true},
{Case: "pwsh", TermProgram: "iTerm.app", SquelchMark: "1", Shell: "pwsh", Template: "{{ .PromptMark }}", ExpectedDisabled: true},
{Case: "gibberishshell", TermProgram: "iTerm.app", SquelchMark: "1", Shell: "jaserhuashf", Template: "{{ .PromptMark }}", ExpectedDisabled: true},
}
@ -33,6 +34,7 @@ func TestITermSegment(t *testing.T) {
env.On("Getenv", "TERM_PROGRAM").Return(tc.TermProgram)
env.On("Getenv", "ITERM2_SQUELCH_MARK").Return(tc.SquelchMark)
env.On("Shell").Return(tc.Shell)
env.On("Error", mock2.Anything).Return()
iterm := &ITerm{
env: env,
}

View file

@ -6,12 +6,25 @@ sidebar_label: iTerm
## What
Inserts the iTerm2 shell integration prompt mark for zsh, bash, and fish.
Inserts the iTerm2 shell integration prompt mark for zsh, and bash.
For more information, read the [shell integration page][int-page] on
the developer's website.
:::info
You will need to set env var `ITERM2_SQUELCH_MARK = 1` prior to initiating Oh My Posh.
You will need to add `export ITERM2_SQUELCH_MARK=1` before the shell integration script is sourced.
:::
:::info Fish shell
For fish, you can make use of Oh My Posh's `set_poshcontext` function to set the prompt mark. Add the
following line after initialising Oh My Posh:
```fish
function set_poshcontext
iterm2_prompt_mark
end
```
You do not need to add this segment.
:::
## Sample Configuration