tide/functions/fish_prompt.fish

165 lines
6.2 KiB
Fish
Raw Normal View History

2021-03-01 03:47:07 +03:00
function fish_prompt
2022-02-06 02:14:21 +03:00
end # In case this file gets loaded non-interactively, e.g by conda
status is-interactive || exit
_tide_remove_unusable_items
2021-08-22 01:05:08 +03:00
_tide_cache_variables
_tide_parent_dirs
2022-01-05 22:25:32 +03:00
source (functions --details _tide_pwd)
2022-01-06 00:50:08 +03:00
set -l prompt_var _tide_prompt_$fish_pid
2022-01-11 01:47:32 +03:00
set -U $prompt_var # Set var here so if we erase $prompt_var, bg job won't set a uvar
set_color normal | read -l color_normal
status fish-path | read -l fish_path
2022-01-14 09:10:33 +03:00
2021-12-22 01:32:17 +03:00
# _tide_repaint prevents us from creating a second background job
function _tide_refresh_prompt --on-variable $prompt_var --on-variable COLUMNS
2021-12-22 01:32:17 +03:00
set -g _tide_repaint
commandline -f repaint
end
2022-01-09 01:05:44 +03:00
if contains newline $_tide_left_items # two line prompt initialization
2022-01-06 00:50:08 +03:00
test "$tide_prompt_add_newline_before" = true && set -l add_newline '\n'
2022-01-11 01:47:32 +03:00
set_color $tide_prompt_color_frame_and_connection -b normal | read -l prompt_and_frame_color
set -l column_offset 5
test "$tide_left_prompt_frame_enabled" = true &&
2022-01-11 01:47:32 +03:00
set -l top_left_frame "$prompt_and_frame_color╭─" &&
set -l bot_left_frame "$prompt_and_frame_color╰─" &&
set column_offset (math $column_offset-2)
test "$tide_right_prompt_frame_enabled" = true &&
2022-01-11 01:47:32 +03:00
set -l top_right_frame "$prompt_and_frame_color─╮" &&
set -l bot_right_frame "$prompt_and_frame_color─╯" &&
set column_offset (math $column_offset-2)
if test "$tide_prompt_transient_enabled" = true
2023-07-31 05:53:35 +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_path -c \"set _tide_pipestatus \$_tide_pipestatus
set _tide_parent_dirs \$_tide_parent_dirs
PATH=\$(string escape \"\$PATH\") CMD_DURATION=\$CMD_DURATION fish_bind_mode=\$fish_bind_mode set $prompt_var (_tide_2_line_prompt)\" &
builtin disown
command kill \$_tide_last_pid 2>/dev/null
set -g _tide_last_pid \$last_pid
end
if not set -q _tide_transient
math \$COLUMNS-(string length -V \"\$$prompt_var[1][1]\$$prompt_var[1][3]\")+$column_offset | read -lx dist_btwn_sides
echo -n $add_newline'$top_left_frame'(string replace @PWD@ (_tide_pwd) \"\$$prompt_var[1][1]\")'$prompt_and_frame_color'
string repeat -Nm(math max 0, \$dist_btwn_sides-\$_tide_pwd_len) '$tide_prompt_icon_connection'
echo \"\$$prompt_var[1][3]$top_right_frame\"
end
echo -n \e\[0J\"$bot_left_frame\$$prompt_var[1][2]$color_normal \"
end
function fish_right_prompt
set -e _tide_transient || string unescape \"\$$prompt_var[1][4]$bot_right_frame$color_normal\"
end"
else
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
2022-03-10 01:12:55 +03:00
$fish_path -c \"set _tide_pipestatus \$_tide_pipestatus
set _tide_parent_dirs \$_tide_parent_dirs
PATH=\$(string escape \"\$PATH\") CMD_DURATION=\$CMD_DURATION fish_bind_mode=\$fish_bind_mode set $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
2022-01-09 22:28:42 +03:00
set -g _tide_last_pid \$last_pid
end
2022-01-04 00:03:28 +03:00
2022-01-12 21:24:41 +03:00
math \$COLUMNS-(string length -V \"\$$prompt_var[1][1]\$$prompt_var[1][3]\")+$column_offset | read -lx dist_btwn_sides
2022-01-04 00:03:28 +03:00
2022-01-11 01:47:32 +03:00
echo -ns $add_newline'$top_left_frame'(string replace @PWD@ (_tide_pwd) \"\$$prompt_var[1][1]\")'$prompt_and_frame_color'
2022-01-26 20:35:35 +03:00
string repeat -Nm(math max 0, \$dist_btwn_sides-\$_tide_pwd_len) '$tide_prompt_icon_connection'
echo -ns \"\$$prompt_var[1][3]$top_right_frame\"\n\"$bot_left_frame\$$prompt_var[1][2]$color_normal \"
2022-01-09 01:05:44 +03:00
end
function fish_right_prompt
2022-01-14 09:10:33 +03:00
string unescape \"\$$prompt_var[1][4]$bot_right_frame$color_normal\"
2022-01-04 00:03:28 +03:00
end"
2023-07-31 05:53:35 +03:00
end
2022-01-09 01:05:44 +03:00
else # one line prompt initialization
2022-01-06 00:50:08 +03:00
test "$tide_prompt_add_newline_before" = true && set -l 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"
if test "$tide_prompt_transient_enabled" = true
2023-07-31 06:27:51 +03:00
eval "
function fish_prompt
set -lx _tide_status \$status
_tide_pipestatus=\$pipestatus if not set -e _tide_repaint
jobs -q && set -lx _tide_jobs
$fish_path -c \"set _tide_pipestatus \$_tide_pipestatus
set _tide_parent_dirs \$_tide_parent_dirs
PATH=\$(string escape \"\$PATH\") CMD_DURATION=\$CMD_DURATION fish_bind_mode=\$fish_bind_mode set $prompt_var (_tide_1_line_prompt)\" &
builtin disown
command kill \$_tide_last_pid 2>/dev/null
set -g _tide_last_pid \$last_pid
end
if set -q _tide_transient
echo -n \e\[0J
add_prefix= _tide_item_character
else
math \$COLUMNS-(string length -V \"\$$prompt_var[1][1]\$$prompt_var[1][2]\")$column_offset | read -lx dist_btwn_sides
string replace @PWD@ (_tide_pwd) $add_newline \$$prompt_var[1][1]'$color_normal '
end
end
function fish_right_prompt
set -e _tide_transient || string unescape \"\$$prompt_var[1][2]$color_normal\"
end"
else
eval "
2022-01-04 00:03:28 +03:00
function fish_prompt
_tide_status=\$status _tide_pipestatus=\$pipestatus if not set -e _tide_repaint
jobs -q && set -lx _tide_jobs
2022-03-10 01:12:55 +03:00
$fish_path -c \"set _tide_pipestatus \$_tide_pipestatus
set _tide_parent_dirs \$_tide_parent_dirs
PATH=\$(string escape \"\$PATH\") CMD_DURATION=\$CMD_DURATION fish_bind_mode=\$fish_bind_mode set $prompt_var (_tide_1_line_prompt)\" &
2022-01-04 00:03:28 +03:00
builtin disown
command kill \$_tide_last_pid 2>/dev/null
2022-01-09 22:28:42 +03:00
set -g _tide_last_pid \$last_pid
2022-01-04 00:03:28 +03:00
end
2022-01-12 21:24:41 +03:00
math \$COLUMNS-(string length -V \"\$$prompt_var[1][1]\$$prompt_var[1][2]\")$column_offset | read -lx dist_btwn_sides
string replace @PWD@ (_tide_pwd) $add_newline \$$prompt_var[1][1]'$color_normal '
2021-12-08 20:27:33 +03:00
end
2021-08-13 14:54:40 +03:00
function fish_right_prompt
2022-01-14 09:10:33 +03:00
string unescape \"\$$prompt_var[1][2]$color_normal\"
2022-01-09 01:05:44 +03:00
end"
2023-07-31 06:27:51 +03:00
end
2021-08-13 14:54:40 +03:00
end
2022-01-09 01:05:44 +03:00
eval "function _tide_on_fish_exit --on-event fish_exit
2022-01-06 00:50:08 +03:00
set -e $prompt_var
2021-12-09 20:03:36 +03:00
end"
2023-07-31 05:53:35 +03:00
if test "$tide_prompt_transient_enabled" = true
2023-07-31 05:53:35 +03:00
function _tide_enter_transient
2023-09-20 22:23:08 +03:00
# If the commandline will be executed, or is empty
if commandline --is-valid || test -z "$(commandline)"
2023-07-31 05:53:35 +03:00
set -g _tide_transient
set -g _tide_repaint
commandline -f repaint
end
commandline -f execute
end
bind \r _tide_enter_transient
bind -M insert \r _tide_enter_transient
end