summaryrefslogtreecommitdiff
path: root/.config/fisher/github.com/matchai/spacefish/functions/__sf_section_git_status.fish
diff options
context:
space:
mode:
authorRoger Gonzalez <rogergonzalez21@gmail.com>2019-12-29 14:58:33 -0300
committerRoger Gonzalez <rogergonzalez21@gmail.com>2019-12-29 14:58:33 -0300
commitefb336a23b65a9a2d56889396b13c1757bdaf354 (patch)
tree234e40115f79a84c8a755df6fb932cc6797e36e1 /.config/fisher/github.com/matchai/spacefish/functions/__sf_section_git_status.fish
Initial commit
Diffstat (limited to '.config/fisher/github.com/matchai/spacefish/functions/__sf_section_git_status.fish')
-rw-r--r--.config/fisher/github.com/matchai/spacefish/functions/__sf_section_git_status.fish100
1 files changed, 100 insertions, 0 deletions
diff --git a/.config/fisher/github.com/matchai/spacefish/functions/__sf_section_git_status.fish b/.config/fisher/github.com/matchai/spacefish/functions/__sf_section_git_status.fish
new file mode 100644
index 00000000..7316c491
--- /dev/null
+++ b/.config/fisher/github.com/matchai/spacefish/functions/__sf_section_git_status.fish
@@ -0,0 +1,100 @@
+#
+# Git status
+#
+
+function __sf_section_git_status -d "Display the current git status"
+ # ------------------------------------------------------------------------------
+ # Configuration
+ # ------------------------------------------------------------------------------
+
+ __sf_util_set_default SPACEFISH_GIT_STATUS_SHOW true
+ __sf_util_set_default SPACEFISH_GIT_STATUS_PREFIX " ["
+ __sf_util_set_default SPACEFISH_GIT_STATUS_SUFFIX ]
+ __sf_util_set_default SPACEFISH_GIT_STATUS_COLOR red
+ __sf_util_set_default SPACEFISH_GIT_STATUS_UNTRACKED \?
+ __sf_util_set_default SPACEFISH_GIT_STATUS_ADDED +
+ __sf_util_set_default SPACEFISH_GIT_STATUS_MODIFIED !
+ __sf_util_set_default SPACEFISH_GIT_STATUS_RENAMED »
+ __sf_util_set_default SPACEFISH_GIT_STATUS_DELETED ✘
+ __sf_util_set_default SPACEFISH_GIT_STATUS_STASHED \$
+ __sf_util_set_default SPACEFISH_GIT_STATUS_UNMERGED =
+ __sf_util_set_default SPACEFISH_GIT_STATUS_AHEAD ⇡
+ __sf_util_set_default SPACEFISH_GIT_STATUS_BEHIND ⇣
+ __sf_util_set_default SPACEFISH_GIT_STATUS_DIVERGED ⇕
+ __sf_util_set_default SPACEFISH_GIT_PROMPT_ORDER untracked added modified renamed deleted stashed unmerged diverged ahead behind
+
+ # ------------------------------------------------------------------------------
+ # Section
+ # ------------------------------------------------------------------------------
+
+ [ $SPACEFISH_GIT_STATUS_SHOW = false ]; and return
+
+ set -l git_status
+ set -l is_ahead
+ set -l is_behind
+
+ set -l index (command git status --porcelain 2>/dev/null -b)
+ set -l trimmed_index (string split \n $index | string sub --start 1 --length 2)
+
+ for i in $trimmed_index
+ if test (string match '\?\?' $i)
+ set git_status untracked $git_status
+ end
+ if test (string match '*A*' $i)
+ set git_status added $git_status
+ end
+ if test (string match '*M*' $i)
+ set git_status modified $git_status
+ end
+ if test (string match '*R*' $i)
+ set git_status renamed $git_status
+ end
+ if test (string match '*D*' $i)
+ set git_status deleted $git_status
+ end
+ if test (string match '*U*' $i)
+ set git_status unmerged $git_status
+ end
+ end
+
+ # Check for stashes
+ if test -n (echo (command git rev-parse --verify refs/stash 2>/dev/null))
+ set git_status stashed $git_status
+ end
+
+ # Check whether the branch is ahead
+ if test (string match '*ahead*' $index)
+ set is_ahead true
+ end
+
+ # Check whether the branch is behind
+ if test (string match '*behind*' $index)
+ set is_behind true
+ end
+
+ # Check whether the branch has diverged
+ if test "$is_ahead" = "true" -a "$is_behind" = "true"
+ set git_status diverged $git_status
+ else if test "$is_ahead" = "true"
+ set git_status ahead $git_status
+ else if test "$is_behind" = "true"
+ set git_status behind $git_status
+ end
+
+ set -l full_git_status
+ for i in $SPACEFISH_GIT_PROMPT_ORDER
+ set i (string upper $i)
+ set git_status (string upper $git_status)
+ if contains $i in $git_status
+ set -l status_symbol SPACEFISH_GIT_STATUS_$i
+ set full_git_status "$$status_symbol$full_git_status"
+ end
+ end
+
+ # Check if git status
+ if test -n "$full_git_status"
+ __sf_lib_section \
+ $SPACEFISH_GIT_STATUS_COLOR \
+ "$SPACEFISH_GIT_STATUS_PREFIX$full_git_status$SPACEFISH_GIT_STATUS_SUFFIX"
+ end
+end