More work on async

This commit is contained in:
Ilan Cosman 2020-11-23 14:56:52 -08:00
parent 829f886a47
commit 5bd71efa45
11 changed files with 89 additions and 101 deletions

View File

@ -1,11 +1,6 @@
if set -q _tide_version
_tide_count_left_prompt_height
if not set -q _tide_subshell && set -q _tide_version
_tide_detect_os
_tide_git_prompt_set_vars
_tide_pwd
end
function _tide_init_install --on-event _tide_init_install

View File

@ -1,4 +0,0 @@
function _tide_count_left_prompt_height --on-variable tide_left_prompt_items
set -l numberOfNewlines (string match --all 'newline' $tide_left_prompt_items | count)
set -g _tide_left_prompt_height (math 1+$numberOfNewlines)
end

View File

@ -1,18 +1,18 @@
function _tide_detect_os
switch (uname | string lower)
case darwin
set -g _tide_os_icon
set -gx _tide_os_icon
case freebsd openbsd dragonfly
set -g _tide_os_icon
set -gx _tide_os_icon
case linux
if _tide_detect_os_linux_cases /etc/os-release ID
else if _tide_detect_os_linux_cases /etc/os-release ID_LIKE
else if _tide_detect_os_linux_cases /etc/lsb-release DISTRIB_ID
else
set -g _tide_os_icon
set -gx _tide_os_icon
end
case '*'
set -g _tide_os_icon '?'
set -gx _tide_os_icon '?'
end
end
@ -27,31 +27,31 @@ function _tide_detect_os_linux_cases -a file key
switch $name
case alpine
set -g _tide_os_icon
set -gx _tide_os_icon
case arch
set -g _tide_os_icon
set -gx _tide_os_icon
case centos
set -g _tide_os_icon
set -gx _tide_os_icon
case debian
set -g _tide_os_icon
set -gx _tide_os_icon
case elementary
set -g _tide_os_icon
set -gx _tide_os_icon
case fedora
set -g _tide_os_icon
set -gx _tide_os_icon
case gentoo
set -g _tide_os_icon
set -gx _tide_os_icon
case linuxmint
set -g _tide_os_icon
set -gx _tide_os_icon
case manjaro
set -g _tide_os_icon
set -gx _tide_os_icon
case nixos
set -g _tide_os_icon
set -gx _tide_os_icon
case opensuse tumbleweed
set -g _tide_os_icon
set -gx _tide_os_icon
case raspbian
set -g _tide_os_icon
set -gx _tide_os_icon
case ubuntu
set -g _tide_os_icon
set -gx _tide_os_icon
case '*'
return 1
end

View File

@ -7,6 +7,6 @@ function _tide_git_prompt_set_vars --on-variable tide_git_prompt_bg_color
end
for var in (set --names | string match --regex "__fish_git_prompt_char_.*")
set -g _$var $color$$var
set -gx _$var $color$$var
end
end

View File

@ -1,5 +1,3 @@
function _tide_item_git_prompt
if test -n "$_tide_git_dir"
fish_git_prompt '%s'
end
fish_git_prompt '%s'
end

View File

@ -1,3 +1,63 @@
function _tide_item_pwd
printf '%s' $_tide_pwd_output
set -l preMaxDirsSplitPwd (string replace $HOME '~' $PWD | string split '/')
set -l splitPwd $preMaxDirsSplitPwd[(math --scale=0 -$tide_pwd_max_dirs)..-1]
set -l pwd (string join '/' $splitPwd)
set -l gitDir (git rev-parse --show-toplevel 2>/dev/null)
# Compute anchors
if contains 'first' $tide_pwd_anchors
if test -n "$splitPwd[1]"
set -a tidePwdAnchors $splitPwd[1]
else
set -a tidePwdAnchors $splitPwd[2]
end
end
if contains 'last' $tide_pwd_anchors
set -a tidePwdAnchors $splitPwd[-1]
end
if contains 'git' $tide_pwd_anchors
set -a tidePwdAnchors (string split -r -m1 '/' "$gitDir")[2]
end
set -l colorDirs (set_color $tide_pwd_color_dirs; or echo)
set -l colorAnchors (set_color -o $tide_pwd_color_anchors; or echo)
set -l keepBackgroundColor (set_color normal -b $tide_pwd_bg_color; or echo)
set -l colorTruncatedDirs (set_color $tide_pwd_color_truncated_dirs; or echo)
set -g _tide_pwd_output $colorDirs$pwd
# Prepend icons
if not test -w $PWD
set -p _tide_pwd_output $colorDirs$tide_pwd_unwritable_icon
else if test $PWD = $HOME
set -p _tide_pwd_output $colorDirs$tide_pwd_home_icon
else
set -p _tide_pwd_output $colorDirs$tide_pwd_dir_icon
end
set -l truncatedList $splitPwd '.'
if test -z "$splitPwd[1]" # Empty string will cause an issue for the while loop
set -e truncatedList[1]
end
set -l pwdMaxLength (math $COLUMNS -$tide_pwd_truncate_margin)
for dir in $splitPwd
if contains $dir $tidePwdAnchors
set _tide_pwd_output (string replace $dir $colorAnchors$dir$keepBackgroundColor $_tide_pwd_output)
else if test (string length $pwd) -gt $pwdMaxLength
set -l dirTruncated $dir
set -l truncationLength 1
while contains $dirTruncated $truncatedList
set dirTruncated (string sub -l $truncationLength $dir)
set truncationLength (math $truncationLength+1)
end
set -a truncatedList $dirTruncated
set pwd (string replace $dir $dirTruncated $pwd)
set _tide_pwd_output (string replace $dir $colorTruncatedDirs$dirTruncated $_tide_pwd_output)
end
end
string replace --all '/' $colorDirs'/' $_tide_pwd_output
end

View File

@ -7,6 +7,8 @@ function _tide_prompt
string repeat --no-newline --max $COLUMNS $tide_prompt_connection_icon
printf '%b' '\r'
set -g _tide_left_prompt_height (math 1+(string match --all 'newline' $tide_left_prompt_items | count))
_tide_right_prompt
_tide_left_prompt
end

View File

@ -1,63 +0,0 @@
function _tide_pwd --on-variable PWD --on-signal WINCH
set -l preMaxDirsSplitPwd (string replace $HOME '~' $PWD | string split '/')
set -l splitPwd $preMaxDirsSplitPwd[(math --scale=0 -$tide_pwd_max_dirs)..-1]
set -l pwd (string join '/' $splitPwd)
set -g _tide_git_dir (git rev-parse --show-toplevel 2>/dev/null) # Used for git_prompt item
# Compute anchors
if contains 'first' $tide_pwd_anchors
if test -n "$splitPwd[1]"
set -a tidePwdAnchors $splitPwd[1]
else
set -a tidePwdAnchors $splitPwd[2]
end
end
if contains 'last' $tide_pwd_anchors
set -a tidePwdAnchors $splitPwd[-1]
end
if contains 'git' $tide_pwd_anchors
set -a tidePwdAnchors (string split -r -m1 '/' "$_tide_git_dir")[2]
end
set -l colorDirs (set_color $tide_pwd_color_dirs; or echo)
set -l colorAnchors (set_color -o $tide_pwd_color_anchors; or echo)
set -l keepBackgroundColor (set_color normal -b $tide_pwd_bg_color; or echo)
set -l colorTruncatedDirs (set_color $tide_pwd_color_truncated_dirs; or echo)
set -g _tide_pwd_output $colorDirs$pwd
# Prepend icons
if not test -w $PWD
set -p _tide_pwd_output $colorDirs$tide_pwd_unwritable_icon' '
else if test $PWD = $HOME
set -p _tide_pwd_output $colorDirs$tide_pwd_home_icon' '
else
set -p _tide_pwd_output $colorDirs$tide_pwd_dir_icon' '
end
set -l truncatedList $splitPwd '.'
if test -z "$splitPwd[1]" # Empty string will cause an issue for the while loop
set -e truncatedList[1]
end
set -l pwdMaxLength (math $COLUMNS -$tide_pwd_truncate_margin)
for dir in $splitPwd
if contains $dir $tidePwdAnchors
set _tide_pwd_output (string replace $dir $colorAnchors$dir$keepBackgroundColor $_tide_pwd_output)
else if test (string length $pwd) -gt $pwdMaxLength
set -l dirTruncated $dir
set -l truncationLength 1
while contains $dirTruncated $truncatedList
set dirTruncated (string sub -l $truncationLength $dir)
set truncationLength (math $truncationLength+1)
end
set -a truncatedList $dirTruncated
set pwd (string replace $dir $dirTruncated $pwd)
set _tide_pwd_output (string replace $dir $colorTruncatedDirs$dirTruncated $_tide_pwd_output)
end
end
set _tide_pwd_output (string replace --all '/' $colorDirs'/' $_tide_pwd_output)
end

View File

@ -35,11 +35,11 @@ function _tide_right_prompt
end
if test $printAtEndedRightPromptHeight -eq $_tide_left_prompt_height
set -g _tide_fish_right_prompt_display $splitText[-1]
set -U _tide_right_prompt_display $splitText[-1]
set printAtEndedRightPromptHeight (math $printAtEndedRightPromptHeight-1)
else
_tide_print_at_end $splitText[-1]
set -g _tide_fish_right_prompt_display
set -U _tide_right_prompt_display
end
_tide_cursor_up $printAtEndedRightPromptHeight

View File

@ -2,11 +2,11 @@ function fish_prompt --description 'Created by tide configure'
set -lx _tide_last_pipestatus $pipestatus
set -lx _tide_last_status $status
fish --command 'set -U _tide_prompt (_tide_prompt)' &
fish --command 'set -g _tide_subshell; set -U _tide_left_prompt_display (_tide_prompt)' &
printf '%s\n' $_tide_prompt
string unescape $_tide_left_prompt_display
end
function _tide_prompt --on-variable _tide_prompt
function _tide_refresh_prompt --on-variable _tide_left_prompt_display --on-variable _tide_right_prompt_display
commandline --function repaint
end

View File

@ -1,5 +1,5 @@
function fish_right_prompt
printf '%s' $_tide_fish_right_prompt_display
printf '%s' $_tide_right_prompt_display
# Right prompt is always the last thing on the line
# therefore reset colors for tab completion
set_color normal