mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2025-03-05 20:49:04 -08:00
refactor: better use of POSH_THEME
This commit is contained in:
parent
f9d2f6040e
commit
4fa407d15e
|
@ -244,8 +244,10 @@ func (term *Terminal) Init() {
|
|||
func (term *Terminal) resolveConfigPath() {
|
||||
defer term.Trace(time.Now())
|
||||
|
||||
if len(term.CmdFlags.Config) == 0 {
|
||||
term.CmdFlags.Config = term.Getenv("POSH_THEME")
|
||||
if poshTheme := term.Getenv("POSH_THEME"); len(poshTheme) > 0 {
|
||||
term.DebugF("Config set using POSH_THEME: %s", poshTheme)
|
||||
term.CmdFlags.Config = poshTheme
|
||||
return
|
||||
}
|
||||
|
||||
if len(term.CmdFlags.Config) == 0 {
|
||||
|
|
|
@ -20,7 +20,7 @@ _omp_ftcs_marks=0
|
|||
# start timer on command start
|
||||
PS0='${_omp_start_time:0:$((_omp_start_time="$(_omp_start_timer)",0))}$(_omp_ftcs_command_start)'
|
||||
# set secondary prompt
|
||||
PS2="$(${_omp_executable} print secondary --config="$POSH_THEME" --shell=bash --shell-version="$BASH_VERSION")"
|
||||
PS2="$(${_omp_executable} print secondary --shell=bash --shell-version="$BASH_VERSION")"
|
||||
|
||||
function _omp_set_cursor_position() {
|
||||
# not supported in Midnight Commander
|
||||
|
@ -81,7 +81,7 @@ function _omp_hook() {
|
|||
set_poshcontext
|
||||
_omp_set_cursor_position
|
||||
|
||||
PS1="$(${_omp_executable} print primary --config="$POSH_THEME" --shell=bash --shell-version="$BASH_VERSION" --status="$_omp_status_cache" --pipestatus="${_omp_pipestatus_cache[*]}" --execution-time="$_omp_elapsed" --stack-count="$_omp_stack_count" --no-status="$_omp_no_exit_code" --terminal-width="${COLUMNS-0}" | tr -d '\0')"
|
||||
PS1="$(${_omp_executable} print primary --shell=bash --shell-version="$BASH_VERSION" --status="$_omp_status_cache" --pipestatus="${_omp_pipestatus_cache[*]}" --execution-time="$_omp_elapsed" --stack-count="$_omp_stack_count" --no-status="$_omp_no_exit_code" --terminal-width="${COLUMNS-0}" | tr -d '\0')"
|
||||
|
||||
return $_omp_status_cache
|
||||
}
|
||||
|
|
|
@ -24,10 +24,10 @@ set edit:after-command = [ $@edit:after-command $posh-after-command-hook~ ]
|
|||
|
||||
set edit:prompt = {
|
||||
var cmd-duration = (printf "%.0f" (* $edit:command-duration 1000))
|
||||
$_omp_executable print primary --config=$E:POSH_THEME --shell=elvish --execution-time=$cmd-duration --status=$error-code --pwd=$pwd --shell-version=$E:POSH_SHELL_VERSION
|
||||
$_omp_executable print primary --shell=elvish --execution-time=$cmd-duration --status=$error-code --pwd=$pwd --shell-version=$E:POSH_SHELL_VERSION
|
||||
}
|
||||
|
||||
set edit:rprompt = {
|
||||
var cmd-duration = (printf "%.0f" (* $edit:command-duration 1000))
|
||||
$_omp_executable print right --config=$E:POSH_THEME --shell=elvish --execution-time=$cmd-duration --status=$error-code --pwd=$pwd --shell-version=$E:POSH_SHELL_VERSION
|
||||
$_omp_executable print right --shell=elvish --execution-time=$cmd-duration --status=$error-code --pwd=$pwd --shell-version=$E:POSH_SHELL_VERSION
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@ function fish_prompt
|
|||
# see https://github.com/fish-shell/fish-shell/issues/8418
|
||||
printf \e\[0J
|
||||
if test "$_omp_transient" = true
|
||||
$_omp_executable 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_executable print transient --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
|
||||
end
|
||||
if test "$_omp_new_prompt" = false
|
||||
|
@ -77,7 +77,7 @@ function fish_prompt
|
|||
end
|
||||
|
||||
# The prompt is saved for possible reuse, typically a repaint after clearing the screen buffer.
|
||||
set --global _omp_current_prompt ($_omp_executable 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 | string collect)
|
||||
set --global _omp_current_prompt ($_omp_executable print primary --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 | string collect)
|
||||
echo -n "$_omp_current_prompt"
|
||||
end
|
||||
|
||||
|
@ -94,7 +94,7 @@ function fish_right_prompt
|
|||
end
|
||||
|
||||
set _omp_new_prompt false
|
||||
set --global _omp_current_rprompt ($_omp_executable print right --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 | string join '')
|
||||
set --global _omp_current_rprompt ($_omp_executable print right --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 | string join '')
|
||||
|
||||
echo -n "$_omp_current_rprompt"
|
||||
end
|
||||
|
@ -150,7 +150,7 @@ function _omp_space_key_handler
|
|||
end
|
||||
|
||||
set _omp_tooltip_command $tooltip_command
|
||||
set --local tooltip_prompt ($_omp_executable print tooltip --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 --command $_omp_tooltip_command --no-status=$_omp_no_exit_code | string join '')
|
||||
set --local tooltip_prompt ($_omp_executable print tooltip --shell fish --status $_omp_status_cache --pipestatus="$_omp_pipestatus_cache" --execution-time $_omp_duration --stack-count $_omp_stack_count --shell-version $FISH_VERSION --command $_omp_tooltip_command --no-status=$_omp_no_exit_code | string join '')
|
||||
|
||||
if test -z "$tooltip_prompt"
|
||||
return
|
||||
|
|
|
@ -74,10 +74,6 @@ local function omp_exe()
|
|||
return '"'..::OMP::..'"'
|
||||
end
|
||||
|
||||
local function omp_config()
|
||||
return '"'..::CONFIG::..'"'
|
||||
end
|
||||
|
||||
os.setenv("POSH_THEME", ::CONFIG::)
|
||||
os.setenv("POSH_SHELL_VERSION", string.format('clink v%s.%s.%s.%s', clink.version_major, clink.version_minor, clink.version_patch, clink.version_commit))
|
||||
|
||||
|
@ -162,7 +158,7 @@ local function get_posh_prompt(rprompt)
|
|||
if rprompt then
|
||||
prompt = "right"
|
||||
end
|
||||
local prompt_exe = string.format('%s print %s --shell=cmd --config=%s %s %s %s', omp_exe(), prompt, omp_config(), execution_time_option(), error_level_option(), no_exit_code_option())
|
||||
local prompt_exe = string.format('%s print %s --shell=cmd %s %s %s', omp_exe(), prompt, execution_time_option(), error_level_option(), no_exit_code_option())
|
||||
return run_posh_command(prompt_exe)
|
||||
end
|
||||
|
||||
|
@ -171,7 +167,7 @@ local function set_posh_tooltip(tip_command)
|
|||
-- Escape special characters properly, if any.
|
||||
local escaped_tip_command = string.gsub(tip_command, '(\\+)"', '%1%1"'):gsub('(\\+)$', '%1%1'):gsub('"', '\\"'):gsub('([&<>%(%)@%^|])', '^%1')
|
||||
|
||||
local prompt_exe = string.format('%s print tooltip --shell=cmd %s --config=%s --command="%s"', omp_exe(), error_level_option(), omp_config(), escaped_tip_command)
|
||||
local prompt_exe = string.format('%s print tooltip --shell=cmd %s --command="%s"', omp_exe(), error_level_option(), escaped_tip_command)
|
||||
local tooltip = run_posh_command(prompt_exe)
|
||||
-- Do not cache an empty tooltip.
|
||||
if tooltip == "" then
|
||||
|
@ -273,7 +269,7 @@ function p:transientfilter(prompt)
|
|||
return nil
|
||||
end
|
||||
|
||||
local prompt_exe = string.format('%s print transient --shell=cmd --config=%s %s %s', omp_exe(), omp_config(), error_level_option(), no_exit_code_option())
|
||||
local prompt_exe = string.format('%s print transient --shell=cmd %s %s', omp_exe(), error_level_option(), no_exit_code_option())
|
||||
prompt = run_posh_command(prompt_exe)
|
||||
|
||||
if prompt == "" then
|
||||
|
|
|
@ -23,7 +23,7 @@ def posh_width [] {
|
|||
}
|
||||
|
||||
# PROMPTS
|
||||
$env.PROMPT_MULTILINE_INDICATOR = (^$_omp_executable print secondary $"--config=($env.POSH_THEME)" --shell=nu $"--shell-version=($env.POSH_SHELL_VERSION)")
|
||||
$env.PROMPT_MULTILINE_INDICATOR = (^$_omp_executable print secondary --shell=nu $"--shell-version=($env.POSH_SHELL_VERSION)")
|
||||
|
||||
$env.PROMPT_COMMAND = { ||
|
||||
# hack to set the cursor line to 1 when the user clears the screen
|
||||
|
@ -37,9 +37,9 @@ $env.PROMPT_COMMAND = { ||
|
|||
do --env $env.SET_POSHCONTEXT
|
||||
}
|
||||
|
||||
^$_omp_executable print primary $"--config=($env.POSH_THEME)" --shell=nu $"--shell-version=($env.POSH_SHELL_VERSION)" $"--execution-time=(posh_cmd_duration)" $"--status=($env.LAST_EXIT_CODE)" $"--terminal-width=(posh_width)" $"--cleared=($clear)"
|
||||
^$_omp_executable print primary --shell=nu $"--shell-version=($env.POSH_SHELL_VERSION)" $"--execution-time=(posh_cmd_duration)" $"--status=($env.LAST_EXIT_CODE)" $"--terminal-width=(posh_width)" $"--cleared=($clear)"
|
||||
}
|
||||
|
||||
$env.PROMPT_COMMAND_RIGHT = { ||
|
||||
^$_omp_executable print right $"--config=($env.POSH_THEME)" --shell=nu $"--shell-version=($env.POSH_SHELL_VERSION)" $"--execution-time=(posh_cmd_duration)" $"--status=($env.LAST_EXIT_CODE)" $"--terminal-width=(posh_width)"
|
||||
^$_omp_executable print right --shell=nu $"--shell-version=($env.POSH_SHELL_VERSION)" $"--execution-time=(posh_cmd_duration)" $"--status=($env.LAST_EXIT_CODE)" $"--terminal-width=(posh_width)"
|
||||
}
|
||||
|
|
|
@ -157,7 +157,7 @@ New-Module -Name "oh-my-posh-core" -ScriptBlock {
|
|||
$cleanPSWD = Get-CleanPSWD
|
||||
$stackCount = global:Get-PoshStackCount
|
||||
|
||||
$standardOut = (Start-Utf8Process $global:_ompExecutable @("print", "tooltip", "--status=$script:ErrorCode", "--shell=$script:ShellName", "--pswd=$cleanPSWD", "--execution-time=$script:ExecutionTime", "--stack-count=$stackCount", "--config=$env:POSH_THEME", "--command=$command", "--shell-version=$script:PSVersion", "--column=$column", "--terminal-width=$terminalWidth", "--no-status=$script:NoExitCode", "--job-count=$script:JobCount")) -join ''
|
||||
$standardOut = (Start-Utf8Process $global:_ompExecutable @("print", "tooltip", "--status=$script:ErrorCode", "--shell=$script:ShellName", "--pswd=$cleanPSWD", "--execution-time=$script:ExecutionTime", "--stack-count=$stackCount", "--command=$command", "--shell-version=$script:PSVersion", "--column=$column", "--terminal-width=$terminalWidth", "--no-status=$script:NoExitCode", "--job-count=$script:JobCount")) -join ''
|
||||
if (!$standardOut) {
|
||||
return
|
||||
}
|
||||
|
@ -227,8 +227,8 @@ New-Module -Name "oh-my-posh-core" -ScriptBlock {
|
|||
}
|
||||
|
||||
function Enable-PoshLineError {
|
||||
$validLine = (Start-Utf8Process $global:_ompExecutable @("print", "valid", "--config=$env:POSH_THEME", "--shell=$script:ShellName")) -join "`n"
|
||||
$errorLine = (Start-Utf8Process $global:_ompExecutable @("print", "error", "--config=$env:POSH_THEME", "--shell=$script:ShellName")) -join "`n"
|
||||
$validLine = (Start-Utf8Process $global:_ompExecutable @("print", "valid", "--shell=$script:ShellName")) -join "`n"
|
||||
$errorLine = (Start-Utf8Process $global:_ompExecutable @("print", "error", "--shell=$script:ShellName")) -join "`n"
|
||||
Set-PSReadLineOption -PromptText $validLine, $errorLine
|
||||
}
|
||||
|
||||
|
@ -267,7 +267,7 @@ New-Module -Name "oh-my-posh-core" -ScriptBlock {
|
|||
$Format = 'json'
|
||||
)
|
||||
|
||||
$configString = Start-Utf8Process $global:_ompExecutable @("config", "export", "--config=$env:POSH_THEME", "--format=$Format")
|
||||
$configString = Start-Utf8Process $global:_ompExecutable @("config", "export", "--format=$Format")
|
||||
# if no path, copy to clipboard by default
|
||||
if ($FilePath) {
|
||||
# https://stackoverflow.com/questions/3038337/powershell-resolve-path-that-might-not-exist
|
||||
|
@ -450,7 +450,7 @@ Example:
|
|||
$env:POSH_CURSOR_LINE = $Host.UI.RawUI.CursorPosition.Y + 1
|
||||
$env:POSH_CURSOR_COLUMN = $Host.UI.RawUI.CursorPosition.X + 1
|
||||
|
||||
$standardOut = Start-Utf8Process $global:_ompExecutable @("print", $script:PromptType, "--status=$script:ErrorCode", "--pswd=$cleanPSWD", "--execution-time=$script:ExecutionTime", "--stack-count=$stackCount", "--config=$env:POSH_THEME", "--shell-version=$script:PSVersion", "--terminal-width=$terminalWidth", "--shell=$script:ShellName", "--no-status=$script:NoExitCode", "--job-count=$script:JobCount")
|
||||
$standardOut = Start-Utf8Process $global:_ompExecutable @("print", $script:PromptType, "--status=$script:ErrorCode", "--pswd=$cleanPSWD", "--execution-time=$script:ExecutionTime", "--stack-count=$stackCount", "--shell-version=$script:PSVersion", "--terminal-width=$terminalWidth", "--shell=$script:ShellName", "--no-status=$script:NoExitCode", "--job-count=$script:JobCount")
|
||||
# make sure PSReadLine knows if we have a multiline prompt
|
||||
Set-PSReadLineOption -ExtraPromptLineCount (($standardOut | Measure-Object -Line).Lines - 1)
|
||||
|
||||
|
@ -467,7 +467,7 @@ Example:
|
|||
$Function:prompt = $promptFunction
|
||||
|
||||
# set secondary prompt
|
||||
Set-PSReadLineOption -ContinuationPrompt ((Start-Utf8Process $global:_ompExecutable @("print", "secondary", "--config=$env:POSH_THEME", "--shell=$script:ShellName")) -join "`n")
|
||||
Set-PSReadLineOption -ContinuationPrompt ((Start-Utf8Process $global:_ompExecutable @("print", "secondary", "--shell=$script:ShellName")) -join "`n")
|
||||
|
||||
# perform cleanup on removal so a new initialization in current session works
|
||||
if (!$script:ConstrainedLanguageMode) {
|
||||
|
|
|
@ -14,11 +14,11 @@ def get_command_context():
|
|||
|
||||
def posh_primary():
|
||||
status, duration = get_command_context()
|
||||
return $(@($POSH_EXECUTABLE) print primary --config=@($POSH_THEME) --shell=xonsh --status=@(status) --execution-time=@(duration) --shell-version=@($POSH_SHELL_VERSION))
|
||||
return $(@($POSH_EXECUTABLE) print primary --shell=xonsh --status=@(status) --execution-time=@(duration) --shell-version=@($POSH_SHELL_VERSION))
|
||||
|
||||
def posh_right():
|
||||
status, duration = get_command_context()
|
||||
return $(@($POSH_EXECUTABLE) print right --config=@($POSH_THEME) --shell=xonsh --status=@(status) --execution-time=@(duration) --shell-version=@($POSH_SHELL_VERSION))
|
||||
return $(@($POSH_EXECUTABLE) print right --shell=xonsh --status=@(status) --execution-time=@(duration) --shell-version=@($POSH_SHELL_VERSION))
|
||||
|
||||
|
||||
$PROMPT = posh_primary
|
||||
|
|
|
@ -5,7 +5,7 @@ setenv POSH_SHELL_VERSION "";
|
|||
set POSH_COMMAND = ::OMP::;
|
||||
set USER_PRECMD = "`alias precmd`";
|
||||
set USER_POSTCMD = "`alias postcmd`";
|
||||
set POSH_PRECMD = 'set POSH_CMD_STATUS = $status;set POSH_END_TIME = `$POSH_COMMAND get millis`;set POSH_DURATION = 0;if ( $POSH_START_TIME != -1 ) @ POSH_DURATION = $POSH_END_TIME - $POSH_START_TIME;set prompt = "`$POSH_COMMAND print primary --shell=tcsh --config=$POSH_THEME --status=$POSH_CMD_STATUS --execution-time=$POSH_DURATION`";set POSH_START_TIME = -1';
|
||||
set POSH_PRECMD = 'set POSH_CMD_STATUS = $status;set POSH_END_TIME = `$POSH_COMMAND get millis`;set POSH_DURATION = 0;if ( $POSH_START_TIME != -1 ) @ POSH_DURATION = $POSH_END_TIME - $POSH_START_TIME;set prompt = "`$POSH_COMMAND print primary --shell=tcsh --status=$POSH_CMD_STATUS --execution-time=$POSH_DURATION`";set POSH_START_TIME = -1';
|
||||
set POSH_POSTCMD = 'set POSH_START_TIME = `$POSH_COMMAND get millis`';
|
||||
|
||||
alias precmd "$POSH_PRECMD;$USER_PRECMD";
|
||||
|
|
|
@ -13,7 +13,7 @@ _omp_cursor_positioning=0
|
|||
_omp_ftcs_marks=0
|
||||
|
||||
# set secondary prompt
|
||||
PS2="$(${_omp_executable} print secondary --config="$POSH_THEME" --shell=zsh)"
|
||||
PS2="$(${_omp_executable} print secondary --shell=zsh)"
|
||||
|
||||
function _omp_set_cursor_position() {
|
||||
# not supported in Midnight Commander
|
||||
|
@ -73,7 +73,7 @@ function _omp_precmd() {
|
|||
set_poshcontext
|
||||
_omp_set_cursor_position
|
||||
|
||||
eval "$(${_omp_executable} print primary --config="$POSH_THEME" --status="$_omp_status_cache" --pipestatus="${_omp_pipestatus_cache[*]}" --execution-time="$_omp_elapsed" --stack-count="$_omp_stack_count" --eval --shell=zsh --shell-version="$ZSH_VERSION" --no-status="$_omp_no_exit_code")"
|
||||
eval "$(${_omp_executable} print primary --status="$_omp_status_cache" --pipestatus="${_omp_pipestatus_cache[*]}" --execution-time="$_omp_elapsed" --stack-count="$_omp_stack_count" --eval --shell=zsh --shell-version="$ZSH_VERSION" --no-status="$_omp_no_exit_code")"
|
||||
unset _omp_start_time
|
||||
}
|
||||
|
||||
|
@ -116,7 +116,7 @@ function _omp_render_tooltip() {
|
|||
fi
|
||||
|
||||
_omp_tooltip_command="$tooltip_command"
|
||||
local tooltip=$(${_omp_executable} print tooltip --config="$POSH_THEME" --status="$_omp_status_cache" --pipestatus="${_omp_pipestatus_cache[*]}" --execution-time="$_omp_elapsed" --stack-count="$_omp_stack_count" --command="$tooltip_command" --shell=zsh --shell-version="$ZSH_VERSION" --no-status="$_omp_no_exit_code")
|
||||
local tooltip=$(${_omp_executable} print tooltip --status="$_omp_status_cache" --pipestatus="${_omp_pipestatus_cache[*]}" --execution-time="$_omp_elapsed" --stack-count="$_omp_stack_count" --command="$tooltip_command" --shell=zsh --shell-version="$ZSH_VERSION" --no-status="$_omp_no_exit_code")
|
||||
if [[ -z "$tooltip" ]]; then
|
||||
return
|
||||
fi
|
||||
|
@ -135,7 +135,7 @@ function _omp_zle-line-init() {
|
|||
(( $+zle_bracketed_paste )) && print -r -n - $zle_bracketed_paste[2]
|
||||
|
||||
_omp_tooltip_command=''
|
||||
eval "$(${_omp_executable} print transient --config="$POSH_THEME" --status="$_omp_status_cache" --pipestatus="${_omp_pipestatus_cache[*]}" --execution-time="$_omp_elapsed" --stack-count="$_omp_stack_count" --eval --shell=zsh --shell-version="$ZSH_VERSION" --no-status="$_omp_no_exit_code")"
|
||||
eval "$(${_omp_executable} print transient --status="$_omp_status_cache" --pipestatus="${_omp_pipestatus_cache[*]}" --execution-time="$_omp_elapsed" --stack-count="$_omp_stack_count" --eval --shell=zsh --shell-version="$ZSH_VERSION" --no-status="$_omp_no_exit_code")"
|
||||
zle .reset-prompt
|
||||
|
||||
# Exit the shell if we receive EOT.
|
||||
|
|
Loading…
Reference in a new issue