Skip to content

Commit

Permalink
fish prompt: preserve pipestatus (#1530)
Browse files Browse the repository at this point in the history
The upcoming release fish 3.1.0 provides a variable $pipestatus, that
exposes the exit code of each process in a pipeline. This $pipestatus
is also used by the new default prompt.

Presently, $status is restored but not $pipestatus, so a prompt displaying
the pipestatus is wrong:

expected:

	(env) $ false | true | false
	(env) [1|0|1] $

actual:

	(env) $ false | true | false
	(env) [0|1] $

The wrong $pipestatus is because `echo 'exit 1' | source` is used
to restore the $status.
This commit solves this problem more elegantly by running the user's
prompt immediately, and printing it later.
Uses the fish builtin "string" command which exists since fish 2.3b1
(released April 19, 2016) so that's unlikely to cause problems.
  • Loading branch information
krobelus authored Jan 30, 2020
1 parent 9d37eb3 commit 5f802b0
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions src/virtualenv/activation/fish/activate.fish
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ if test -z "$VIRTUAL_ENV_DISABLE_PROMPT"
functions -c fish_prompt _old_fish_prompt

function fish_prompt
# Save the current $status, for fish_prompts that display it.
set -l old_status $status
# Run the user's prompt first; it might depend on (pipe)status.
set -l prompt (_old_fish_prompt)

# Prompt override provided?
# If not, just prepend the environment name.
Expand All @@ -93,9 +93,7 @@ if test -z "$VIRTUAL_ENV_DISABLE_PROMPT"
printf '%s(%s) ' (set_color normal) (basename '$VIRTUAL_ENV')
end

# Restore the original $status
echo "exit $old_status" | source
_old_fish_prompt
string join -- \n $prompt # handle multi-line prompts
end

set -gx _OLD_FISH_PROMPT_OVERRIDE "$VIRTUAL_ENV"
Expand Down

0 comments on commit 5f802b0

Please sign in to comment.