mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2025-01-13 20:27:28 -08:00
fix(iterm): initialize prompt mark correctly for all supported shells
This commit is contained in:
parent
5dee9d74a6
commit
eebb45ef07
|
@ -181,7 +181,6 @@ func (w *Writer) Init(shellName string) {
|
||||||
w.osc99 = "\x1b]9;9;%s\x1b\\"
|
w.osc99 = "\x1b]9;9;%s\x1b\\"
|
||||||
w.osc7 = "\x1b]7;file://%s/%s\x1b\\"
|
w.osc7 = "\x1b]7;file://%s/%s\x1b\\"
|
||||||
w.osc51 = "\x1b]51;A%s@%s:%s\x1b\\"
|
w.osc51 = "\x1b]51;A%s@%s:%s\x1b\\"
|
||||||
w.iTermPromptMark = "$(iterm2_prompt_mark)"
|
|
||||||
w.iTermCurrentDir = "\x1b]1337;CurrentDir=%s\x07"
|
w.iTermCurrentDir = "\x1b]1337;CurrentDir=%s\x07"
|
||||||
w.iTermRemoteHost = "\x1b]1337;RemoteHost=%s@%s\x07"
|
w.iTermRemoteHost = "\x1b]1337;RemoteHost=%s@%s\x07"
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,10 @@ package ansi
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"slices"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/jandedobbeleer/oh-my-posh/src/shell"
|
||||||
)
|
)
|
||||||
|
|
||||||
type iTermFeature string
|
type iTermFeature string
|
||||||
|
@ -15,11 +18,27 @@ const (
|
||||||
|
|
||||||
type ITermFeatures []iTermFeature
|
type ITermFeatures []iTermFeature
|
||||||
|
|
||||||
func (w *Writer) RenderItermFeatures(features ITermFeatures, pwd, user, host string) string {
|
func (f ITermFeatures) Contains(feature iTermFeature) bool {
|
||||||
|
for _, item := range f {
|
||||||
|
if item == feature {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w *Writer) RenderItermFeatures(features ITermFeatures, sh, pwd, user, host string) string {
|
||||||
|
supportedShells := []string{shell.BASH, shell.ZSH}
|
||||||
|
|
||||||
var result strings.Builder
|
var result strings.Builder
|
||||||
for _, feature := range features {
|
for _, feature := range features {
|
||||||
switch feature {
|
switch feature {
|
||||||
case PromptMark:
|
case PromptMark:
|
||||||
|
if !slices.Contains(supportedShells, sh) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
result.WriteString(w.iTermPromptMark)
|
result.WriteString(w.iTermPromptMark)
|
||||||
case CurrentDir:
|
case CurrentDir:
|
||||||
result.WriteString(fmt.Sprintf(w.iTermCurrentDir, pwd))
|
result.WriteString(fmt.Sprintf(w.iTermCurrentDir, pwd))
|
||||||
|
|
|
@ -3,6 +3,7 @@ package cli
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/jandedobbeleer/oh-my-posh/src/ansi"
|
||||||
"github.com/jandedobbeleer/oh-my-posh/src/engine"
|
"github.com/jandedobbeleer/oh-my-posh/src/engine"
|
||||||
"github.com/jandedobbeleer/oh-my-posh/src/platform"
|
"github.com/jandedobbeleer/oh-my-posh/src/platform"
|
||||||
"github.com/jandedobbeleer/oh-my-posh/src/shell"
|
"github.com/jandedobbeleer/oh-my-posh/src/shell"
|
||||||
|
@ -71,6 +72,7 @@ func runInit(shellName string) {
|
||||||
shell.ErrorLine = cfg.ErrorLine != nil || cfg.ValidLine != nil
|
shell.ErrorLine = cfg.ErrorLine != nil || cfg.ValidLine != nil
|
||||||
shell.Tooltips = len(cfg.Tooltips) > 0
|
shell.Tooltips = len(cfg.Tooltips) > 0
|
||||||
shell.ShellIntegration = cfg.ShellIntegration
|
shell.ShellIntegration = cfg.ShellIntegration
|
||||||
|
shell.PromptMark = shellName == shell.FISH && cfg.ITermFeatures != nil && cfg.ITermFeatures.Contains(ansi.PromptMark)
|
||||||
|
|
||||||
for i, block := range cfg.Blocks {
|
for i, block := range cfg.Blocks {
|
||||||
// only fetch cursor position when relevant
|
// only fetch cursor position when relevant
|
||||||
|
|
|
@ -70,7 +70,7 @@ func (e *Engine) Primary() string {
|
||||||
|
|
||||||
if e.Config.ITermFeatures != nil && e.isIterm() {
|
if e.Config.ITermFeatures != nil && e.isIterm() {
|
||||||
host, _ := e.Env.Host()
|
host, _ := e.Env.Host()
|
||||||
e.write(e.Writer.RenderItermFeatures(e.Config.ITermFeatures, e.Env.Pwd(), e.Env.User(), host))
|
e.write(e.Writer.RenderItermFeatures(e.Config.ITermFeatures, e.Env.Shell(), e.Env.Pwd(), e.Env.User(), host))
|
||||||
}
|
}
|
||||||
|
|
||||||
if e.Config.ShellIntegration && e.Config.TransientPrompt == nil {
|
if e.Config.ShellIntegration && e.Config.TransientPrompt == nil {
|
||||||
|
|
|
@ -52,6 +52,7 @@ var (
|
||||||
ShellIntegration bool
|
ShellIntegration bool
|
||||||
RPrompt bool
|
RPrompt bool
|
||||||
CursorPositioning bool
|
CursorPositioning bool
|
||||||
|
PromptMark bool
|
||||||
)
|
)
|
||||||
|
|
||||||
func getExecutablePath(env platform.Environment) (string, error) {
|
func getExecutablePath(env platform.Environment) (string, error) {
|
||||||
|
@ -207,9 +208,18 @@ func PrintInit(env platform.Environment) string {
|
||||||
if env.Flags().Manual {
|
if env.Flags().Manual {
|
||||||
return "false"
|
return "false"
|
||||||
}
|
}
|
||||||
|
|
||||||
return strconv.FormatBool(setting)
|
return strconv.FormatBool(setting)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
promptMark := func() string {
|
||||||
|
if PromptMark {
|
||||||
|
return "iterm2_prompt_mark"
|
||||||
|
}
|
||||||
|
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
shell := env.Flags().Shell
|
shell := env.Flags().Shell
|
||||||
configFile := env.Flags().Config
|
configFile := env.Flags().Config
|
||||||
|
|
||||||
|
@ -273,6 +283,7 @@ func PrintInit(env platform.Environment) string {
|
||||||
"::CURSOR::", strconv.FormatBool(CursorPositioning),
|
"::CURSOR::", strconv.FormatBool(CursorPositioning),
|
||||||
"::UPGRADE::", strconv.FormatBool(hasNotice),
|
"::UPGRADE::", strconv.FormatBool(hasNotice),
|
||||||
"::UPGRADENOTICE::", notice,
|
"::UPGRADENOTICE::", notice,
|
||||||
|
"::PROMPT_MARK::", promptMark(),
|
||||||
).Replace(script)
|
).Replace(script)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,16 +23,19 @@ function fish_prompt
|
||||||
::OMP:: print transient --config $POSH_THEME --shell fish --status $omp_status_cache --pipestatus="$omp_pipestatus_cache" --execution-time $omp_duration --stack-count $omp_stack_count --shell-version $FISH_VERSION --no-status=$omp_no_exit_code
|
::OMP:: print transient --config $POSH_THEME --shell fish --status $omp_status_cache --pipestatus="$omp_pipestatus_cache" --execution-time $omp_duration --stack-count $omp_stack_count --shell-version $FISH_VERSION --no-status=$omp_no_exit_code
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
set --global omp_status_cache $omp_status_cache_temp
|
set --global omp_status_cache $omp_status_cache_temp
|
||||||
set --global omp_pipestatus_cache $omp_pipestatus_cache_temp
|
set --global omp_pipestatus_cache $omp_pipestatus_cache_temp
|
||||||
set --global omp_stack_count (count $dirstack)
|
set --global omp_stack_count (count $dirstack)
|
||||||
set --global omp_duration "$CMD_DURATION$cmd_duration"
|
set --global omp_duration "$CMD_DURATION$cmd_duration"
|
||||||
set --global omp_no_exit_code false
|
set --global omp_no_exit_code false
|
||||||
|
|
||||||
# check if variable set, < 3.2 case
|
# check if variable set, < 3.2 case
|
||||||
if set --query omp_lastcommand; and test "$omp_lastcommand" = ""
|
if set --query omp_lastcommand; and test "$omp_lastcommand" = ""
|
||||||
set omp_duration 0
|
set omp_duration 0
|
||||||
set omp_no_exit_code true
|
set omp_no_exit_code true
|
||||||
end
|
end
|
||||||
|
|
||||||
# works with fish >=3.2
|
# works with fish >=3.2
|
||||||
if set --query omp_last_status_generation; and test "$omp_last_status_generation" = "$status_generation"
|
if set --query omp_last_status_generation; and test "$omp_last_status_generation" = "$status_generation"
|
||||||
set omp_duration 0
|
set omp_duration 0
|
||||||
|
@ -41,16 +44,23 @@ function fish_prompt
|
||||||
# first execution - $status_generation is 0, $omp_last_status_generation is empty
|
# first execution - $status_generation is 0, $omp_last_status_generation is empty
|
||||||
set omp_no_exit_code true
|
set omp_no_exit_code true
|
||||||
end
|
end
|
||||||
|
|
||||||
if set --query status_generation
|
if set --query status_generation
|
||||||
set --global --export omp_last_status_generation $status_generation
|
set --global --export omp_last_status_generation $status_generation
|
||||||
end
|
end
|
||||||
|
|
||||||
set_poshcontext
|
set_poshcontext
|
||||||
|
|
||||||
# validate if the user cleared the screen
|
# validate if the user cleared the screen
|
||||||
set --local omp_cleared false
|
set --local omp_cleared false
|
||||||
set --local last_command (history search --max 1)
|
set --local last_command (history search --max 1)
|
||||||
|
|
||||||
if test "$last_command" = "clear"
|
if test "$last_command" = "clear"
|
||||||
set omp_cleared true
|
set omp_cleared true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
::PROMPT_MARK::
|
||||||
|
|
||||||
::OMP:: print primary --config $POSH_THEME --shell fish --status $omp_status_cache --pipestatus="$omp_pipestatus_cache" --execution-time $omp_duration --stack-count $omp_stack_count --shell-version $FISH_VERSION --cleared=$omp_cleared --no-status=$omp_no_exit_code
|
::OMP:: print primary --config $POSH_THEME --shell fish --status $omp_status_cache --pipestatus="$omp_pipestatus_cache" --execution-time $omp_duration --stack-count $omp_stack_count --shell-version $FISH_VERSION --cleared=$omp_cleared --no-status=$omp_no_exit_code
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue