From e68ee511731d8df9dbbc80a38cefeaaf5ea95ea0 Mon Sep 17 00:00:00 2001 From: Ilan Cosman Date: Wed, 29 Apr 2020 12:32:59 -0700 Subject: [PATCH] Add status item --- functions/fish_prompt.fish | 8 ++++---- functions/lean_load_right_prompt_items.fish | 17 +++++++++++++++++ functions/lean_uninstall.fish | 2 ++ install.fish | 17 +++++++++++------ .../prompt_modules/fake_prompt/1_initial.fish | 4 +++- .../prompt_modules/fake_prompt/4_final.fish | 2 +- .../prompt_modules/fish_prompt/1_initial.fish | 3 ++- .../prompt_modules/fish_prompt/4_final.fish | 2 +- 8 files changed, 41 insertions(+), 14 deletions(-) diff --git a/functions/fish_prompt.fish b/functions/fish_prompt.fish index 4b1402a..45fe5c1 100644 --- a/functions/fish_prompt.fish +++ b/functions/fish_prompt.fish @@ -1,6 +1,7 @@ # Created by lean_wizard function fish_prompt --description 'Write out the prompt' - set -l lastExitCode $status + set -g last_pipestatus $pipestatus + set -g last_status $status echo @@ -16,7 +17,7 @@ function fish_prompt --description 'Write out the prompt' echo -e (lean_right_prompt) # Prompt character - if test $lastExitCode -eq 0 + if test $last_status -eq 0 set_color $lean_color_green else set_color $fish_color_error @@ -27,7 +28,7 @@ end function _lean_right_prompt_nocolor echo -n " " - + for item in lean_{$lean_right_prompt_items} if test -n "$$item" echo -n "$$item" @@ -36,4 +37,3 @@ function _lean_right_prompt_nocolor end end - diff --git a/functions/lean_load_right_prompt_items.fish b/functions/lean_load_right_prompt_items.fish index 14e39f9..de486d9 100644 --- a/functions/lean_load_right_prompt_items.fish +++ b/functions/lean_load_right_prompt_items.fish @@ -4,6 +4,23 @@ function lean_load_right_prompt_items end end +function _lean_status + if string match -q --invert "0" $last_pipestatus + set -l fishPipestatusWithSignal (__fish_pipestatus_with_signal $last_pipestatus) + + if test (count $last_pipestatus) -gt 1 || string match -qe "SIG" $fishPipestatusWithSignal + if test $last_status -eq 0 + set -g lean_status_color $lean_status_success_color + echo -n "$lean_status_success_icon " + else + set -g lean_status_color $lean_status_failure_color + echo -n "$lean_status_failure_icon " + end + string join "|" (string replace "SIG" "" $fishPipestatusWithSignal) + end + end +end + function _lean_timer if test (math $CMD_DURATION/1000) -gt $lean_timer_duration echo -n (math --scale=$lean_timer_decimals $CMD_DURATION/1000)"s" diff --git a/functions/lean_uninstall.fish b/functions/lean_uninstall.fish index 58894cf..0ba6dc8 100644 --- a/functions/lean_uninstall.fish +++ b/functions/lean_uninstall.fish @@ -35,6 +35,8 @@ function lean_uninstall # ----------------Right Prompt Items---------------- set -a rmVars lean_right_prompt_items + # --------------Status-------------- + set -a rmVars lean_status_{success_icon, success_color, failure_icon, failure_color} # --------------Timer-------------- set -a rmVars lean_timer_{color, decimals, duration} # ---------------SSH--------------- diff --git a/install.fish b/install.fish index d4831ab..8b4c480 100644 --- a/install.fish +++ b/install.fish @@ -28,7 +28,7 @@ function lean_install set -U lean_color_gold D7AF00 # ---------------Pwd--------------- set -U lean_pwd_shorten_margin 5 - set -U lean_pwd_unwritable_icon  # Lock + set -U lean_pwd_unwritable_icon "" # Lock # ------------Git prompt------------ set -U __fish_git_prompt_show_informative_status true set -U __fish_git_prompt_showstashstate true @@ -38,8 +38,8 @@ function lean_install set -U __fish_git_prompt_char_upstream_ahead " ⇡" set -U __fish_git_prompt_char_upstream_behind " ⇣" set -U __fish_git_prompt_char_stagedstate " +" - set -U __fish_git_prompt_char_dirtystate ' !' - set -U __fish_git_prompt_char_untrackedfiles ' ?' + set -U __fish_git_prompt_char_dirtystate " !" + set -U __fish_git_prompt_char_untrackedfiles " ?" set -U __fish_git_prompt_char_stashstate " *" # --------Colors-------- set -U __fish_git_prompt_color_branch $lean_color_green @@ -50,7 +50,12 @@ function lean_install set -U __fish_git_prompt_color_stashstate $lean_color_green # ----------------Right Prompt Items---------------- - set -U lean_right_prompt_items timer context jobs + set -U lean_right_prompt_items "status" "timer" "context" "jobs" + # --------------Status-------------- + set -U lean_status_success_icon "✔" + set -U lean_status_success_color 5FAF00 + set -U lean_status_failure_icon "✘" + set -U lean_status_failure_color D70000 # --------------Timer-------------- set -U lean_timer_color 87875F set -U lean_timer_decimals 0 @@ -59,7 +64,7 @@ function lean_install set -U lean_context_ssh_color D7AF87 set -U lean_context_root_color D7AF00 # ---------------Jobs--------------- - set -U lean_jobs_icon  # Gear + set -U lean_jobs_icon "" # Gear set -U lean_jobs_color 5FAF00 # -----------------------Finish----------------------- @@ -85,7 +90,7 @@ function _user_confirm_defaultYes -a question return 0 case n N no No return 1 - case '' + case "" return 0 end end diff --git a/lean_theme/prompt_modules/fake_prompt/1_initial.fish b/lean_theme/prompt_modules/fake_prompt/1_initial.fish index 91863c6..42686fa 100644 --- a/lean_theme/prompt_modules/fake_prompt/1_initial.fish +++ b/lean_theme/prompt_modules/fake_prompt/1_initial.fish @@ -1,2 +1,4 @@ +# Created by lean_wizard function fake_prompt --description 'Write out the prompt' - set -l lastExitCode $status \ No newline at end of file + set -g last_pipestatus $pipestatus + set -g last_status $status \ No newline at end of file diff --git a/lean_theme/prompt_modules/fake_prompt/4_final.fish b/lean_theme/prompt_modules/fake_prompt/4_final.fish index a3bea46..1c8748d 100644 --- a/lean_theme/prompt_modules/fake_prompt/4_final.fish +++ b/lean_theme/prompt_modules/fake_prompt/4_final.fish @@ -1,5 +1,5 @@ # Prompt character - if test $lastExitCode -eq 0 + if test $last_status -eq 0 set_color $lean_color_green else set_color $fish_color_error diff --git a/lean_theme/prompt_modules/fish_prompt/1_initial.fish b/lean_theme/prompt_modules/fish_prompt/1_initial.fish index 6f4b960..ef281bd 100644 --- a/lean_theme/prompt_modules/fish_prompt/1_initial.fish +++ b/lean_theme/prompt_modules/fish_prompt/1_initial.fish @@ -1,3 +1,4 @@ # Created by lean_wizard function fish_prompt --description 'Write out the prompt' - set -l lastExitCode $status \ No newline at end of file + set -g last_pipestatus $pipestatus + set -g last_status $status \ No newline at end of file diff --git a/lean_theme/prompt_modules/fish_prompt/4_final.fish b/lean_theme/prompt_modules/fish_prompt/4_final.fish index a3bea46..1c8748d 100644 --- a/lean_theme/prompt_modules/fish_prompt/4_final.fish +++ b/lean_theme/prompt_modules/fish_prompt/4_final.fish @@ -1,5 +1,5 @@ # Prompt character - if test $lastExitCode -eq 0 + if test $last_status -eq 0 set_color $lean_color_green else set_color $fish_color_error