Skip to content

Commit d76c48d

Browse files
committed
fix(status): reset .Executed per prompt in cmd, bash and nushell
.Executed only turned false when the shell started, never again after the first real command ran, so pressing enter on an empty line kept the status segment visible. pwsh, zsh and fish already re-evaluate it every prompt; bring clink, bash and nushell in line: - clink: command_executed_mark now sets no_exit_code from the current input instead of only ever clearing it. - bash: _omp_hook resets _omp_no_status=true before checking whether a command actually started, mirroring the zsh precmd hook. - nushell: derive --no-status from whether history actually grew this prompt cycle instead of the one-shot CMD_DURATION_MS startup sentinel, which can't observe anything after the first command. Fixes #7757 Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018AhjcGCfxm2mFCfZhehLhv
1 parent c79d69d commit d76c48d

3 files changed

Lines changed: 22 additions & 6 deletions

File tree

src/shell/scripts/omp.bash

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ function _omp_hook() {
162162
_omp_job_count=${#_omp_jobs[@]}
163163

164164
_omp_execution_time=-1
165+
_omp_no_status=true
165166
if [[ $_omp_start_time ]]; then
166167
local omp_now=$(_omp_milliseconds)
167168
_omp_execution_time=$((omp_now - _omp_start_time))

src/shell/scripts/omp.lua

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -376,9 +376,7 @@ local function url_encode(str)
376376
end
377377

378378
local function command_executed_mark(input)
379-
if string.gsub(input, '^%s*(.-)%s*$', '%1') ~= '' then
380-
no_exit_code = false
381-
end
379+
no_exit_code = string.gsub(input, '^%s*(.-)%s*$', '%1') == ''
382380

383381
if not ftcs_marks_enabled then
384382
return

src/shell/scripts/omp.nu

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,22 @@ def --wrapped _omp_get_prompt [
3535
$ms => { $ms | into int }
3636
}
3737

38+
# `$env.POSH_EXECUTED` is set once per prompt cycle in `$env.PROMPT_COMMAND`, based on
39+
# whether history actually grew. Falls back to the execution-time sentinel when history
40+
# is disabled, which only detects a freshly started shell.
41+
let no_status = if $nu.history-enabled {
42+
not ($env.POSH_EXECUTED? | default false)
43+
} else {
44+
$execution_time < 0
45+
}
46+
3847
(
3948
^$_omp_executable print $type
4049
--save-cache
4150
--shell=nu
4251
$"--shell-version=($env.POSH_SHELL_VERSION)"
4352
$"--status=($env.LAST_EXIT_CODE)"
44-
$"--no-status=($execution_time < 0)"
53+
$"--no-status=($no_status)"
4554
$"--execution-time=($execution_time)"
4655
$"--terminal-width=((term size).columns)"
4756
$"--job-count=(job list | length)"
@@ -56,16 +65,24 @@ $env.PROMPT_MULTILINE_INDICATOR = (
5665
)
5766

5867
$env.PROMPT_COMMAND = {||
68+
let hist = if $nu.history-enabled { history } else { [] }
69+
let hist_len = ($hist | length)
70+
5971
# hack: sets cursor line to 1 on clear; not bulletproof, just a start
6072
let clear = $nu.history-enabled and (
61-
(history | is-empty)
62-
or (history | last | get command?) == "clear"
73+
($hist | is-empty)
74+
or ($hist | last | get command?) == "clear"
6375
)
6476

6577
if ($env.SET_POSHCONTEXT? | is-not-empty) {
6678
do --env $env.SET_POSHCONTEXT
6779
}
6880

81+
# a command was executed this prompt cycle only if history actually grew;
82+
# an empty Enter (or history disabled) leaves the length unchanged
83+
$env.POSH_EXECUTED = ($nu.history-enabled and ($hist_len > ($env.POSH_LAST_HISTORY_LEN? | default 0)))
84+
$env.POSH_LAST_HISTORY_LEN = $hist_len
85+
6986
_omp_get_prompt primary $"--cleared=($clear)"
7087
}
7188

0 commit comments

Comments
 (0)