mirror of
https://github.com/IlanCosman/tide.git
synced 2024-12-23 12:03:48 +03:00
Run even less code, improve variable scoping
This commit is contained in:
parent
fb151162b0
commit
5a70822cc1
@ -9,13 +9,6 @@ function _tide_2_line_prompt
|
|||||||
_tide_item_$item
|
_tide_item_$item
|
||||||
end)
|
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─╯"
|
|
||||||
|
|
||||||
echo -ns "$right[2]"\n"$left[1]"\n"$right[1]"\n"$left[2]"
|
echo -ns "$right[2]"\n"$left[1]"\n"$right[1]"\n"$left[2]"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -16,9 +16,9 @@ function _tide_cache_variables
|
|||||||
)
|
)
|
||||||
|
|
||||||
# pwd
|
# pwd
|
||||||
set -gx _tide_color_anchors "$data[1]"
|
set -g _tide_color_anchors "$data[1]"
|
||||||
set -gx _tide_color_truncated_dirs "$data[2]"
|
set -g _tide_color_truncated_dirs "$data[2]"
|
||||||
set -gx _tide_reset_to_color_dirs "$data[3]"
|
set -g _tide_reset_to_color_dirs "$data[3]"
|
||||||
|
|
||||||
# Same-color-separator color
|
# Same-color-separator color
|
||||||
set -gx _tide_color_separator_same_color "$data[4]"
|
set -gx _tide_color_separator_same_color "$data[4]"
|
||||||
@ -33,25 +33,6 @@ function _tide_cache_variables
|
|||||||
set -e _tide_private_mode
|
set -e _tide_private_mode
|
||||||
end
|
end
|
||||||
|
|
||||||
# newline before
|
|
||||||
test "$tide_prompt_add_newline_before" = true && set -g _tide_add_newline '\0'
|
|
||||||
|
|
||||||
# two line prompt
|
|
||||||
if contains newline $_tide_left_items
|
|
||||||
test "$_tide_add_newline" = '\0' && set _tide_add_newline '\n'
|
|
||||||
|
|
||||||
set_color $tide_prompt_color_frame_and_connection -b normal | read -gx _tide_prompt_and_frame_color
|
|
||||||
set -g _tide_X_line_prompt _tide_2_line_prompt
|
|
||||||
|
|
||||||
set -g column_offset +5
|
|
||||||
else
|
|
||||||
set -e _tide_prompt_and_frame_color
|
|
||||||
set -g _tide_X_line_prompt _tide_1_line_prompt
|
|
||||||
|
|
||||||
math 5 -$tide_prompt_min_cols | read -g column_offset
|
|
||||||
test $column_offset -gt 0 && set column_offset "+$column_offset"
|
|
||||||
end
|
|
||||||
|
|
||||||
# item padding
|
# item padding
|
||||||
test "$tide_prompt_pad_items" = true && set -gx _tide_pad ' ' || set -e _tide_pad
|
test "$tide_prompt_pad_items" = true && set -gx _tide_pad ' ' || set -e _tide_pad
|
||||||
end
|
end
|
||||||
|
@ -8,7 +8,7 @@ _tide_cache_variables
|
|||||||
|
|
||||||
# The first element in $$_tide_prompt_var is right prompt
|
# The first element in $$_tide_prompt_var is right prompt
|
||||||
# All remaining ones are 'left' prompt (also upper right in 2-line prompts)
|
# All remaining ones are 'left' prompt (also upper right in 2-line prompts)
|
||||||
set -g _tide_prompt_var _tide_prompt_$fish_pid
|
set -l _tide_prompt_var _tide_prompt_$fish_pid
|
||||||
set -U $_tide_prompt_var # So that if we erase $_tide_prompt_var, the bg job can't set a uvar
|
set -U $_tide_prompt_var # So that if we erase $_tide_prompt_var, the bg job can't set a uvar
|
||||||
|
|
||||||
# _tide_repaint prevents us from creating a second background job
|
# _tide_repaint prevents us from creating a second background job
|
||||||
@ -18,49 +18,67 @@ function _tide_refresh_prompt --on-variable $_tide_prompt_var
|
|||||||
end
|
end
|
||||||
|
|
||||||
if contains newline $_tide_left_items
|
if contains newline $_tide_left_items
|
||||||
|
test "$tide_prompt_add_newline_before" = true && set -l _tide_add_newline '\n'
|
||||||
|
|
||||||
|
set_color $tide_prompt_color_frame_and_connection -b normal | read -l _tide_prompt_and_frame_color
|
||||||
|
|
||||||
|
set -l column_offset 5
|
||||||
|
|
||||||
|
test "$tide_left_prompt_frame_enabled" = true &&
|
||||||
|
set -l top_left_frame "$_tide_prompt_and_frame_color╭─" &&
|
||||||
|
set -l bot_left_frame "$_tide_prompt_and_frame_color╰─" &&
|
||||||
|
set column_offset (math $column_offset-2)
|
||||||
|
test "$tide_right_prompt_frame_enabled" = true &&
|
||||||
|
set -l top_right_frame "$_tide_prompt_and_frame_color─╮" &&
|
||||||
|
set -l bot_right_frame "$_tide_prompt_and_frame_color─╯" &&
|
||||||
|
set column_offset (math $column_offset-2)
|
||||||
|
|
||||||
eval "
|
eval "
|
||||||
function fish_prompt
|
function fish_prompt
|
||||||
_tide_status=\$status _tide_pipestatus=\$pipestatus if not set -e _tide_repaint
|
_tide_status=\$status _tide_pipestatus=\$pipestatus if not set -e _tide_repaint
|
||||||
jobs -q && set -lx _tide_jobs
|
jobs -q && set -lx _tide_jobs
|
||||||
fish -c \"set _tide_pipestatus \$_tide_pipestatus
|
fish -c \"set _tide_pipestatus \$_tide_pipestatus
|
||||||
CMD_DURATION=\$CMD_DURATION fish_bind_mode=\$fish_bind_mode set $_tide_prompt_var ($_tide_X_line_prompt)\" &
|
CMD_DURATION=\$CMD_DURATION fish_bind_mode=\$fish_bind_mode set $_tide_prompt_var (_tide_2_line_prompt)\" &
|
||||||
builtin disown
|
builtin disown
|
||||||
|
|
||||||
command kill \$_tide_last_pid 2>/dev/null
|
command kill \$_tide_last_pid 2>/dev/null
|
||||||
set -g _tide_last_pid \$last_pid
|
set -l _tide_last_pid \$last_pid
|
||||||
end
|
end
|
||||||
|
|
||||||
math \$COLUMNS-(string length --visible \"\$$_tide_prompt_var[1][2..3]\")$column_offset | read -lx dist_btwn_sides
|
math \$COLUMNS-(string length --visible \"\$$_tide_prompt_var[1][2]\$$_tide_prompt_var[1][3]\")+$column_offset | read -lx dist_btwn_sides
|
||||||
|
|
||||||
echo -ns $_tide_add_newline(string replace @PWD@ (_tide_pwd) \"\$$_tide_prompt_var[1][2]\")'$_tide_prompt_and_frame_color'
|
echo -ns $_tide_add_newline(string replace @PWD@ (_tide_pwd) \"$top_left_frame\$$_tide_prompt_var[1][2]\")'$_tide_prompt_and_frame_color'
|
||||||
string repeat --no-newline --max (math max 0, \$dist_btwn_sides-\$pwd_length) '$tide_prompt_icon_connection'
|
string repeat --no-newline --max (math max 0, \$dist_btwn_sides-\$pwd_length) '$tide_prompt_icon_connection'
|
||||||
echo -ns \"\$$_tide_prompt_var[1][3]\"\n\"\$$_tide_prompt_var[1][4] \"
|
echo -ns \"\$$_tide_prompt_var[1][3]$top_right_frame\"\n\"$bot_left_frame\$$_tide_prompt_var[1][4] \"
|
||||||
end"
|
end"
|
||||||
else
|
else
|
||||||
|
test "$tide_prompt_add_newline_before" = true && set -l _tide_add_newline '\0'
|
||||||
|
|
||||||
|
math 5 -$tide_prompt_min_cols | read -l column_offset
|
||||||
|
test $column_offset -lt 0 && set column_offset "+$column_offset"
|
||||||
|
|
||||||
eval "
|
eval "
|
||||||
function fish_prompt
|
function fish_prompt
|
||||||
_tide_status=\$status _tide_pipestatus=\$pipestatus if not set -e _tide_repaint
|
_tide_status=\$status _tide_pipestatus=\$pipestatus if not set -e _tide_repaint
|
||||||
jobs -q && set -lx _tide_jobs
|
jobs -q && set -lx _tide_jobs
|
||||||
fish -c \"set _tide_pipestatus \$_tide_pipestatus
|
fish -c \"set _tide_pipestatus \$_tide_pipestatus
|
||||||
CMD_DURATION=\$CMD_DURATION fish_bind_mode=\$fish_bind_mode set $_tide_prompt_var ($_tide_X_line_prompt)\" &
|
CMD_DURATION=\$CMD_DURATION fish_bind_mode=\$fish_bind_mode set $_tide_prompt_var (_tide_1_line_prompt)\" &
|
||||||
builtin disown
|
builtin disown
|
||||||
|
|
||||||
command kill \$_tide_last_pid 2>/dev/null
|
command kill \$_tide_last_pid 2>/dev/null
|
||||||
set -g _tide_last_pid \$last_pid
|
set -l _tide_last_pid \$last_pid
|
||||||
end
|
end
|
||||||
|
|
||||||
math \$COLUMNS-(string length --visible \"\$$_tide_prompt_var[1]\")$column_offset | read -lx dist_btwn_sides
|
math \$COLUMNS-(string length --visible \"\$$_tide_prompt_var[1][2]\$$_tide_prompt_var[1][3]\")$column_offset | read -lx dist_btwn_sides
|
||||||
string replace @PWD@ (_tide_pwd) $_tide_add_newline \$$_tide_prompt_var[1][2]' '
|
string replace @PWD@ (_tide_pwd) $_tide_add_newline \$$_tide_prompt_var[1][2]' '
|
||||||
end"
|
end"
|
||||||
end
|
end
|
||||||
|
|
||||||
eval "
|
eval "
|
||||||
function fish_right_prompt
|
function fish_right_prompt
|
||||||
string unescape \$$_tide_prompt_var[1][1]
|
string unescape \$$_tide_prompt_var[1][1]$bot_right_frame
|
||||||
end
|
end
|
||||||
|
|
||||||
function _tide_on_fish_exit --on-event fish_exit
|
function _tide_on_fish_exit --on-event fish_exit
|
||||||
set -e $_tide_prompt_var
|
set -e $_tide_prompt_var
|
||||||
end"
|
end"
|
||||||
|
|
||||||
set -e column_offset _tide_prompt_var _tide_X_line_prompt _tide_add_newline
|
|
||||||
|
Loading…
Reference in New Issue
Block a user