mirror of
https://github.com/fish-shell/fish-shell
synced 2025-01-13 21:44:16 +00:00
Merge pull request #5709 from zabereer/prompts_with_pipestatus
Prompts with pipestatus
This commit is contained in:
commit
a7a12c5c96
7 changed files with 58 additions and 5 deletions
5
share/functions/__fish_pipestatus_with_signal.fish
Normal file
5
share/functions/__fish_pipestatus_with_signal.fish
Normal file
|
@ -0,0 +1,5 @@
|
|||
function __fish_pipestatus_with_signal --description "Print arguments from \$pipestatus replacing values with signal names where appropriate"
|
||||
for pstat in $argv
|
||||
__fish_status_to_signal $pstat
|
||||
end
|
||||
end
|
17
share/functions/__fish_print_pipestatus.fish
Normal file
17
share/functions/__fish_print_pipestatus.fish
Normal file
|
@ -0,0 +1,17 @@
|
|||
function __fish_print_pipestatus --description "Print pipestatus for prompt"
|
||||
set -l left_brace $argv[1]
|
||||
set -l right_brace $argv[2]
|
||||
set -l separator $argv[3]
|
||||
set -l brace_sep_color $argv[4]
|
||||
set -l status_color $argv[5]
|
||||
set -e argv[1 2 3 4 5]
|
||||
|
||||
# only output $pipestatus if there was a pipe and any part of it had non-zero exit status
|
||||
if set -q argv[2] && string match -qvr '^0$' $argv
|
||||
set -l sep (set_color normal){$brace_sep_color}{$separator}(set_color normal){$status_color}
|
||||
set -l last_pipestatus_string (string join "$sep" (__fish_pipestatus_with_signal $argv))
|
||||
printf "%s%s%s%s%s%s%s%s%s%s" (set_color normal )$brace_sep_color $left_brace \
|
||||
(set_color normal) $status_color $last_pipestatus_string (set_color normal) \
|
||||
$brace_sep_color $right_brace (set_color normal)
|
||||
end
|
||||
end
|
22
share/functions/__fish_status_to_signal.fish
Normal file
22
share/functions/__fish_status_to_signal.fish
Normal file
|
@ -0,0 +1,22 @@
|
|||
function __fish_status_to_signal --description "Print signal name from argument (\$status), or just argument"
|
||||
if test (count $argv) -ne 1
|
||||
echo "expected single argument as integer from \$status" >&2
|
||||
return 1
|
||||
end
|
||||
|
||||
if test $argv[1] -gt 128
|
||||
set -l signals SIGHUP SIGINT SIGQUIT SIGILL SIGTRAP SIGABRT SIGBUS \
|
||||
SIGFPE SIGKILL SIGUSR1 SIGSEGV SIGUSR2 SIGPIPE SIGALRM \
|
||||
SIGTERM SIGSTKFLT SIGCHLD SIGCONT SIGSTOP SIGTSTP \
|
||||
SIGTTIN SIGTTOU SIGURG SIGXCPU SIGXFSZ SIGVTALRM \
|
||||
SIGPROF SIGWINCH SIGIO SIGPWR SIGSYS
|
||||
set -l sigix (math $argv[1] - 128)
|
||||
if test $sigix -le (count $signals)
|
||||
echo $signals[$sigix]
|
||||
return 0
|
||||
end
|
||||
end
|
||||
|
||||
echo $argv[1]
|
||||
return 0
|
||||
end
|
|
@ -3,10 +3,13 @@
|
|||
|
||||
function fish_prompt --description "Write out the prompt"
|
||||
# Save our status
|
||||
set -l last_pipestatus $pipestatus
|
||||
set -l last_status $status
|
||||
|
||||
__fish_print_pipestatus "[" "] " "|" (set_color yellow) (set_color --bold yellow) $last_pipestatus
|
||||
|
||||
if test $last_status -ne 0
|
||||
printf "%s(%d)%s " (set_color red --bold) $last_status (set_color normal)
|
||||
printf "%s(%s)%s " (set_color red --bold) (__fish_status_to_signal $last_status) (set_color normal)
|
||||
end
|
||||
|
||||
set -l color_cwd
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
# vim: set noet:
|
||||
|
||||
function fish_prompt --description 'Write out the prompt'
|
||||
set -l last_pipestatus $pipestatus
|
||||
set -l last_status $status
|
||||
set -l normal (set_color normal)
|
||||
|
||||
|
@ -62,9 +63,9 @@ function fish_prompt --description 'Write out the prompt'
|
|||
set suffix '>'
|
||||
end
|
||||
|
||||
set -l prompt_status
|
||||
set -l prompt_status (__fish_print_pipestatus "[" "] " "|" (set_color yellow) (set_color --bold yellow) $last_pipestatus)
|
||||
if test $last_status -ne 0
|
||||
set prompt_status ' ' (set_color $fish_color_status) "[$last_status]" "$normal"
|
||||
set prompt_status " $prompt_status" (set_color $fish_color_status) "[$last_status]" "$normal"
|
||||
end
|
||||
|
||||
echo -n -s (set_color $fish_color_user) "$USER" $normal @ (set_color $fish_color_host) (prompt_hostname) $normal ' ' (set_color $color_cwd) (prompt_pwd) $normal (fish_vcs_prompt) $normal $prompt_status $suffix " "
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
function fish_prompt --description 'Write out the prompt'
|
||||
#Save the return status of the previous command
|
||||
set -l last_pipestatus $pipestatus
|
||||
set stat $status
|
||||
|
||||
if not set -q __fish_prompt_normal
|
||||
|
@ -39,8 +40,8 @@ function fish_prompt --description 'Write out the prompt'
|
|||
if not set -q __fish_prompt_cwd
|
||||
set -g __fish_prompt_cwd (set_color $fish_color_cwd)
|
||||
end
|
||||
|
||||
printf '[%s] %s%s@%s %s%s %s(%s)%s \f\r> ' (date "+%H:%M:%S") "$__fish_color_blue" $USER (prompt_hostname) "$__fish_prompt_cwd" "$PWD" "$__fish_color_status" "$stat" "$__fish_prompt_normal"
|
||||
set -l pipestatus_string (__fish_print_pipestatus "[" "] " "|" (set_color yellow) (set_color --bold yellow) $last_pipestatus)
|
||||
printf '[%s] %s%s@%s %s%s %s%s(%s)%s \f\r> ' (date "+%H:%M:%S") "$__fish_color_blue" $USER (prompt_hostname) "$__fish_prompt_cwd" "$PWD" "$pipestatus_string" "$__fish_color_status" "$stat" "$__fish_prompt_normal"
|
||||
|
||||
end
|
||||
end
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
|
||||
function fish_prompt --description 'Write out the prompt'
|
||||
set -l last_pipestatus $pipestatus
|
||||
set -l last_status $status
|
||||
|
||||
if not set -q __fish_git_prompt_show_informative_status
|
||||
|
@ -88,6 +89,9 @@ function fish_prompt --description 'Write out the prompt'
|
|||
|
||||
printf '%s ' (fish_vcs_prompt)
|
||||
|
||||
set -l pipestatus_string (__fish_print_pipestatus "[" "] " "|" (set_color yellow) (set_color --bold yellow) $last_pipestatus)
|
||||
echo -n "$pipestatus_string"
|
||||
|
||||
if not test $last_status -eq 0
|
||||
set_color $fish_color_error
|
||||
echo -n "[$last_status] "
|
||||
|
|
Loading…
Reference in a new issue