Generalize prompt items, add left_prompt

This commit is contained in:
Ilan Cosman 2020-05-13 12:46:42 -07:00
parent 859600359c
commit 9b3ec5eabe
10 changed files with 70 additions and 5 deletions

View File

@ -0,0 +1,16 @@
function _lean_cmd_duration
if test $CMD_DURATION -gt $lean_cmd_duration_threshold
set -l seconds (math --scale=$lean_cmd_duration_decimals "$CMD_DURATION/1000" % 60)
set -l minutes (math -s0 "$seconds/60" % 60)
set -l hours (math -s0 "$minutes/60" % 60)
for time in hours minutes seconds
if test $$time -eq 0
set -e $time
end
end
set_color $lean_cmd_duration_color
echo -n {$hours}'h' {$minutes}'m' {$seconds}'s'
end
end

View File

@ -0,0 +1,9 @@
function _lean_context
if set -q SSH_TTY
set_color $lean_context_ssh_color
echo -n $USER'@'(prompt_hostname)
else if test $USER = 'root'
set_color $lean_context_root_color
echo -n $USER'@'(prompt_hostname)
end
end

View File

@ -1,8 +1,8 @@
function lean_git_prompt
function _lean_git_prompt
set -l gitPrompt (fish_git_prompt)
set -l gitPrompt (string replace '(' '' $gitPrompt)
set -l gitPrompt (string replace ')' '' $gitPrompt)
echo $gitPrompt
string trim $gitPrompt
end

View File

@ -0,0 +1,6 @@
function _lean_jobs
if jobs -q
set_color $lean_jobs_color
echo -n $lean_jobs_icon
end
end

View File

@ -1,4 +1,4 @@
function lean_pwd
function _lean_pwd
set -l splitPwd (string split --no-empty '/' (_shorten_pwd))
set -l splitPwdLength (count $splitPwd)

View File

@ -0,0 +1,16 @@
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_color $lean_status_success_color
echo -n {$lean_status_success_icon}' '
else
set_color $lean_status_failure_color
echo -n {$lean_status_failure_icon}' '
end
string join '|' (string replace 'SIG' '' $fishPipestatusWithSignal)
end
end
end

View File

@ -0,0 +1,4 @@
function _lean_time
set_color $lean_time_color
date +$lean_time_format
end

View File

@ -9,7 +9,8 @@ function fish_prompt --description 'Write out the prompt'
printf "%.s$lean_prompt_connection_icon" (seq $COLUMNS)
set_color $fish_color_normal
echo -ne '\r'(lean_pwd)(lean_git_prompt)' '
printf '\r'
lean_left_prompt
set -l rightPrompt (lean_right_prompt)
set -l rightPromptStartLocation (math $COLUMNS-(string length (lean_decolor $rightPrompt)))
@ -25,3 +26,4 @@ function fish_prompt --description 'Write out the prompt'
echo -n ' '
set_color $fish_color_normal
end

View File

@ -0,0 +1,11 @@
function lean_left_prompt
for item in lean_{$lean_left_prompt_items}
set -l itemOutput (_$item)
if test -n "$itemOutput"
echo -n $itemOutput' '
end
set_color normal
end
end

View File

@ -2,7 +2,8 @@
printf "%.s$lean_prompt_connection_icon" (seq $COLUMNS)
set_color $fish_color_normal
echo -ne '\r'(lean_pwd)(lean_git_prompt)' '
printf '\r'
lean_left_prompt
set -l rightPrompt (lean_right_prompt)
set -l rightPromptStartLocation (math $COLUMNS-(string length (lean_decolor $rightPrompt)))