Use one prompt variable instead of two (closes #171)

This commit is contained in:
Ilan Cosman 2021-08-13 04:28:09 -07:00
parent 733ad697c1
commit 26485519ba
3 changed files with 12 additions and 13 deletions

View File

@ -1,6 +1,4 @@
function _tide_prompt
test "$tide_prompt_add_newline_before" = true && echo
left_prompt=(_tide_left_prompt) right_prompt=(_tide_right_prompt) if set -q left_prompt[2] # If prompt is two lines
set -l prompt_and_frame_color (set_color $tide_prompt_color_frame_and_connection -b normal)
if test "$tide_left_prompt_frame_enabled" = true
@ -12,20 +10,20 @@ function _tide_prompt
set right_prompt[2] "$right_prompt[2]"$prompt_and_frame_color─╯
end
echo $right_prompt[2]
set -lx dist_btwn_sides (math $COLUMNS + 5 - ( # Regex removes color. 5 = @PWD@ length which will be replaced
string replace -ar '\e(\[[\d;]*|\(B\e\[)m(\co)?' '' "$left_prompt[1]""$right_prompt[1]" | string length))
printf '%s' (string replace @PWD@ (_tide_pwd) "$left_prompt[1]") $prompt_and_frame_color
string repeat --no-newline --max (math max 0, $dist_btwn_sides - $pwd_length) $tide_prompt_icon_connection
printf '%s' $right_prompt[1] \n $left_prompt[2]' '
set -U $_tide_right_prompt_display_var $right_prompt[2]
else
echo $right_prompt[1]
set -lx dist_btwn_sides (math $COLUMNS + 5 -$tide_prompt_min_cols - (
string replace -ar '\e(\[[\d;]*|\(B\e\[)m(\co)?' '' "$left_prompt[1]""$right_prompt[1]" | string length))
string replace @PWD@ (_tide_pwd) "$left_prompt[1] "
set -U $_tide_right_prompt_display_var $right_prompt[1]
end
end

View File

@ -5,11 +5,11 @@ status is-interactive || exit
_tide_remove_unusable_items
set -g _tide_left_prompt_display_var _tide_left_prompt_display_$fish_pid
set -gx _tide_right_prompt_display_var _tide_right_prompt_display_$fish_pid
set -g _tide_prompt_var _tide_prompt_$fish_pid
function _tide_refresh_prompt --on-variable $_tide_left_prompt_display_var --on-variable $_tide_right_prompt_display_var
function _tide_refresh_prompt --on-variable $_tide_prompt_var
set -g _tide_self_repainting # prevents us from creating a second background job
set -g _tide_prompt_data $$_tide_prompt_var # First element in _tide_prompt_data is 'actual' right prompt
commandline --function repaint
end
@ -17,16 +17,17 @@ function fish_prompt
_tide_last_status=$status _tide_last_pipestatus=$pipestatus if not set -e _tide_self_repainting
jobs --query
fish --command "_tide_jobs_status=$status CMD_DURATION=$CMD_DURATION COLUMNS=$COLUMNS \
fish_bind_mode=$fish_bind_mode set -U $_tide_left_prompt_display_var (_tide_prompt)" &
fish_bind_mode=$fish_bind_mode set -U $_tide_prompt_var (_tide_prompt)" &
builtin disown
command kill $_tide_last_pid 2>/dev/null
set -g _tide_last_pid $last_pid
end
string unescape $$_tide_left_prompt_display_var
test "$tide_prompt_add_newline_before" = true && echo
string unescape $_tide_prompt_data[2..]
end
function _tide_on_fish_exit --on-event fish_exit
set -e $_tide_left_prompt_display_var $_tide_right_prompt_display_var
set -e $_tide_prompt_var $_tide_right_prompt_display_var
end

View File

@ -1,3 +1,3 @@
function fish_right_prompt
string unescape $$_tide_right_prompt_display_var
string unescape $_tide_prompt_data[1]
end