tide/functions/fish_prompt.fish

86 lines
3.3 KiB
Fish
Raw Normal View History

2021-03-01 03:47:07 +03:00
function fish_prompt
end
status is-interactive || exit
_tide_remove_unusable_items
2021-08-22 01:05:08 +03:00
_tide_cache_variables
2022-01-05 22:25:32 +03:00
source (functions --details _tide_pwd)
# The first element in $$_tide_prompt_var is right prompt
# All remaining ones are 'left' prompt (also upper right in 2-line prompts)
set -l _tide_prompt_var _tide_prompt_$fish_pid
2021-09-27 04:14:26 +03:00
set -U $_tide_prompt_var # So that if we erase $_tide_prompt_var, the bg job can't set a uvar
2021-12-22 01:32:17 +03:00
# _tide_repaint prevents us from creating a second background job
function _tide_refresh_prompt --on-variable $_tide_prompt_var
2021-12-22 01:32:17 +03:00
set -g _tide_repaint
commandline -f repaint
end
2022-01-04 00:03:28 +03:00
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)
2022-01-04 00:03:28 +03:00
eval "
2021-12-09 20:03:36 +03:00
function fish_prompt
2021-12-08 20:09:13 +03:00
_tide_status=\$status _tide_pipestatus=\$pipestatus if not set -e _tide_repaint
2021-12-22 01:32:17 +03:00
jobs -q && set -lx _tide_jobs
fish -c \"set _tide_pipestatus \$_tide_pipestatus
CMD_DURATION=\$CMD_DURATION fish_bind_mode=\$fish_bind_mode set $_tide_prompt_var (_tide_2_line_prompt)\" &
2021-06-28 19:43:25 +03:00
builtin disown
2021-12-08 20:09:13 +03:00
command kill \$_tide_last_pid 2>/dev/null
set -l _tide_last_pid \$last_pid
end
2022-01-04 00:03:28 +03:00
math \$COLUMNS-(string length --visible \"\$$_tide_prompt_var[1][2]\$$_tide_prompt_var[1][3]\")+$column_offset | read -lx dist_btwn_sides
2022-01-04 00:03:28 +03:00
echo -ns $_tide_add_newline(string replace @PWD@ (_tide_pwd) \"$top_left_frame\$$_tide_prompt_var[1][2]\")'$_tide_prompt_and_frame_color'
2022-01-04 00:03:28 +03:00
string repeat --no-newline --max (math max 0, \$dist_btwn_sides-\$pwd_length) '$tide_prompt_icon_connection'
echo -ns \"\$$_tide_prompt_var[1][3]$top_right_frame\"\n\"$bot_left_frame\$$_tide_prompt_var[1][4] \"
2022-01-04 00:03:28 +03:00
end"
else
test "$tide_prompt_add_newline_before" = true && set -l _tide_add_newline '\0'
math 5 -$tide_prompt_min_cols | read -l column_offset
2022-01-05 02:17:49 +03:00
test $column_offset -ge 0 && set column_offset "+$column_offset"
2022-01-04 00:03:28 +03:00
eval "
function fish_prompt
_tide_status=\$status _tide_pipestatus=\$pipestatus if not set -e _tide_repaint
jobs -q && set -lx _tide_jobs
fish -c \"set _tide_pipestatus \$_tide_pipestatus
CMD_DURATION=\$CMD_DURATION fish_bind_mode=\$fish_bind_mode set $_tide_prompt_var (_tide_1_line_prompt)\" &
2022-01-04 00:03:28 +03:00
builtin disown
command kill \$_tide_last_pid 2>/dev/null
set -l _tide_last_pid \$last_pid
2022-01-04 00:03:28 +03:00
end
math \$COLUMNS-(string length --visible \"\$$_tide_prompt_var[1][2]\$$_tide_prompt_var[1][3]\")$column_offset | read -lx dist_btwn_sides
2022-01-04 00:03:28 +03:00
string replace @PWD@ (_tide_pwd) $_tide_add_newline \$$_tide_prompt_var[1][2]' '
end"
2021-12-08 20:27:33 +03:00
end
2022-01-04 00:03:28 +03:00
eval "
2021-08-13 14:54:40 +03:00
function fish_right_prompt
string unescape \$$_tide_prompt_var[1][1]$bot_right_frame
2021-08-13 14:54:40 +03:00
end
function _tide_on_fish_exit --on-event fish_exit
2021-08-13 14:49:48 +03:00
set -e $_tide_prompt_var
2021-12-09 20:03:36 +03:00
end"