diff --git a/functions/_tide_1_line_prompt.fish b/functions/_tide_1_line_prompt.fish new file mode 100644 index 0000000..5465ff1 --- /dev/null +++ b/functions/_tide_1_line_prompt.fish @@ -0,0 +1,23 @@ +function _tide_1_line_prompt + set -g add_prefix + _tide_side=left set -f left (for item in $_tide_left_items + _tide_item_$item + end + set_color $prev_bg_color -b normal + echo -ns $tide_left_prompt_suffix) + + set -g add_prefix + _tide_side=right set -f right (for item in $_tide_right_items + _tide_item_$item + end + set_color $prev_bg_color -b normal + echo -ns $tide_right_prompt_suffix) + + # 5 = @PWD@ length which will be replaced + math $COLUMNS+5-(string length --visible "$left[1]$right[1]") -$tide_prompt_min_cols | read -lx dist_btwn_sides + string replace @PWD@ (_tide_pwd) "$right[1]" "$left[1] " +end + +function _tide_item_pwd + _tide_print_item pwd @PWD@ +end diff --git a/functions/_tide_2_line_prompt.fish b/functions/_tide_2_line_prompt.fish new file mode 100644 index 0000000..d8b4166 --- /dev/null +++ b/functions/_tide_2_line_prompt.fish @@ -0,0 +1,43 @@ +function _tide_2_line_prompt + set -g add_prefix + _tide_side=left set -f left (for item in $_tide_left_items + _tide_item_$item + end + if not set -e add_prefix + set_color $prev_bg_color -b normal + echo -ns $tide_left_prompt_suffix + end) + + set -g add_prefix + _tide_side=right set -f right (for item in $_tide_right_items + _tide_item_$item + end + if not set -e add_prefix + set_color $prev_bg_color -b normal + echo -ns $tide_right_prompt_suffix + end) + + test "$tide_left_prompt_frame_enabled" = true && + set left[1] "$_tide_prompt_and_frame_color╭─$left[1]" && + set left[2] "$_tide_prompt_and_frame_color╰─$left[2]" + test "$tide_right_prompt_frame_enabled" = true && + set right[1] "$right[1]$_tide_prompt_and_frame_color─╮" && + set right[2] "$right[2]$_tide_prompt_and_frame_color─╯" + + # 5 = @PWD@ length which will be replaced + math $COLUMNS+5-(string length --visible "$left[1]$right[1]") | read -lx dist_btwn_sides + echo -ns "$right[2]"\n(string replace @PWD@ (_tide_pwd) "$left[1]")$_tide_prompt_and_frame_color + + string repeat --no-newline --max (math max 0, $dist_btwn_sides-$pwd_length) $tide_prompt_icon_connection + echo -ns "$right[1]"\n"$left[2] " +end + +function _tide_item_pwd + _tide_print_item pwd @PWD@ +end + +function _tide_item_newline + set_color $prev_bg_color -b normal + var=tide_"$_tide_side"_prompt_suffix echo $$var + set -g add_prefix +end diff --git a/functions/_tide_cache_variables.fish b/functions/_tide_cache_variables.fish index 23c55d4..8844049 100644 --- a/functions/_tide_cache_variables.fish +++ b/functions/_tide_cache_variables.fish @@ -36,8 +36,10 @@ function _tide_cache_variables # two line prompt if contains newline $_tide_left_items set_color $tide_prompt_color_frame_and_connection -b normal | read -gx _tide_prompt_and_frame_color + set -g _tide_prompt_num_lines _tide_2_line_prompt else set -e _tide_prompt_and_frame_color + set -g _tide_prompt_num_lines _tide_1_line_prompt end # newline before diff --git a/functions/_tide_item_newline.fish b/functions/_tide_item_newline.fish deleted file mode 100644 index 7948bbd..0000000 --- a/functions/_tide_item_newline.fish +++ /dev/null @@ -1,5 +0,0 @@ -function _tide_item_newline - set_color $prev_bg_color -b normal - var=tide_"$_tide_side"_prompt_suffix echo $$var - set -g add_prefix -end diff --git a/functions/_tide_prompt.fish b/functions/_tide_prompt.fish deleted file mode 100644 index 59c483c..0000000 --- a/functions/_tide_prompt.fish +++ /dev/null @@ -1,42 +0,0 @@ -function _tide_prompt - set -g add_prefix - _tide_side=left set -f left (for item in $_tide_left_items - _tide_item_$item - end - if not set -e add_prefix - set_color $prev_bg_color -b normal - echo -ns $tide_left_prompt_suffix - end) - - set -g add_prefix - _tide_side=right set -f right (for item in $_tide_right_items - _tide_item_$item - end - if not set -e add_prefix - set_color $prev_bg_color -b normal - echo -ns $tide_right_prompt_suffix - end) - - if set -q _tide_prompt_and_frame_color # If prompt is two lines - test "$tide_left_prompt_frame_enabled" = true && - set left[1] "$_tide_prompt_and_frame_color╭─$left[1]" && - set left[2] "$_tide_prompt_and_frame_color╰─$left[2]" - test "$tide_right_prompt_frame_enabled" = true && - set right[1] "$right[1]$_tide_prompt_and_frame_color─╮" && - set right[2] "$right[2]$_tide_prompt_and_frame_color─╯" - - # 5 = @PWD@ length which will be replaced - math $COLUMNS+5-(string length --visible "$left[1]$right[1]") | read -lx dist_btwn_sides - echo -ns "$right[2]"\n(string replace @PWD@ (_tide_pwd) "$left[1]")$_tide_prompt_and_frame_color - - string repeat --no-newline --max (math max 0, $dist_btwn_sides-$pwd_length) $tide_prompt_icon_connection - echo -ns "$right[1]"\n"$left[2] " - else - math $COLUMNS+5-(string length --visible "$left[1]$right[1]") -$tide_prompt_min_cols | read -lx dist_btwn_sides - string replace @PWD@ (_tide_pwd) "$right[1]" "$left[1] " - end -end - -function _tide_item_pwd - _tide_print_item pwd @PWD@ -end diff --git a/functions/fish_prompt.fish b/functions/fish_prompt.fish index 9ccbebb..6cbbe1c 100644 --- a/functions/fish_prompt.fish +++ b/functions/fish_prompt.fish @@ -21,7 +21,7 @@ var="function fish_prompt jobs --query fish --command \"set _tide_pipestatus \$_tide_pipestatus _tide_jobs_status=\$status CMD_DURATION=\$CMD_DURATION COLUMNS=\$COLUMNS \ - fish_bind_mode=\$fish_bind_mode set $_tide_prompt_var (_tide_prompt)\" & + fish_bind_mode=\$fish_bind_mode set $_tide_prompt_var ($_tide_prompt_num_lines)\" & builtin disown command kill \$_tide_last_pid 2>/dev/null @@ -30,7 +30,7 @@ var="function fish_prompt string unescape $_tide_add_newline \$\$_tide_prompt_var[1][2..] end" eval "$var" -set -e _tide_add_newline +set -e _tide_add_newline _tide_prompt_num_lines function fish_right_prompt string unescape $$_tide_prompt_var[1][1]