Improve fossil prompt execution time (#9528)

* Improve prompt execution time

* Change status to changes

* Remove grep/awk/sort

* Remove calls to grep/awk/sort
* Don't overwrite user defined colors

* Make look more consistent with git
This commit is contained in:
rymrg 2023-02-15 17:52:05 +00:00 committed by GitHub
parent 9c8b50cb8f
commit 43b1be0579
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -4,50 +4,110 @@ function fish_fossil_prompt --description 'Write out the fossil prompt'
return 1 return 1
end end
# Bail if not a fossil checkout # Read branch and bookmark (bail if not checkout)
if not fossil ls &> /dev/null set -l branch (fossil branch current 2>/dev/null)
return 127 or return 127
end
# Parse fossil info set -q fish_color_fossil_clean
set -l fossil_info (fossil info) or set -g fish_color_fossil_clean green
string match --regex --quiet \ set -q fish_color_fossil_modified
'^project-name:\s*(?<fossil_project_name>.*)$' $fossil_info or set -g fish_color_fossil_modified yellow
string match --regex --quiet \ set -q fish_color_fossil_dirty
'^tags:\s*(?<fossil_tags>.*)$' $fossil_info or set -g fish_color_fossil_dirty red
echo -n ' [' set -q fish_color_fossil_added
set_color --bold magenta or set -g fish_color_fossil_added green
echo -n $fossil_project_name set -q fish_color_fossil_renamed
set_color normal or set -g fish_color_fossil_renamed magenta
echo -n ':' set -q fish_color_fossil_missing
set_color --bold yellow or set -g fish_color_fossil_missing red
echo -n $fossil_tags set -q fish_color_fossil_deleted
set_color normal or set -g fish_color_fossil_deleted red
set -q fish_color_fossil_untracked
or set -g fish_color_fossil_untracked yellow
set -q fish_color_fossil_conflict
or set -g fish_color_fossil_conflict red
# Parse fossil status set -q fish_prompt_fossil_status_added
set -l fossil_status (fossil status) or set -g fish_prompt_fossil_status_added '✚'
if string match --quiet 'ADDED*' $fossil_status set -q fish_prompt_fossil_status_modified
set_color --bold green or set -g fish_prompt_fossil_status_modified '*'
echo -n '+' set -q fish_prompt_fossil_status_renamed
end or set -g fish_prompt_fossil_status_renamed '⇒'
if string match --quiet 'DELETED*' $fossil_status set -q fish_prompt_fossil_status_deleted
set_color --bold red or set -g fish_prompt_fossil_status_deleted '-'
echo -n '-' set -q fish_prompt_fossil_status_missing
end or set -g fish_prompt_fossil_status_missing '✖'
if string match --quiet 'MISSING*' $fossil_status set -q fish_prompt_fossil_status_untracked
set_color --bold red or set -g fish_prompt_fossil_status_untracked '?'
echo -n '!' set -q fish_prompt_fossil_status_conflict
end or set -g fish_prompt_fossil_status_conflict '×'
if string match --quiet 'RENAMED*' $fossil_status
set_color --bold yellow set -q fish_prompt_fossil_status_order
echo -n '→' or set -g fish_prompt_fossil_status_order added modified renamed deleted missing untracked conflict
end
if string match --quiet 'CONFLICT*' $fossil_status
set_color --bold green
echo -n '×' echo -n ' ('
set_color magenta
echo -n "$branch"
set_color normal
echo -n '|'
#set -l repo_status (fossil changes --differ 2>/dev/null | string match -rv '\w:|^\s' | string split " " -f1 | sort -u)
set -l repo_status (fossil changes --differ 2>/dev/null | string match -rv '\w:|^\s' | string split " " -f1 | path sort -u)
# Show nice color for a clean repo
if test -z "$repo_status"
set_color $fish_color_fossil_clean
echo -n '✔'
# Handle modified or dirty (unknown state)
else
set -l fossil_statuses
# Take actions for the statuses of the files in the repo
for line in $repo_status
# Add a character for each file status if we have one
switch $line
case 'ADDED'
set -a fossil_statuses added
case 'EDITED'
set -a fossil_statuses modified
case 'EXTRA'
set -a fossil_statuses untracked
case 'DELETED'
set -a fossil_statuses deleted
case 'MISSING'
set -a fossil_statuses missing
case 'RENAMED'
set -a fossil_statuses renamed
case 'CONFLICT'
set -a fossil_statuses conflict
end
end
if string match -qr '^(ADDED|EDITED|DELETED)' $repo_status
set_color $fish_color_fossil_modified
else
set_color --bold $fish_color_fossil_dirty
end
echo -n '⚡'
set_color normal
# Sort status symbols
for i in $fish_prompt_fossil_status_order
if contains -- $i $fossil_statuses
set -l color_name fish_color_fossil_$i
set -l status_name fish_prompt_fossil_status_$i
set_color $$color_name
echo -n $$status_name
end
end
end end
set_color normal set_color normal
echo -n ']' echo -n ')'
end end