fork/fish-shell
git clone https://git.julia.blue/fork/fish-shell
867946468
master
1# colour of the revision number to display in the prompt 2set -g __fish_svn_prompt_color_revision yellow 3 4# setting the prompt status separator character 5set -g __fish_svn_prompt_char_separator"|" 6 7# ============================== 8 9# SVN status display variables 10# these are paired in groups of two: 11# 1. the character to display in the prompt 12# 2. the colour that should be used to display the character 13# 14# these variables are user-configurable and can be set to customize the display output 15 16set -g __fish_svn_prompt_char_added_display A 17set -g __fish_svn_prompt_char_added_color green 18 19set -g __fish_svn_prompt_char_conflicted_display C 20set -g __fish_svn_prompt_char_conflicted_color --underline magenta 21 22set -g __fish_svn_prompt_char_deleted_display D 23set -g __fish_svn_prompt_char_deleted_color red 24 25set -g __fish_svn_prompt_char_ignored_display I 26set -g __fish_svn_prompt_char_ignored_color --bold yellow 27 28set -g __fish_svn_prompt_char_modified_display M 29set -g __fish_svn_prompt_char_modified_color blue 30 31set -g __fish_svn_prompt_char_replaced_display R 32set -g __fish_svn_prompt_char_replaced_color cyan 33 34set -g __fish_svn_prompt_char_unversioned_external_display X 35set -g __fish_svn_prompt_char_unversioned_external_color --underline cyan 36 37set -g __fish_svn_prompt_char_unversioned_display'?' 38set -g __fish_svn_prompt_char_unversioned_color purple 39 40set -g __fish_svn_prompt_char_missing_display ! 41set -g __fish_svn_prompt_char_missing_color yellow 42 43set -g __fish_svn_prompt_char_versioned_obstructed_display'~' 44set -g __fish_svn_prompt_char_versioned_obstructed_color magenta 45 46set -g __fish_svn_prompt_char_locked_display L 47set -g __fish_svn_prompt_char_locked_color --bold red 48 49set -g __fish_svn_prompt_char_scheduled_display'+' 50set -g __fish_svn_prompt_char_scheduled_color --bold green 51 52set -g __fish_svn_prompt_char_switched_display S 53set -g __fish_svn_prompt_char_switched_color --bold blue 54 55set -g __fish_svn_prompt_char_token_present_display K 56set -g __fish_svn_prompt_char_token_present_color --bold cyan 57 58set -g __fish_svn_prompt_char_token_other_display O 59set -g __fish_svn_prompt_char_token_other_color --underline purple 60 61set -g __fish_svn_prompt_char_token_stolen_display T 62set -g __fish_svn_prompt_char_token_stolen_color --bold purple 63 64set -g __fish_svn_prompt_char_token_broken_display B 65set -g __fish_svn_prompt_char_token_broken_color --bold magenta 66 67# ============================== 68 69function __fish_svn_prompt_parse_status --description"helper function that does pretty formatting on svn status" 70# SVN status symbols 71# Do not change these! These are the expected characters that are output from `svn status`, they are taken from `svn help status` 72set -l __fish_svn_prompt_chars A C D I M R X'?' !'~' L + S K O T B 73# this sets up an array of all the types of status codes that could be returned. 74set -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 75# iterate over the different status types 76for flag_typein $__fish_svn_prompt_flag_names 77# resolve the name of the variable for the character representing the current status type 78set -l flag_index( contains -i$flag_type $__fish_svn_prompt_flag_names ) 79# check to see if the status list for this column contains the character representing the current status type 80if contains --$__fish_svn_prompt_chars [ $flag_index ] $argv 81# if it does, then get the names of the variables for the display character and colour to format it with 82set -l flag_var_display __fish_svn_prompt_char_{ $flag_type } _display 83set -l flag_var_color __fish_svn_prompt_char_{ $flag_type } _color 84# set the colour and print display character, then restore to default display colour 85printf '%s%s%s' ( set_color $$flag_var_color ) $$flag_var_display ( set_color --reset) 86end 87end 88end 89 90function fish_svn_prompt --description"Prompt function for svn" 91# if svn isn't installed or doesn't offer svnversion then don't do anything 92if not command -sq svn svnversion 93return 1 94end 95 96# make sure that this is a svn repo 97set -l checkout_info( command svn info2> /dev/null) 98or return 99 100# get the current revision number 101printf '(%s%s%s' ( set_color $__fish_svn_prompt_color_revision ) ( __fish_print_svn_rev ) ( set_color --reset) 102 103# resolve the status of the checkout 104# 1. perform `svn status` 105# 2. remove extra lines that aren't necessary 106# 3. cut the output down to the first 7 columns, as these contain the information needed 107set -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) 108 109# track the last column to contain a status flag 110set -l last_column0 111 112# iterate over the 7 columns of output (the 7 columns are defined on `svn help status`) 113for colin ( seq 7 ) 114# get the output for a particular column 115# 1. echo the whole status flag text 116# 2. cut out the current column of characters 117# 3. remove duplicates 118# 4. remove spaces 119set -l column_status( printf '%s\n' $svn_status_lines | cut -c$col | sort -u| tr -d' ' ) 120 121# check that the column status list does not only contain an empty element (if it does, this column is empty) 122if test ( count $column_status ) -gt 1 -o -n " $column_status [ 1 ] " 123 124# parse the status flags for this column and create the formatting by calling out to the helper function 125set -l svn_status_flags( __fish_svn_prompt_parse_status $column_status ) 126 127# the default separator is empty 128set -l prompt_separator"" 129for indexin ( seq ( math " $col - $last_column " )) 130# 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) 131set prompt_separator$prompt_separator$__fish_svn_prompt_char_separator 132end 133 134# record that the current column was the last one printed to the prompt 135set last_column$col 136# print the separator string then the current column's status flags 137printf '%s%s' $prompt_separator $svn_status_flags 138end 139end 140 141# print the close of the svn status prompt 142printf ')' 143end