Squashed commit of the following:

commit 4a9595845111bcc8d45419241f8f49bc3e8b3445
Author: Harm Aarts <harmaarts@gmail.com>
Date:   Fri May 24 10:45:58 2013 +0200

    use the new functions

commit 1c934ebbe65a82e92079952b15f31d3a92bc5e8f
Author: Harm Aarts <harmaarts@gmail.com>
Date:   Fri May 24 10:45:21 2013 +0200

    moves formatting code to the bottom in order to get it out of the way of all the colour handling

commit c62f827143c30f6810026c7e4a3d8b77178cd9a4
Author: Harm Aarts <harmaarts@gmail.com>
Date:   Fri May 24 10:44:12 2013 +0200

    adds helper returning whether or not there are staged files

commit 624e47cb85a7579bf284a6a7f0c9165dfa38b0ce
Author: Harm Aarts <harmaarts@gmail.com>
Date:   Fri May 24 10:43:41 2013 +0200

    adds helper returning whether or not the current branch is dirty

commit efc270da7b0998f564a7d2ae4ea3013ed6910e58
Author: Harm Aarts <harmaarts@gmail.com>
Date:   Fri May 24 10:42:48 2013 +0200

    adds helper returning whether or not a repo is bare

commit 0da668316cedb8e3fa166977be82c917ef67ad86
Author: Harm Aarts <harmaarts@gmail.com>
Date:   Fri May 24 10:41:55 2013 +0200

    adds helper returning current branch

commit 15cbcedc77199aea1868faee5d178d9547a4d541
Author: Harm Aarts <harmaarts@gmail.com>
Date:   Fri May 24 10:41:10 2013 +0200

    adds helper returning current operation

commit c3352d3e9e60bf94fd4bf412ad85d62bba4cbff8
Author: Harm Aarts <harmaarts@gmail.com>
Date:   Fri May 24 10:40:20 2013 +0200

    adds helper returning the git dir

commit f346e52b7814ebf1eed55f006c3bedc8ece38e3b
Author: Harm Aarts <harmaarts@gmail.com>
Date:   Mon May 20 18:52:19 2013 +0200

    use the fish_git_prompt_char_* variables
This commit is contained in:
ridiculousfish 2013-05-24 23:15:46 -07:00
parent c2616e385c
commit 37123ee053

View file

@ -193,115 +193,54 @@ function __fish_git_prompt_show_upstream --description "Helper function for __fi
switch "$count"
case '' # no upstream
case "0 0" # equal to upstream
echo " u="
echo " $___fish_git_prompt_char_upstream_equal"
case "0 *" # ahead of upstream
echo " u+$ahead"
echo " $___fish_git_prompt_char_upstream_ahead$ahead"
case "* 0" # behind upstream
echo " u-$behind"
echo " $___fish_git_prompt_char_upstream_behind$behind"
case '*' # diverged from upstream
echo " u+$ahead-$behind"
echo " $__fish_git_prompt_char_upstream_diverged$ahead-$behind"
end
end
end
function __fish_git_prompt --description "Prompt function for Git"
# find the enclosing git dir
set -l git_dir
if test -d .git
set git_dir .git
else
set git_dir (git rev-parse --git-dir ^/dev/null)
end
set -l git_dir (__fish_git_prompt_git_dir)
test -n "$git_dir"; or return
set -l r
set -l b
if test -f $git_dir/rebase-merge/interactive
set r "|REBASE-i"
set b (cat $git_dir/rebase-merge/head-name)
else if test -d $git_dir/rebase-merge
set r "|REBASE-m"
set b (cat $git_dir/rebase-merge/head-name)
else
if test -d $git_dir/rebase-apply
if test -f $git_dir/rebase-apply/rebasing
set r "|REBASE"
else if test -f $git_dir/rebase-apply/applying
set r "|AM"
else
set r "|AM/REBASE"
end
else if test -f $git_dir/MERGE_HEAD
set r "|MERGING"
else if test -f $git_dir/CHERRY_PICK_HEAD
set r "|CHERRY-PICKING"
else if test -f $git_dir/BISECT_LOG
set r "|BISECTING"
end
set -l os
set b (git symbolic-ref HEAD ^/dev/null; set os $status)
if test $os -ne 0
set b (switch "$__fish_git_prompt_describe_style"
case contains
git describe --contains HEAD
case branch
git describe --contains --all HEAD
case describe
git describe HEAD
case default '*'
git describe --tags --exact-match HEAD
end ^/dev/null; set os $status)
if test $os -ne 0
set b (cut -c1-7 $git_dir/HEAD ^/dev/null; set os $status)
if test $os -ne 0
set b unknown
end
end
set b "($b)"
end
end
set -l w
set -l i
set -l s
set -l u
set -l c
set -l p
set -l r (__fish_git_prompt_current_operation $git_dir)
set -l b (__fish_git_prompt_current_branch)
set -l w #dirty working directory
set -l i #staged changes
set -l s #stashes
set -l u #untracked
set -l c (__fish_git_prompt_current_branch_bare)
set -l p #upstream
__fish_git_prompt_validate_chars
if test "true" = (git rev-parse --is-inside-git-dir ^/dev/null)
if test "true" = (git rev-parse --is-bare-repository ^/dev/null)
set c "BARE:"
else
set b "GIT_DIR!"
end
else if test "true" = (git rev-parse --is-inside-work-tree ^/dev/null)
if test -n "$__fish_git_prompt_showdirtystate"
set -l config (git config --bool bash.showDirtyState)
if test "$config" != "false"
git diff --no-ext-diff --quiet --exit-code; or set w $___fish_git_prompt_char_dirtystate
if git rev-parse --quiet --verify HEAD >/dev/null
git diff-index --cached --quiet HEAD --; or set i $___fish_git_prompt_char_stagedstate
else
set i $___fish_git_prompt_char_invalidstate
end
end
end
if test -n "$__fish_git_prompt_showstashstate"
git rev-parse --verify refs/stash >/dev/null ^&1; and set s $___fish_git_prompt_char_stashstate
end
if test "true" = (git rev-parse --is-inside-work-tree ^/dev/null)
if test -n "$__fish_git_prompt_showdirtystate"
set -l config (git config --bool bash.showDirtyState)
if test "$config" != "false"
set w (__fish_git_prompt_dirty)
set i (__fish_git_prompt_staged)
end
end
if test -n "$__fish_git_prompt_showuntrackedfiles"
set -l files (git ls-files --others --exclude-standard)
if test -n "$files"
set u $___fish_git_prompt_char_untrackedfiles
end
end
if test -n "$__fish_git_prompt_showstashstate"
git rev-parse --verify refs/stash >/dev/null ^&1; and set s $___fish_git_prompt_char_stashstate
end
if test -n "$__fish_git_prompt_showupstream"
set p (__fish_git_prompt_show_upstream)
if test -n "$__fish_git_prompt_showuntrackedfiles"
set -l files (git ls-files --others --exclude-standard)
if test -n "$files"
set u $___fish_git_prompt_char_untrackedfiles
end
end
if test -n "$__fish_git_prompt_showupstream"
set p (__fish_git_prompt_show_upstream)
end
end
@ -319,14 +258,6 @@ function __fish_git_prompt --description "Prompt function for Git"
if test -n "$u"
set u "$___fish_git_prompt_color_untrackedfiles$u$___fish_git_prompt_color_untrackedfiles_done"
end
set -l f "$w$i$s$u"
set -l format $argv[1]
if test -z "$format"
set format " (%s)"
end
if test -n "$f"
set f " $f"
end
set b (/bin/sh -c 'echo "${1#refs/heads/}"' -- $b)
if test -n "$b"
set b "$___fish_git_prompt_color_branch$b$___fish_git_prompt_color_branch_done"
@ -340,11 +271,121 @@ function __fish_git_prompt --description "Prompt function for Git"
if test -n "$p"
set p "$___fish_git_prompt_color_upstream$p$___fish_git_prompt_color_upstream_done"
end
# Formatting
set -l f "$w$i$s$u"
if test -n "$f"
set f " $f"
end
set -l format $argv[1]
if test -z "$format"
set format " (%s)"
end
printf "%s$format%s" "$___fish_git_prompt_color_prefix" "$___fish_git_prompt_color_prefix_done$c$b$f$r$p$___fish_git_prompt_color_suffix" "$___git_ps_color_suffix_done"
end
### helper functions
function __fish_git_prompt_staged --description "__fish_git_prompt helper, tells whether or not the current branch has staged files"
set -l staged
if git rev-parse --quiet --verify HEAD >/dev/null
git diff-index --cached --quiet HEAD --; or set staged $___fish_git_prompt_char_stagedstate
else
set staged $___fish_git_prompt_char_invalidstate
end
end
function __fish_git_prompt_dirty --description "__fish_git_prompt helper, tells whether or not the current branch has tracked, modified files"
set -l dirty
set -l os
git diff --no-ext-diff --quiet --exit-code
set os $status
if test $os -ne 0
set dirty $___fish_git_prompt_char_dirtystate
end
echo $dirty
end
function __fish_git_prompt_current_branch_bare --description "__fish_git_prompt helper, tells wheter or not the current branch is bare"
set -l bare
if test "true" = (git rev-parse --is-inside-git-dir ^/dev/null)
if test "true" = (git rev-parse --is-bare-repository ^/dev/null)
set bare "BARE:"
end
end
echo $bare
end
function __fish_git_prompt_current_branch --description "__fish_git_prompt helper, returns the current Git branch"
set -l branch
set -l os
set branch (git symbolic-ref HEAD ^/dev/null; set os $status)
if test $os -ne 0
set branch (switch "$__fish_git_prompt_describe_style"
case contains
git describe --contains HEAD
case branch
git describe --contains --all HEAD
case describe
git describe HEAD
case default '*'
git describe --tags --exact-match HEAD
end ^/dev/null; set os $status)
if test $os -ne 0
set branch (cut -c1-7 $git_dir/HEAD ^/dev/null; set os $status)
if test $os -ne 0
set branch unknown
end
end
set branch "($branch)"
end
# I honestly don't know when this is relevant
if test "true" = (git rev-parse --is-inside-git-dir ^/dev/null)
if test "false" = (git rev-parse --is-bare-repository ^/dev/null)
set branch "GIT_DIR!"
end
end
echo $branch
end
function __fish_git_prompt_current_operation --description "__fish_git_prompt helper, returns the current Git operation being performed"
set -l operation
set -l git_dir $argv[1]
if test -f $git_dir/rebase-merge/interactive
set operation "|REBASE-i"
else if test -d $git_dir/rebase-merge
set operation "|REBASE-m"
else
if test -d $git_dir/rebase-apply
if test -f $git_dir/rebase-apply/rebasing
set operation "|REBASE"
else if test -f $git_dir/rebase-apply/applying
set operation "|AM"
else
set operation "|AM/REBASE"
end
else if test -f $git_dir/MERGE_HEAD
set operation "|MERGING"
else if test -f $git_dir/CHERRY_PICK_HEAD
set operation "|CHERRY-PICKING"
else if test -f $git_dir/BISECT_LOG
set operation "|BISECTING"
end
end
echo $operation
end
function __fish_git_prompt_git_dir --description "__fish_git_prompt helper, returns .git dir if any"
echo (git rev-parse --git-dir ^/dev/null)
end
function __fish_git_prompt_validate_chars --description "__fish_git_prompt helper, checks char variables"
if not set -q ___fish_git_prompt_char_dirtystate
set -g ___fish_git_prompt_char_dirtystate (set -q __fish_git_prompt_char_dirtystate; and echo $__fish_git_prompt_char_dirtystate; or echo '*')