mirror of
https://github.com/fish-shell/fish-shell
synced 2024-11-10 15:14:44 +00:00
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
(cherry picked from commit 43b1be0579
)
This commit is contained in:
parent
313b2993f5
commit
6295e32f25
1 changed files with 100 additions and 40 deletions
|
@ -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
|
||||||
|
|
||||||
|
set -q fish_color_fossil_clean
|
||||||
|
or set -g fish_color_fossil_clean green
|
||||||
|
set -q fish_color_fossil_modified
|
||||||
|
or set -g fish_color_fossil_modified yellow
|
||||||
|
set -q fish_color_fossil_dirty
|
||||||
|
or set -g fish_color_fossil_dirty red
|
||||||
|
|
||||||
|
set -q fish_color_fossil_added
|
||||||
|
or set -g fish_color_fossil_added green
|
||||||
|
set -q fish_color_fossil_renamed
|
||||||
|
or set -g fish_color_fossil_renamed magenta
|
||||||
|
set -q fish_color_fossil_missing
|
||||||
|
or set -g fish_color_fossil_missing red
|
||||||
|
set -q fish_color_fossil_deleted
|
||||||
|
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
|
||||||
|
|
||||||
|
set -q fish_prompt_fossil_status_added
|
||||||
|
or set -g fish_prompt_fossil_status_added '✚'
|
||||||
|
set -q fish_prompt_fossil_status_modified
|
||||||
|
or set -g fish_prompt_fossil_status_modified '*'
|
||||||
|
set -q fish_prompt_fossil_status_renamed
|
||||||
|
or set -g fish_prompt_fossil_status_renamed '⇒'
|
||||||
|
set -q fish_prompt_fossil_status_deleted
|
||||||
|
or set -g fish_prompt_fossil_status_deleted '-'
|
||||||
|
set -q fish_prompt_fossil_status_missing
|
||||||
|
or set -g fish_prompt_fossil_status_missing '✖'
|
||||||
|
set -q fish_prompt_fossil_status_untracked
|
||||||
|
or set -g fish_prompt_fossil_status_untracked '?'
|
||||||
|
set -q fish_prompt_fossil_status_conflict
|
||||||
|
or set -g fish_prompt_fossil_status_conflict '×'
|
||||||
|
|
||||||
|
set -q fish_prompt_fossil_status_order
|
||||||
|
or set -g fish_prompt_fossil_status_order added modified renamed deleted missing untracked conflict
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
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
|
end
|
||||||
|
|
||||||
# Parse fossil info
|
if string match -qr '^(ADDED|EDITED|DELETED)' $repo_status
|
||||||
set -l fossil_info (fossil info)
|
set_color $fish_color_fossil_modified
|
||||||
string match --regex --quiet \
|
else
|
||||||
'^project-name:\s*(?<fossil_project_name>.*)$' $fossil_info
|
set_color --bold $fish_color_fossil_dirty
|
||||||
string match --regex --quiet \
|
end
|
||||||
'^tags:\s*(?<fossil_tags>.*)$' $fossil_info
|
|
||||||
|
|
||||||
echo -n ' ['
|
echo -n '⚡'
|
||||||
set_color --bold magenta
|
|
||||||
echo -n $fossil_project_name
|
|
||||||
set_color normal
|
|
||||||
echo -n ':'
|
|
||||||
set_color --bold yellow
|
|
||||||
echo -n $fossil_tags
|
|
||||||
set_color normal
|
set_color normal
|
||||||
|
|
||||||
# Parse fossil status
|
# Sort status symbols
|
||||||
set -l fossil_status (fossil status)
|
for i in $fish_prompt_fossil_status_order
|
||||||
if string match --quiet 'ADDED*' $fossil_status
|
if contains -- $i $fossil_statuses
|
||||||
set_color --bold green
|
set -l color_name fish_color_fossil_$i
|
||||||
echo -n '+'
|
set -l status_name fish_prompt_fossil_status_$i
|
||||||
|
|
||||||
|
set_color $$color_name
|
||||||
|
echo -n $$status_name
|
||||||
end
|
end
|
||||||
if string match --quiet 'DELETED*' $fossil_status
|
|
||||||
set_color --bold red
|
|
||||||
echo -n '-'
|
|
||||||
end
|
end
|
||||||
if string match --quiet 'MISSING*' $fossil_status
|
|
||||||
set_color --bold red
|
|
||||||
echo -n '!'
|
|
||||||
end
|
|
||||||
if string match --quiet 'RENAMED*' $fossil_status
|
|
||||||
set_color --bold yellow
|
|
||||||
echo -n '→'
|
|
||||||
end
|
|
||||||
if string match --quiet 'CONFLICT*' $fossil_status
|
|
||||||
set_color --bold green
|
|
||||||
echo -n '×'
|
|
||||||
end
|
end
|
||||||
|
|
||||||
set_color normal
|
set_color normal
|
||||||
echo -n ']'
|
echo -n ')'
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue