2019-02-09 14:45:10 +00:00
# colour of the revision number to display in the prompt
set -g __fish_svn_prompt_color_revision yellow
# setting the prompt status separator character
set -g __fish_svn_prompt_char_separator "|"
# ==============================
# SVN status display variables
# these are paired in groups of two:
# 1. the character to display in the prompt
# 2. the colour that should be used to display the character
#
# these variables are user-configurable and can be set to customize the display output
2020-03-09 18:36:12 +00:00
set -g __fish_svn_prompt_char_added_display A
2019-02-09 14:45:10 +00:00
set -g __fish_svn_prompt_char_added_color green
2020-03-09 18:36:12 +00:00
set -g __fish_svn_prompt_char_conflicted_display C
2019-02-09 14:45:10 +00:00
set -g __fish_svn_prompt_char_conflicted_color --underline magenta
2020-03-09 18:36:12 +00:00
set -g __fish_svn_prompt_char_deleted_display D
2019-02-09 14:45:10 +00:00
set -g __fish_svn_prompt_char_deleted_color red
2020-03-09 18:36:12 +00:00
set -g __fish_svn_prompt_char_ignored_display I
2019-02-09 14:45:10 +00:00
set -g __fish_svn_prompt_char_ignored_color --bold yellow
2020-03-09 18:36:12 +00:00
set -g __fish_svn_prompt_char_modified_display M
2019-02-09 14:45:10 +00:00
set -g __fish_svn_prompt_char_modified_color blue
2020-03-09 18:36:12 +00:00
set -g __fish_svn_prompt_char_replaced_display R
2019-02-09 14:45:10 +00:00
set -g __fish_svn_prompt_char_replaced_color cyan
2020-03-09 18:36:12 +00:00
set -g __fish_svn_prompt_char_unversioned_external_display X
2019-02-09 14:45:10 +00:00
set -g __fish_svn_prompt_char_unversioned_external_color --underline cyan
set -g __fish_svn_prompt_char_unversioned_display '?'
set -g __fish_svn_prompt_char_unversioned_color purple
2019-05-05 10:09:25 +00:00
set -g __fish_svn_prompt_char_missing_display !
2019-02-09 14:45:10 +00:00
set -g __fish_svn_prompt_char_missing_color yellow
set -g __fish_svn_prompt_char_versioned_obstructed_display '~'
set -g __fish_svn_prompt_char_versioned_obstructed_color magenta
2020-03-09 18:36:12 +00:00
set -g __fish_svn_prompt_char_locked_display L
2019-02-09 14:45:10 +00:00
set -g __fish_svn_prompt_char_locked_color --bold red
set -g __fish_svn_prompt_char_scheduled_display '+'
set -g __fish_svn_prompt_char_scheduled_color --bold green
2020-03-09 18:36:12 +00:00
set -g __fish_svn_prompt_char_switched_display S
2019-02-09 14:45:10 +00:00
set -g __fish_svn_prompt_char_switched_color --bold blue
2020-03-09 18:36:12 +00:00
set -g __fish_svn_prompt_char_token_present_display K
2019-02-09 14:45:10 +00:00
set -g __fish_svn_prompt_char_token_present_color --bold cyan
2020-03-09 18:36:12 +00:00
set -g __fish_svn_prompt_char_token_other_display O
2019-02-09 14:45:10 +00:00
set -g __fish_svn_prompt_char_token_other_color --underline purple
2020-03-09 18:36:12 +00:00
set -g __fish_svn_prompt_char_token_stolen_display T
2019-02-09 14:45:10 +00:00
set -g __fish_svn_prompt_char_token_stolen_color --bold purple
2020-03-09 18:36:12 +00:00
set -g __fish_svn_prompt_char_token_broken_display B
2019-02-09 14:45:10 +00:00
set -g __fish_svn_prompt_char_token_broken_color --bold magenta
# ==============================
2020-08-26 16:31:23 +00:00
function __fish_svn_prompt_parse_status --description "helper function that does pretty formatting on svn status"
2019-02-09 14:45:10 +00:00
# SVN status symbols
# Do not change these! These are the expected characters that are output from `svn status`, they are taken from `svn help status`
2020-08-26 16:31:23 +00:00
set -l __fish_svn_prompt_chars A C D I M R X '?' ! '~' L + S K O T B
2019-02-09 14:45:10 +00:00
# this sets up an array of all the types of status codes that could be returned.
2020-08-26 16:31:23 +00:00
set -l __fish_svn_prompt_flag_names added conflicted deleted ignored modified replaced unversioned_external unversioned missing versioned_obstructed locked scheduled switched token_present token_other token_stolen token_broken
2019-02-09 14:45:10 +00:00
# iterate over the different status types
for flag_type in $__fish_svn_prompt_flag_names
# resolve the name of the variable for the character representing the current status type
set -l flag_index ( contains -i $flag_type $__fish_svn_prompt_flag_names )
2020-08-26 16:31:23 +00:00
# check to see if the status list for this column contains the character representing the current status type
if contains -- $__fish_svn_prompt_chars [ $flag_index ] $argv
2019-02-09 14:45:10 +00:00
# if it does, then get the names of the variables for the display character and colour to format it with
set -l flag_var_display __fish_svn_prompt_char_{ $flag_type } _display
set -l flag_var_color __fish_svn_prompt_char_{ $flag_type } _color
# set the colour and print display character, then restore to default display colour
printf '%s%s%s' ( set_color $$ flag_var_color) $$ flag_var_display ( set_color normal)
end
end
end
function fish_svn_prompt --description "Prompt function for svn"
2019-10-30 20:45:50 +00:00
# if svn isn't installed or doesn't offer svnversion then don't do anything
if not command -sq svn svnversion
2019-02-09 14:45:10 +00:00
return 1
end
# make sure that this is a svn repo
set -l checkout_info ( command svn info 2 > /dev/null)
2019-07-15 15:46:41 +00:00
or return
2019-02-09 14:45:10 +00:00
# get the current revision number
printf '(%s%s%s' ( set_color $__fish_svn_prompt_color_revision ) ( __fish_print_svn_rev ) ( set_color normal)
# resolve the status of the checkout
# 1. perform `svn status`
# 2. remove extra lines that aren't necessary
# 3. cut the output down to the first 7 columns, as these contain the information needed
set -l svn_status_lines ( command svn status | sed -e 's=^Summary of conflicts.*==' -e 's=^ Text conflicts.*==' -e 's=^ Property conflicts.*==' -e 's=^ Tree conflicts.*==' -e 's=.*incoming .* upon update.*==' | cut -c 1 -7 )
# track the last column to contain a status flag
set -l last_column 0
# iterate over the 7 columns of output (the 7 columns are defined on `svn help status`)
for col in ( seq 7 )
# get the output for a particular column
# 1. echo the whole status flag text
# 2. cut out the current column of characters
2020-08-26 16:31:23 +00:00
# 3. remove duplicates
# 4. remove spaces
set -l column_status ( printf '%s\n' $svn_status_lines | cut -c $col | sort -u | tr -d ' ' )
2019-02-09 14:45:10 +00:00
2020-08-26 16:31:23 +00:00
# check that the column status list does not only contain an empty element (if it does, this column is empty)
2021-11-23 13:45:28 +00:00
if test ( count $column_status ) -gt 1 -o -n " $column_status [1] "
2019-02-09 14:45:10 +00:00
# parse the status flags for this column and create the formatting by calling out to the helper function
2020-08-26 16:31:23 +00:00
set -l svn_status_flags ( __fish_svn_prompt_parse_status $column_status )
2019-02-09 14:45:10 +00:00
# the default separator is empty
set -l prompt_separator ""
for index in ( seq ( math " $col - $last_column " ) )
# the prompt separator variable has to be updated with the number of separators needed to represent empty status columns (eg: if a file has the status "A +" then it should display as "A|||+" in the prompt)
set prompt_separator $prompt_separator $__fish_svn_prompt_char_separator
end
# record that the current column was the last one printed to the prompt
set last_column $col
# print the separator string then the current column's status flags
printf '%s%s' $prompt_separator $svn_status_flags
end
end
# print the close of the svn status prompt
printf ')'
end