From ab1d200513f9336467d7b92507f0019ba43a849a Mon Sep 17 00:00:00 2001 From: Ilan Cosman Date: Thu, 14 May 2020 21:53:37 -0700 Subject: [PATCH] Multi-line right prompt --- functions/_lean_cmd_duration.fish | 2 +- functions/_lean_context.fish | 4 +-- functions/_lean_git_prompt.fish | 2 +- functions/_lean_jobs.fish | 2 +- functions/_lean_newline.fish | 3 +++ functions/_lean_prompt_char.fish | 8 ++++++ functions/_lean_pwd.fish | 1 + functions/_lean_status.fish | 2 +- functions/_lean_time.fish | 1 + functions/_up.fish | 5 ++++ functions/fish_prompt.fish | 23 +++++----------- functions/lean_left_prompt.fish | 7 ++++- functions/lean_right_prompt.fish | 26 ++++++++++++++++++- .../prompt_modules/fish_prompt/3_1Line.fish | 2 +- yeet | 1 + 15 files changed, 64 insertions(+), 25 deletions(-) create mode 100644 functions/_lean_newline.fish create mode 100644 functions/_lean_prompt_char.fish create mode 100644 functions/_up.fish create mode 100644 yeet diff --git a/functions/_lean_cmd_duration.fish b/functions/_lean_cmd_duration.fish index 8d56c9c..0872b03 100644 --- a/functions/_lean_cmd_duration.fish +++ b/functions/_lean_cmd_duration.fish @@ -15,6 +15,6 @@ function _lean_cmd_duration end set_color $lean_cmd_duration_color - echo -n {$hours}'h' {$minutes}'m' {$seconds}'s' + echo -n {$hours}'h' {$minutes}'m' {$seconds}'s'' ' end end \ No newline at end of file diff --git a/functions/_lean_context.fish b/functions/_lean_context.fish index 6c44ddb..3241e65 100644 --- a/functions/_lean_context.fish +++ b/functions/_lean_context.fish @@ -1,9 +1,9 @@ function _lean_context if set -q SSH_TTY set_color $lean_context_ssh_color - echo -n $USER'@'(prompt_hostname) + echo -n $USER'@'(prompt_hostname)' ' else if test $USER = 'root' set_color $lean_context_root_color - echo -n $USER'@'(prompt_hostname) + echo -n $USER'@'(prompt_hostname)' ' end end \ No newline at end of file diff --git a/functions/_lean_git_prompt.fish b/functions/_lean_git_prompt.fish index ca73fab..6515715 100644 --- a/functions/_lean_git_prompt.fish +++ b/functions/_lean_git_prompt.fish @@ -4,5 +4,5 @@ function _lean_git_prompt set -l gitPrompt (string replace '(' '' $gitPrompt) set -l gitPrompt (string replace ')' '' $gitPrompt) - string trim $gitPrompt + echo -n (string trim $gitPrompt)' ' end \ No newline at end of file diff --git a/functions/_lean_jobs.fish b/functions/_lean_jobs.fish index 9adc782..1575475 100644 --- a/functions/_lean_jobs.fish +++ b/functions/_lean_jobs.fish @@ -1,6 +1,6 @@ function _lean_jobs if jobs -q set_color $lean_jobs_color - echo -n $lean_jobs_icon + echo -n "$lean_jobs_icon"' ' end end \ No newline at end of file diff --git a/functions/_lean_newline.fish b/functions/_lean_newline.fish new file mode 100644 index 0000000..20dc3da --- /dev/null +++ b/functions/_lean_newline.fish @@ -0,0 +1,3 @@ +function _lean_newline + echo -n '\n' +end \ No newline at end of file diff --git a/functions/_lean_prompt_char.fish b/functions/_lean_prompt_char.fish new file mode 100644 index 0000000..06c893f --- /dev/null +++ b/functions/_lean_prompt_char.fish @@ -0,0 +1,8 @@ +function _lean_prompt_char + if test $last_status -eq 0 + set_color $lean_color_green + else + set_color $fish_color_error + end + echo -n '❯ ' +end \ No newline at end of file diff --git a/functions/_lean_pwd.fish b/functions/_lean_pwd.fish index b00cb51..1ce7cf6 100644 --- a/functions/_lean_pwd.fish +++ b/functions/_lean_pwd.fish @@ -35,6 +35,7 @@ function _lean_pwd echo -n $splitPwd[-1] set_color $fish_color_normal end + echo -n ' ' end function _shorten_pwd diff --git a/functions/_lean_status.fish b/functions/_lean_status.fish index 4e24004..20d3452 100644 --- a/functions/_lean_status.fish +++ b/functions/_lean_status.fish @@ -10,7 +10,7 @@ function _lean_status set_color $lean_status_failure_color echo -n {$lean_status_failure_icon}' ' end - string join '|' (string replace 'SIG' '' $fishPipestatusWithSignal) + echo -n (string join '|' (string replace 'SIG' '' $fishPipestatusWithSignal))' ' end end end \ No newline at end of file diff --git a/functions/_lean_time.fish b/functions/_lean_time.fish index 8bc32de..cdefe5e 100644 --- a/functions/_lean_time.fish +++ b/functions/_lean_time.fish @@ -1,4 +1,5 @@ function _lean_time set_color $lean_time_color date +$lean_time_format + echo -n ' ' end \ No newline at end of file diff --git a/functions/_up.fish b/functions/_up.fish new file mode 100644 index 0000000..0a1de18 --- /dev/null +++ b/functions/_up.fish @@ -0,0 +1,5 @@ +function _up -a number + if test $number -ne 0 + echo -ne '\033['$number'A' + end +end \ No newline at end of file diff --git a/functions/fish_prompt.fish b/functions/fish_prompt.fish index 0779ffd..75b8341 100644 --- a/functions/fish_prompt.fish +++ b/functions/fish_prompt.fish @@ -3,27 +3,18 @@ function fish_prompt --description 'Write out the prompt' set -g last_pipestatus $pipestatus set -g last_status $status - echo + if test "$lean_newline" = 'true' + echo + end set_color $lean_prompt_connection_color printf "%.s$lean_prompt_connection_icon" (seq $COLUMNS) set_color $fish_color_normal + printf '\r' + lean_right_prompt + _up $leftPromptHeight + printf '\r' lean_left_prompt - - set -l rightPrompt (lean_right_prompt) - set -l rightPromptStartLocation (math $COLUMNS-(string length (lean_decolor $rightPrompt))) - printf '\r\033['$rightPromptStartLocation'C' - echo $rightPrompt - - # Prompt character - if test $last_status -eq 0 - set_color $lean_color_green - else - set_color $fish_color_error - end - echo -n '❯ ' - set_color $fish_color_normal end - diff --git a/functions/lean_left_prompt.fish b/functions/lean_left_prompt.fish index 0b2b5a4..fa0e63c 100644 --- a/functions/lean_left_prompt.fish +++ b/functions/lean_left_prompt.fish @@ -1,9 +1,14 @@ function lean_left_prompt + set -U leftPromptHeight 1 + for item in lean_{$lean_left_prompt_items} set -l itemOutput (_$item) if test -n "$itemOutput" - echo -n $itemOutput' ' + echo -ne $itemOutput + end + if test $item = 'lean_newline' + set -U leftPromptHeight (math $leftPromptHeight+1) end set_color normal diff --git a/functions/lean_right_prompt.fish b/functions/lean_right_prompt.fish index 2f3f595..89e34c5 100644 --- a/functions/lean_right_prompt.fish +++ b/functions/lean_right_prompt.fish @@ -1,13 +1,37 @@ function lean_right_prompt + set -l splitText (string split '\n' (_fetch_right_prompt_items)) + for thing in $splitText[1..-2] + _print_at_end $thing + end + if test (count $splitText) -eq $leftPromptHeight + set -g fishRightPromptRun $splitText[-1] + else + _print_at_end $splitText[-1] + set -g fishRightPromptRun '' + end + echo +end + +function fish_right_prompt + echo $fishRightPromptRun +end + +function _fetch_right_prompt_items echo -n ' ' for item in lean_{$lean_right_prompt_items} set -l itemOutput (_$item) if test -n "$itemOutput" - echo -n $itemOutput' ' + echo -n $itemOutput end set_color normal end +end + +function _print_at_end -a text + set -l startLocation (math $COLUMNS-(string length (lean_decolor $text))) + echo -ne '\033['$startLocation'C' + echo $text end \ No newline at end of file diff --git a/lean_theme/prompt_modules/fish_prompt/3_1Line.fish b/lean_theme/prompt_modules/fish_prompt/3_1Line.fish index e201199..cbb17ac 100644 --- a/lean_theme/prompt_modules/fish_prompt/3_1Line.fish +++ b/lean_theme/prompt_modules/fish_prompt/3_1Line.fish @@ -1 +1 @@ - echo -n (lean_pwd)(lean_git_prompt)' ' \ No newline at end of file + lean_left_prompt \ No newline at end of file diff --git a/yeet b/yeet new file mode 100644 index 0000000..c215ede --- /dev/null +++ b/yeet @@ -0,0 +1 @@ +master(B !1(B ?2(B