tide/functions/_tide_prompt.fish

65 lines
2.5 KiB
Fish
Raw Normal View History

2020-11-21 01:04:04 +03:00
function _tide_prompt
2021-05-04 21:03:38 +03:00
test "$tide_prompt_add_newline_before" = true && echo
2020-11-21 01:04:04 +03:00
2021-05-19 20:14:21 +03:00
left_prompt=(_tide_left_prompt) right_prompt=(_tide_right_prompt) if set -q left_prompt[2] # If prompt is two lines
2021-07-03 21:24:29 +03:00
set -l prompt_and_frame_color (set_color $tide_prompt_color_frame_and_connection -b normal)
2021-03-04 22:05:49 +03:00
if test "$tide_left_prompt_frame_enabled" = true
2021-05-12 23:13:51 +03:00
set left_prompt[1] $prompt_and_frame_color╭─"$left_prompt[1]"
set left_prompt[2] $prompt_and_frame_color╰─"$left_prompt[2]"
2021-03-04 22:05:49 +03:00
end
if test "$tide_right_prompt_frame_enabled" = true
2021-05-12 23:13:51 +03:00
set right_prompt[1] "$right_prompt[1]"$prompt_and_frame_color─╮
set right_prompt[2] "$right_prompt[2]"$prompt_and_frame_color─╯
2021-03-04 22:05:49 +03:00
end
2021-07-03 21:24:29 +03:00
set -lx dist_btwn_sides (math $COLUMNS + 5 - ( # Regex removes color. 5 = @PWD@ length which will be replaced
2021-06-27 22:15:10 +03:00
string replace -ar '\e(\[[\d;]*|\(B\e\[)m(\co)?' '' "$left_prompt[1]""$right_prompt[1]" | string length))
2021-07-03 21:24:29 +03:00
printf '%s' (string replace @PWD@ (_tide_pwd) "$left_prompt[1]") $prompt_and_frame_color
2021-06-27 22:15:10 +03:00
2021-06-28 19:43:25 +03:00
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]' '
2021-06-27 22:15:10 +03:00
2021-05-12 23:13:51 +03:00
set -U $_tide_right_prompt_display_var $right_prompt[2]
2021-05-05 01:25:38 +03:00
else
2021-07-03 21:24:29 +03:00
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))
2021-07-03 21:24:29 +03:00
string replace @PWD@ (_tide_pwd) "$left_prompt[1] "
2021-05-12 23:13:51 +03:00
set -U $_tide_right_prompt_display_var $right_prompt[1]
2021-03-04 22:05:49 +03:00
end
end
function _tide_left_prompt
2021-05-08 23:08:36 +03:00
set -g _tide_last_item newline
2021-08-02 00:28:27 +03:00
_tide_which_side_working_on=left for item in $tide_left_prompt_items
_tide_item_$item
end
2021-05-08 23:08:36 +03:00
if not contains -- $_tide_last_item newline character
set_color $_tide_previous_bg_color -b normal
printf '%s' $tide_left_prompt_suffix
end
set_color normal # Make sure there is something printed on the last line
end
function _tide_right_prompt
2021-05-08 23:08:36 +03:00
set -g _tide_last_item newline
2021-08-02 00:28:27 +03:00
_tide_which_side_working_on=right for item in $tide_right_prompt_items
_tide_item_$item
end
2021-05-08 23:08:36 +03:00
if test "$_tide_last_item" != newline
set_color $_tide_previous_bg_color -b normal
printf '%s' $tide_right_prompt_suffix
end
set_color normal # Make sure there is something printed on the last line
end
function _tide_item_pwd
2021-07-03 21:24:29 +03:00
_tide_print_item pwd @PWD@
end