mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2024-12-28 04:19:41 -08:00
fix(fish): do not use the iTerm segment
This commit is contained in:
parent
c76e9fd166
commit
565f53b117
|
@ -5,6 +5,7 @@ import (
|
||||||
|
|
||||||
"github.com/jandedobbeleer/oh-my-posh/src/platform"
|
"github.com/jandedobbeleer/oh-my-posh/src/platform"
|
||||||
"github.com/jandedobbeleer/oh-my-posh/src/properties"
|
"github.com/jandedobbeleer/oh-my-posh/src/properties"
|
||||||
|
"github.com/jandedobbeleer/oh-my-posh/src/shell"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ITerm struct {
|
type ITerm struct {
|
||||||
|
@ -21,6 +22,7 @@ func (i *ITerm) Template() string {
|
||||||
func (i *ITerm) Enabled() bool {
|
func (i *ITerm) Enabled() bool {
|
||||||
promptMark, err := i.getResult()
|
promptMark, err := i.getResult()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
i.env.Error(err)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
i.PromptMark = promptMark
|
i.PromptMark = promptMark
|
||||||
|
@ -35,19 +37,17 @@ func (i *ITerm) getResult() (string, error) {
|
||||||
return "", errors.New("Only works with iTerm")
|
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" {
|
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)
|
// Now, set the mark string based on shell (or error out)
|
||||||
switch i.env.Shell() {
|
switch i.env.Shell() {
|
||||||
case "zsh":
|
case shell.ZSH:
|
||||||
response = `%{$(iterm2_prompt_mark)%}`
|
response = `%{$(iterm2_prompt_mark)%}`
|
||||||
case "bash":
|
case shell.BASH:
|
||||||
response = `\[$(iterm2_prompt_mark)\]`
|
response = `\[$(iterm2_prompt_mark)\]`
|
||||||
case "fish":
|
|
||||||
response = `iterm2_prompt_mark`
|
|
||||||
default:
|
default:
|
||||||
return "", errors.New("Shell isn't compatible with iTerm Shell Integration")
|
return "", errors.New("Shell isn't compatible with iTerm Shell Integration")
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@ import (
|
||||||
"github.com/jandedobbeleer/oh-my-posh/src/mock"
|
"github.com/jandedobbeleer/oh-my-posh/src/mock"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
mock2 "github.com/stretchr/testify/mock"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestITermSegment(t *testing.T) {
|
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: "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: "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: "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: "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},
|
{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", "TERM_PROGRAM").Return(tc.TermProgram)
|
||||||
env.On("Getenv", "ITERM2_SQUELCH_MARK").Return(tc.SquelchMark)
|
env.On("Getenv", "ITERM2_SQUELCH_MARK").Return(tc.SquelchMark)
|
||||||
env.On("Shell").Return(tc.Shell)
|
env.On("Shell").Return(tc.Shell)
|
||||||
|
env.On("Error", mock2.Anything).Return()
|
||||||
iterm := &ITerm{
|
iterm := &ITerm{
|
||||||
env: env,
|
env: env,
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,12 +6,25 @@ sidebar_label: iTerm
|
||||||
|
|
||||||
## What
|
## 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
|
For more information, read the [shell integration page][int-page] on
|
||||||
the developer's website.
|
the developer's website.
|
||||||
|
|
||||||
:::info
|
:::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
|
## Sample Configuration
|
||||||
|
|
Loading…
Reference in a new issue