diff options
author | Brian Gernhardt <brian@gernhardtsoftware.com> | 2013-07-02 11:15:34 -0400 |
---|---|---|
committer | Brian Gernhardt <brian@gernhardtsoftware.com> | 2013-07-26 16:10:33 -0400 |
commit | 5753fa2106688115802eaae79005e1ec87f309e9 (patch) | |
tree | aa02654441c4dcd7f0e0dfdc281caf1a8a5b1ef7 /share/functions/__fish_git_prompt.fish | |
parent | 31b01f8de338ae4a5f055f4e589aa440bee9e893 (diff) |
git_prompt: Merge operation, branch, and bare helpers
Operation and branch detection are merged together in the original
because branch information may come from different places depending on
the operation.
Merging the bare helper in helps avoid testing for the working
directory and bare status twice, both of which requires forking a new
process.
Also helps the code match the original more, which will make adding
new features easier.
Diffstat (limited to 'share/functions/__fish_git_prompt.fish')
-rw-r--r-- | share/functions/__fish_git_prompt.fish | 78 |
1 files changed, 35 insertions, 43 deletions
diff --git a/share/functions/__fish_git_prompt.fish b/share/functions/__fish_git_prompt.fish index b36aa052..84ce0901 100644 --- a/share/functions/__fish_git_prompt.fish +++ b/share/functions/__fish_git_prompt.fish @@ -232,13 +232,14 @@ function __fish_git_prompt --description "Prompt function for Git" set -l git_dir (__fish_git_prompt_git_dir) test -n "$git_dir"; or return - set -l r (__fish_git_prompt_current_operation $git_dir) - set -l b (__fish_git_prompt_current_branch $git_dir) + set -l rbc (__fish_git_prompt_operation_branch_bare $git_dir) + set -l r $rbc[1] # current operation + set -l b $rbc[2] # 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 c $rbc[3] # bare repository set -l p #upstream set -l informative_status @@ -379,22 +380,36 @@ function __fish_git_prompt_informative_status end -function __fish_git_prompt_current_branch_bare --description "__fish_git_prompt helper, tells wheter or not the current branch is bare" +# Keeping these together avoids many duplicated checks +function __fish_git_prompt_operation_branch_bare --description "__fish_git_prompt helper, returns the current Git operation and branch" + set -l git_dir $argv[1] + set -l branch + set -l operation set -l bare + set -l os - 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:" + 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 $bare -end -function __fish_git_prompt_current_branch --description "__fish_git_prompt helper, returns the current Git branch" - set -l git_dir $argv[1] - 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" @@ -416,41 +431,18 @@ function __fish_git_prompt_current_branch --description "__fish_git_prompt helpe set branch "($branch)" end - # Let user know they're inside the git dir of a non-bare repo if test "true" = (git rev-parse --is-inside-git-dir ^/dev/null) - if test "false" = (git rev-parse --is-bare-repository ^/dev/null) + if test "true" = (git rev-parse --is-bare-repository ^/dev/null) + set bare "BARE:" + else + # Let user know they're inside the git dir of a non-bare repo 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 + echo $branch + echo $bare end function __fish_git_prompt_git_dir --description "__fish_git_prompt helper, returns .git dir if any" |