fork/fish-shell
git clone https://git.julia.blue/fork/fish-shell
4e8d2c706
master
1# based off of the git-prompt script that ships with git 2# hence licensed under GPL version 2 (like the rest of fish). 3# 4# Written by Lily Ballard and updated by Brian Gernhardt and fish contributors 5# 6# This is based on git's git-prompt.bash script, Copyright (C) 2006,2007 Shawn O. Pearce <spearce@spearce.org>. 7# The act of porting the code, along with any new code, are Copyright (C) 2012 Lily Ballard. 8 9function __fish_git_prompt_show_upstream --description"Helper function for fish_git_prompt" 10set -l show_upstream$__fish_git_prompt_showupstream 11set -l svn_prefix# For better SVN upstream information 12set -l informative 13 14set -l svn_url_pattern 15set -l count 16set -l upstream git 17set -l verbose 18set -l name 19 20# Default to informative if __fish_git_prompt_show_informative_status is set 21if contains --" $__fish_git_prompt_show_informative_status " yes true1 22set informative1 23end 24 25set -l svn_remote 26# get some config options from git-config 27command git config -z --get-regexp'^(svn-remote\..*\.url|bash\.showupstream)$' 2> /dev/null| while read -lz key value 28switch $key 29case bash.showupstream 30set show_upstream$value 31test -n " $show_upstream " 32or return 33case svn-remote.'*' .url 34set svn_remote$svn_remote $value 35# Avoid adding \| to the beginning to avoid needing #?? later 36if test -n " $svn_url_pattern " 37set svn_url_pattern$svn_url_pattern "| $value " 38else 39set svn_url_pattern$value 40end 41set upstream svn+git# default upstream is SVN if available, else git 42 43# Save the config key (without .url) for later use 44set -l remote_prefix( string replace -r'\.url$' '' --$key ) 45set svn_prefix$svn_prefix $remote_prefix 46end 47end 48 49# parse configuration variables 50# and clear informative default when needed 51for optionin $show_upstream 52switch $option 53case git svn 54set upstream$option 55set -e informative 56case verbose 57set verbose1 58set -e informative 59case informative 60set informative1 61case name 62set name1 63case none 64return 65end 66end 67 68# Find our upstream 69switch $upstream 70case git 71set upstream'@{upstream}' 72case svn\* 73# get the upstream from the 'git-svn-id: …' in a commit message 74# (git-svn uses essentially the same procedure internally) 75set -l svn_upstream( git log --first-parent-1 --grep="^git-svn-id: \( $svn_url_pattern \)" 2> /dev/null) 76if test ( count $svn_upstream ) -ne 0 77echo $svn_upstream [ -1 ] | read -l __ svn_upstream __ 78set svn_upstream( string replace -r'@.*' '' --$svn_upstream ) 79set -l cur_prefix 80 81for iin ( seq ( count $svn_remote )) 82set -l remote$svn_remote [ $i ] 83set -l mod_upstream( string replace" $remote " "" --$svn_upstream ) 84if test " $svn_upstream " != " $mod_upstream " 85# we found a valid remote 86set svn_upstream$mod_upstream 87set cur_prefix$svn_prefix [ $i ] 88break 89end 90end 91 92if test -z " $svn_upstream " 93# default branch name for checkouts with no layout: 94if test -n " $GIT_SVN_ID " 95set upstream$GIT_SVN_ID 96else 97set upstream git-svn 98end 99else 100set upstream( string replace'/branches' '' --$svn_upstream | string replace -a'/' '' ) 101 102# Use fetch config to fix upstream 103set -l fetch_val( command git config" $cur_prefix " .fetch) 104if test -n " $fetch_val " 105string split -m1 : --" $fetch_val " | read -l trunk pattern 106set upstream( string replace -r --"/ $trunk \$" '' $pattern ) /$upstream 107end 108end 109else if test $upstream = svn+git 110set upstream'@{upstream}' 111end 112end 113 114# Find how many commits we are ahead/behind our upstream 115set count( command git rev-list --count --left-right$upstream ...HEAD2> /dev/null| string replace\t " " ) 116 117# calculate the result 118if test -n " $verbose " 119# Verbose has a space by default 120set -l prefix" $___fish_git_prompt_char_upstream_prefix " 121# Using two underscore version to check if user explicitly set to nothing 122if not set -q __fish_git_prompt_char_upstream_prefix 123set prefix" " 124end 125 126echo $count | read -l behind ahead 127switch " $count " 128case '' # no upstream 129case "0 0" # equal to upstream 130echo " $prefix$___fish_git_prompt_char_upstream_equal " 131case "0 *" # ahead of upstream 132echo " $prefix$___fish_git_prompt_char_upstream_ahead$ahead " 133case "* 0" # behind upstream 134echo " $prefix$___fish_git_prompt_char_upstream_behind$behind " 135case '*' # diverged from upstream 136echo " $prefix$___fish_git_prompt_char_upstream_diverged$ahead - $behind " 137end 138if test -n " $count " -a -n " $name " 139echo " " ( command git rev-parse --abbrev-ref" $upstream " 2> /dev/null) 140end 141else if test -n " $informative " 142echo $count | read -l behind ahead 143switch " $count " 144case '' # no upstream 145case "0 0" # equal to upstream 146case "0 *" # ahead of upstream 147echo " $___fish_git_prompt_char_upstream_prefix$___fish_git_prompt_char_upstream_ahead$ahead " 148case "* 0" # behind upstream 149echo " $___fish_git_prompt_char_upstream_prefix$___fish_git_prompt_char_upstream_behind$behind " 150case '*' # diverged from upstream 151echo " $___fish_git_prompt_char_upstream_prefix$___fish_git_prompt_char_upstream_ahead$ahead$___fish_git_prompt_char_upstream_behind$behind " 152end 153else 154switch " $count " 155case '' # no upstream 156case "0 0" # equal to upstream 157echo " $___fish_git_prompt_char_upstream_prefix$___fish_git_prompt_char_upstream_equal " 158case "0 *" # ahead of upstream 159echo " $___fish_git_prompt_char_upstream_prefix$___fish_git_prompt_char_upstream_ahead " 160case "* 0" # behind upstream 161echo " $___fish_git_prompt_char_upstream_prefix$___fish_git_prompt_char_upstream_behind " 162case '*' # diverged from upstream 163echo " $___fish_git_prompt_char_upstream_prefix$___fish_git_prompt_char_upstream_diverged " 164end 165end 166 167# For the return status 168test " $count " = "0 0" 169end 170 171# Decide if git is safe to run. 172# On Darwin, git is pre-installed as a stub, which will pop a dialog if you run it. 173if string match -q Darwin --( __fish_uname ) && string match -q /usr/bin/git --( command -s git) && type -q xcode-select&& type -q xcrun 174if not xcode-select --print-path&> /dev/null 175# Only the stub git is installed. 176# Do not try to run it. 177function __fish_git_prompt_ready 178return 1 179end 180else 181# git is installed, but on the first run it may be very slow as xcrun needs to populate the cache. 182# Kick it off in the background to populate the cache. 183set -l sh( __fish_posix_shell ) 184$sh -c'( /usr/bin/git --version; touch /tmp/__fish_git_ready ) >/dev/null 2>&1 &' 185function __fish_git_prompt_ready 186path is /tmp/__fish_git_ready|| return 1 187# git is ready, erase the function. 188functions -e __fish_git_prompt_ready 189return 0 190end 191end 192end 193 194function fish_git_prompt --description"Prompt function for Git" 195# If git isn't installed, there's nothing we can do 196# Return 1 so the calling prompt can deal with it 197if not command -sq git 198return 1 199end 200# Fail if __fish_git_prompt_ready is defined and fails. 201if functions -q __fish_git_prompt_ready&& not __fish_git_prompt_ready 202return 1 203end 204set -l repo_info( command git rev-parse --git-dir --git-common-dir --is-inside-git-dir --is-bare-repository --is-inside-work-tree HEAD2> /dev/null) 205test -n " $repo_info " 206or return 207 208set -l git_dir$repo_info [ 1 ] 209set -l git_common_dir$repo_info [ 2 ] 210set -l inside_gitdir$repo_info [ 3 ] 211set -l bare_repo$repo_info [ 4 ] 212set -l inside_worktree$repo_info [ 5 ] 213set -q repo_info[ 6 ] 214and set -l sha$repo_info [ 6 ] 215 216set -l branch_state( __fish_git_prompt_operation_branch_bare $repo_info ) 217set -l operation$branch_state [ 1 ] 218set -l branch$branch_state [ 2 ] 219set -l detached$branch_state [ 3 ] 220set -l dirtystate 221set -l stagedstate 222set -l invalidstate 223set -l stashstate 224set -l untrackedfiles 225set -l bare_prefix$branch_state [ 4 ] 226set -l upstream 227set -l informative_status 228 229set -q __fish_git_prompt_status_order 230or set -g __fish_git_prompt_status_order stagedstate invalidstate dirtystate untrackedfiles stashstate 231 232if not set -q ___fish_git_prompt_init 233# This takes a while, so it only needs to be done once, 234# and then whenever the configuration changes. 235__fish_git_prompt_validate_chars 236__fish_git_prompt_validate_colors 237set -g ___fish_git_prompt_init 238end 239 240set -l space" $___fish_git_prompt_color$___fish_git_prompt_char_stateseparator$___fish_git_prompt_color_done " 241 242# Use our variables as defaults, but allow overrides via the local git config. 243# That means if neither is set, this stays empty. 244# 245# So "!= true" or "!= false" are useful tests if you want to do something by default. 246set -l informative 247set -l dirty 248set -l untracked 249command git config -z --get-regexp'bash\.(showInformativeStatus|showDirtyState|showUntrackedFiles)' 2> /dev/null| while read -lz key value 250switch $key 251case bash.showinformativestatus 252set informative$value 253case bash.showdirtystate 254set dirty$value 255case bash.showuntrackedfiles 256set untracked$value 257end 258end 259 260# If we don't print these, there is no need to compute them. Note: For now, staged and dirty are coupled. 261if not set -q dirty[ 1 ] 262contains --" $__fish_git_prompt_showdirtystate " yes true1 263and set dirty true 264end 265contains dirtystate$__fish_git_prompt_status_order || contains stagedstate$__fish_git_prompt_status_order 266or set dirty false 267 268if not set -q untracked[ 1 ] 269contains --" $__fish_git_prompt_showuntrackedfiles " yes true1 270and set untracked true 271end 272contains untrackedfiles$__fish_git_prompt_status_order 273or set untracked false 274 275if test true= $inside_worktree 276# Use informative status if it has been enabled locally, or it has been 277# enabled globally (via the fish variable) and dirty or untracked are not false. 278# 279# This is to allow overrides for the repository. 280if test " $informative " = true 281or begin 282contains --" $__fish_git_prompt_show_informative_status " yes true1 283and test " $dirty " != false 284end 285set informative_status( untracked=$untracked __fish_git_prompt_informative_status$git_common_dir ) 286if test -n " $informative_status " 287set informative_status" $space$informative_status " 288end 289else 290if not test " $dirty " = true;and test " $untracked " = true 291# Only untracked, ls-files is faster. 292command git -c core.fsmonitor= ls-files --others --exclude-standard --directory --no-empty-directory --error-unmatch -- :/> /dev/null2>&1 293and set untrackedfiles1 294else if test " $dirty " = true 295# With both dirty and untracked, git status is ~10% faster. 296# With just dirty, it's ~20%. 297set -l opt -uno 298test " $untracked " = true;and set opt -unormal 299# Don't use `--ignored=no`; it was introduced in Git 2.16, from January 2018 300# Ignored files are omitted by default 301# Renames and copies in porcelain -z output have an extra NUL-delimited 302# field for the source path. Filter to entries starting with a valid 303# two-char status code followed by a space to skip those bare paths. 304set -l stat( __fish_git_prompt_status_porcelain_modulo_rename_source $opt ) 305 306set dirtystate( string match -qr'^.[ACDMRTU]' --$stat ;and echo 1 ) 307if test -n " $sha " 308set stagedstate( string match -qr'^[ACDMRTU].' --$stat ;and echo 1 ) 309else 310set invalidstate1 311end 312 313test " $untracked " = true 314and set untrackedfiles( string match -qr'\?\?' --$stat ;and echo 1 ) 315end 316 317if contains --" $__fish_git_prompt_showstashstate " yes true1 318and test -r $git_common_dir /logs/refs/stash 319# If we have informative status but don't want to actually 320# *compute* the informative status, we might still count the stash. 321if contains --" $__fish_git_prompt_show_informative_status " yes true1 322set stashstate( count < $git_common_dir /logs/refs/stash) 323else if test -s $git_common_dir /logs/refs/stash 324set stashstate1 325end 326end 327end 328 329# (showupstream has a variety of options, not just bool) 330if set -q __fish_git_prompt_showupstream 331or contains --" $__fish_git_prompt_show_informative_status " yes true1 332set upstream( __fish_git_prompt_show_upstream ) 333end 334end 335 336set -l branch_color$___fish_git_prompt_color_branch 337set -l branch_done$___fish_git_prompt_color_branch_done 338if contains --" $__fish_git_prompt_showcolorhints " yes true1 339if test $detached = yes 340set branch_color$___fish_git_prompt_color_branch_detached 341set branch_done$___fish_git_prompt_color_branch_detached_done 342else if test -n " $dirtystate$untrackedfiles " ;and set -q __fish_git_prompt_color_branch_dirty 343set branch_color( set_color $__fish_git_prompt_color_branch_dirty ) 344set branch_done( set_color $__fish_git_prompt_color_branch_dirty_done ) 345else if test -n " $stagedstate " ;and set -q __fish_git_prompt_color_branch_staged 346set branch_color( set_color $__fish_git_prompt_color_branch_staged ) 347set branch_done( set_color $__fish_git_prompt_color_branch_staged_done ) 348end 349end 350 351set -l flags"" 352for iin $__fish_git_prompt_status_order 353if test -n " $$i " 354set -l color_var ___fish_git_prompt_color_$i 355set -l color_done_var ___fish_git_prompt_color_{ $i } _done 356set -l symbol_var ___fish_git_prompt_char_$i 357 358set -l color$$color_var 359set -l color_done$$color_done_var 360set -l symbol$$symbol_var 361 362# If we count some things, print the number 363# This won't be done if we actually do the full informative status 364# because that does the printing. 365contains --" $__fish_git_prompt_show_informative_status " yes true1 366and set flags" $flags$color$symbol$$i$color_done " 367or set flags" $flags$color$symbol$color_done " 368end 369end 370 371set branch( string replace refs/heads/'' --$branch ) 372# Strip control characters before display. 373set branch( string replace -ra'[[:cntrl:]]' '' --$branch ) 374set operation( string replace -ra'[[:cntrl:]]' '' --$operation ) 375if string match -qr'^\d+$' " $__fish_git_prompt_shorten_branch_len " 376set -q __fish_git_prompt_shorten_branch_char_suffix 377and set -l char -c" $__fish_git_prompt_shorten_branch_char_suffix " 378set branch( string shorten -m" $__fish_git_prompt_shorten_branch_len " $char --" $branch " ) 379end 380if test -n " $branch " 381set branch" $branch_color$branch$branch_done " 382if test -z " $dirtystate$untrackedfiles$stagedstate " ;and test -n " $___fish_git_prompt_char_cleanstate " 383and not contains --" $__fish_git_prompt_show_informative_status " yes true1 384set branch" $branch$___fish_git_prompt_color_cleanstate$___fish_git_prompt_char_cleanstate$___fish_git_prompt_color_cleanstate_done " 385end 386end 387if test -n " $bare_prefix " 388set bare_prefix" $___fish_git_prompt_color_bare$bare_prefix$___fish_git_prompt_color_bare_done " 389end 390if test -n " $operation " 391set operation" $___fish_git_prompt_color_merging$operation$___fish_git_prompt_color_merging_done " 392end 393if test -n " $upstream " 394set upstream" $___fish_git_prompt_color_upstream$upstream$___fish_git_prompt_color_upstream_done " 395end 396 397# Formatting 398# If we have state, a bare repo or upstream difference, add a separator. 399# merging is already separate. 400if test -n " $flags$bare_prefix$upstream " 401set flags" $space$flags " 402end 403set -l format$argv [ 1 ] 404if test -z " $format " 405set format" (%s)" 406end 407 408printf "%s $format %s" " $___fish_git_prompt_color_prefix " " $___fish_git_prompt_color_prefix_done$bare_prefix$branch$flags$operation$upstream$informative_status$___fish_git_prompt_color_suffix " " $___fish_git_prompt_color_suffix_done " 409end 410 411### helper functions 412 413function __fish_git_prompt_status_porcelain_modulo_rename_source 414set -l skip false 415for linein ( git -c core.fsmonitor= status --porcelain -z$argv | string split0) 416if $skip 417set skip false 418continue 419end 420printf %s\n $line 421if string match -rq -- ^[ RC] $line 422set skip true 423end 424end 425end 426 427function __fish_git_prompt_informative_status 428set -l stashstate0 429set -l stashfile" $argv [ 1 ] /logs/refs/stash" 430if contains --" $__fish_git_prompt_showstashstate " yes true1 ;and test -e " $stashfile " 431set stashstate( count < $stashfile ) 432end 433 434# If we're not told to show untracked files, we don't. 435# If we are, we still use the "normal" mode because it's a lot faster, 436# and it's unlikely anyone cares about the number of files if it's *all* of the files 437# in that directory. 438set -l untr -uno 439test " $untracked " = true 440and set untr -unormal 441 442# Use git status --porcelain. 443# The v2 format is better, but we don't actually care in this case. 444# Renames and copies in porcelain -z output have an extra NUL-delimited 445# field for the source path. Filter to entries starting with a valid 446# two-char status code followed by a space to skip those bare paths. 447set -l stats( __fish_git_prompt_status_porcelain_modulo_rename_source $untr ) 448set -l invalidstate( string match -r'^UU' $stats | count ) 449set -l stagedstate( string match -r'^[ACDMRT].' $stats | count ) 450set -l dirtystate( string match -r'^.[ACDMRT]' $stats | count ) 451set -l untrackedfiles( string match -r'^\?\?' $stats | count ) 452 453set -l info 454 455if test " $dirtystate$invalidstate$stagedstate$untrackedfiles$stashstate " = 00000 456if test -n " $___fish_git_prompt_char_cleanstate " 457set info$___fish_git_prompt_color_cleanstate$___fish_git_prompt_char_cleanstate$___fish_git_prompt_color_cleanstate_done 458end 459else 460for iin $__fish_git_prompt_status_order 461if test $$i != 0 462set -l color_var ___fish_git_prompt_color_$i 463set -l color_done_var ___fish_git_prompt_color_{ $i } _done 464set -l symbol_var ___fish_git_prompt_char_$i 465 466set -l color$$color_var 467set -l color_done$$color_done_var 468set -l symbol$$symbol_var 469 470set -l count 471 472if not set -q __fish_git_prompt_hide_$i 473set count$$i 474end 475 476set info" $info$color$symbol$count$color_done " 477end 478end 479end 480 481echo $info 482 483end 484 485# Keeping these together avoids many duplicated checks 486function __fish_git_prompt_operation_branch_bare --description"fish_git_prompt helper, returns the current Git operation and branch" 487# This function is passed the full repo_info array 488set -l git_dir$argv [ 1 ] 489set -l inside_gitdir$argv [ 3 ] 490set -l bare_repo$argv [ 4 ] 491set -q argv[ 6 ] 492and set -l sha$argv [ 6 ] 493 494set -l branch 495set -l operation 496set -l detached no 497set -l bare 498set -l step 499set -l total 500 501if test -d $git_dir /rebase-merge 502set branch( cat $git_dir /rebase-merge/head-name2> /dev/null) 503set step( cat $git_dir /rebase-merge/msgnum2> /dev/null) 504set total( cat $git_dir /rebase-merge/end2> /dev/null) 505if test -f $git_dir /rebase-merge/interactive 506set operation"|REBASE-i" 507else 508set operation"|REBASE-m" 509end 510else 511if test -d $git_dir /rebase-apply 512set step( cat $git_dir /rebase-apply/next2> /dev/null) 513set total( cat $git_dir /rebase-apply/last2> /dev/null) 514if test -f $git_dir /rebase-apply/rebasing 515set branch( cat $git_dir /rebase-apply/head-name2> /dev/null) 516set operation"|REBASE" 517else if test -f $git_dir /rebase-apply/applying 518set operation"|AM" 519else 520set operation"|AM/REBASE" 521end 522else if test -f $git_dir /MERGE_HEAD 523set operation"|MERGING" 524else if test -f $git_dir /CHERRY_PICK_HEAD 525set operation"|CHERRY-PICKING" 526else if test -f $git_dir /REVERT_HEAD 527set operation"|REVERTING" 528else if test -f $git_dir /BISECT_LOG 529set operation"|BISECTING" 530end 531end 532 533if test -n " $step " -a -n " $total " 534set operation" $operation $step / $total " 535end 536 537if test -z " $branch " 538if not set branch( command git symbolic-ref HEAD2> /dev/null) 539set detached yes 540set branch( switch " $__fish_git_prompt_describe_style " 541case contains 542command git describe --contains HEAD 543case branch 544command git describe --contains --all HEAD 545case describe 546command git describe HEAD 547case default'*' 548command git describe --tags --exact-match HEAD 549end 2> /dev/null) 550if test $status -ne 0 551# Shorten the sha ourselves to 8 characters - this should be good for most repositories, 552# and even for large ones it should be good for most commits 553# No need for an ellipsis. 554if set -q sha 555set branch( string shorten -m8 -c"" --$sha ) 556else 557set branch unknown 558end 559end 560set branch" ( $branch ) " 561end 562end 563 564if test true= $inside_gitdir 565if test true= $bare_repo 566set bare"BARE:" 567else 568# Let user know they're inside the git dir of a non-bare repo 569set branch"GIT_DIR!" 570end 571end 572 573echo $operation 574echo $branch 575echo $detached 576echo $bare 577end 578 579function __fish_git_prompt_set_char 580set -l user_variable_name" $argv [ 1 ] " 581set -l char$argv [ 2 ] 582 583if set -q argv[ 3 ] 584and begin 585contains --" $__fish_git_prompt_show_informative_status " yes true1 586or contains --" $__fish_git_prompt_use_informative_chars " yes true1 587end 588set char$argv [ 3 ] 589end 590 591set -l variable _$user_variable_name 592set -l variable_done" $variable " _done 593 594if not set -q$variable 595set -g$variable ( set -q$user_variable_name ;and echo $$user_variable_name ;or echo $char ) 596end 597end 598 599function __fish_git_prompt_validate_chars --description"fish_git_prompt helper, checks char variables" 600# cleanstate is only defined with actual informative status. 601contains --" $__fish_git_prompt_show_informative_status " yes true1 602and __fish_git_prompt_set_char __fish_git_prompt_char_cleanstate'✔' 603or __fish_git_prompt_set_char __fish_git_prompt_char_cleanstate'' 604 605__fish_git_prompt_set_char __fish_git_prompt_char_dirtystate'*' '✚' 606__fish_git_prompt_set_char __fish_git_prompt_char_invalidstate'#' '✖' 607__fish_git_prompt_set_char __fish_git_prompt_char_stagedstate'+' '●' 608__fish_git_prompt_set_char __fish_git_prompt_char_stashstate'$' '⚑' 609__fish_git_prompt_set_char __fish_git_prompt_char_stateseparator' ' '|' 610__fish_git_prompt_set_char __fish_git_prompt_char_untrackedfiles'%' '…' 611__fish_git_prompt_set_char __fish_git_prompt_char_upstream_ahead'>' '↑' 612__fish_git_prompt_set_char __fish_git_prompt_char_upstream_behind'<' '↓' 613__fish_git_prompt_set_char __fish_git_prompt_char_upstream_diverged'<>' '↓↑' 614__fish_git_prompt_set_char __fish_git_prompt_char_upstream_equal'=' 615__fish_git_prompt_set_char __fish_git_prompt_char_upstream_prefix'' 616 617end 618 619function __fish_git_prompt_set_color 620set -l user_variable_name" $argv [ 1 ] " 621 622set -l default 623set -l default_done 624 625switch ( count $argv ) 626case 1 # No defaults given, use prompt color 627set default$___fish_git_prompt_color 628set default_done$___fish_git_prompt_color_done 629case 2 # One default given, use "--reset" for done 630set default" $argv [ 2 ] " 631set default_done( set_color --reset) 632case 3 # Both defaults given 633set default" $argv [ 2 ] " 634set default_done" $argv [ 3 ] " 635end 636 637set -l variable _$user_variable_name 638set -l variable_done" $variable " _done 639 640if not set -q$variable 641if test -n " $$user_variable_name " 642set -g$variable ( set_color $$user_variable_name ) 643set -g$variable_done ( set_color --reset) 644else 645set -g$variable $default 646set -g$variable_done $default_done 647end 648end 649end 650 651function __fish_git_prompt_validate_colors --description"fish_git_prompt helper, checks color variables" 652 653# Base color defaults to nothing (must be done first) 654__fish_git_prompt_set_color __fish_git_prompt_color'' '' 655 656# Normal colors 657__fish_git_prompt_set_color __fish_git_prompt_color_prefix 658__fish_git_prompt_set_color __fish_git_prompt_color_suffix 659__fish_git_prompt_set_color __fish_git_prompt_color_bare 660__fish_git_prompt_set_color __fish_git_prompt_color_merging 661__fish_git_prompt_set_color __fish_git_prompt_color_cleanstate 662__fish_git_prompt_set_color __fish_git_prompt_color_invalidstate 663__fish_git_prompt_set_color __fish_git_prompt_color_upstream 664 665# Colors with defaults with showcolorhints 666if contains --" $__fish_git_prompt_showcolorhints " yes true1 667__fish_git_prompt_set_color __fish_git_prompt_color_flags( set_color --bold blue) 668__fish_git_prompt_set_color __fish_git_prompt_color_branch( set_color green) 669__fish_git_prompt_set_color __fish_git_prompt_color_dirtystate( set_color red) 670__fish_git_prompt_set_color __fish_git_prompt_color_stagedstate( set_color green) 671else 672__fish_git_prompt_set_color __fish_git_prompt_color_flags 673__fish_git_prompt_set_color __fish_git_prompt_color_branch 674__fish_git_prompt_set_color __fish_git_prompt_color_dirtystate$___fish_git_prompt_color_flags $___fish_git_prompt_color_flags_done 675__fish_git_prompt_set_color __fish_git_prompt_color_stagedstate$___fish_git_prompt_color_flags $___fish_git_prompt_color_flags_done 676end 677 678# Branch_detached has a default, but is only used with showcolorhints 679__fish_git_prompt_set_color __fish_git_prompt_color_branch_detached( set_color red) 680 681# Colors that depend on flags color 682__fish_git_prompt_set_color __fish_git_prompt_color_stashstate$___fish_git_prompt_color_flags $___fish_git_prompt_color_flags_done 683__fish_git_prompt_set_color __fish_git_prompt_color_untrackedfiles$___fish_git_prompt_color_flags $___fish_git_prompt_color_flags_done 684 685end 686 687function __fish_git_prompt_reset -a type -a op -a var --description"Event handler, resets prompt when functionality changes" \ 688 --on-variable=__fish_git_prompt_{ show_informative_status, use_informative_chars} 689# Clear characters that have different defaults with/without informative status 690set -e ___fish_git_prompt_char_{ name, cleanstate, dirtystate, invalidstate, stagedstate, stashstate, stateseparator, untrackedfiles, upstream_ahead, upstream_behind} 691# Clear init so we reset the chars next time. 692set -e ___fish_git_prompt_init 693end 694 695function __fish_git_prompt_reset_color -a type -a op -a var --description"Event handler, resets prompt when any color changes" \ 696 --on-variable=__fish_git_prompt_color{ '' , _prefix, _suffix, _bare, _merging, _cleanstate, _invalidstate, _upstream, _flags, _branch, _dirtystate, _stagedstate, _branch_detached, _stashstate, _untrackedfiles} --on-variable=__fish_git_prompt_showcolorhints 697set -e _$var 698set -e _{ $var } _done 699set -e ___fish_git_prompt_init 700if contains --$var __fish_git_prompt_color __fish_git_prompt_color_flags __fish_git_prompt_showcolorhints 701# reset all the other colors too 702set -e ___fish_git_prompt_color_{ prefix, suffix, bare, merging, branch, dirtystate, stagedstate, invalidstate, stashstate, untrackedfiles, upstream, flags}{, _done} 703end 704end 705 706function __fish_git_prompt_reset_char -a type -a op -a var --description"Event handler, resets prompt when any char changes" \ 707 --on-variable=__fish_git_prompt_char_{ cleanstate, dirtystate, invalidstate, stagedstate, stashstate, stateseparator, untrackedfiles, upstream_ahead, upstream_behind, upstream_diverged, upstream_equal, upstream_prefix} 708set -e ___fish_git_prompt_init 709set -e _$var 710end