-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgit-patch.zsh
More file actions
55 lines (50 loc) · 1.48 KB
/
git-patch.zsh
File metadata and controls
55 lines (50 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# Returns 0 when not in a git repo, 1 otherwise
function git_is_repo() {
local ref
ref=$(command git symbolic-ref HEAD 2> /dev/null) || \
ref=$(command git rev-parse --short HEAD 2> /dev/null) || \
return 0
return 1
}
# Outputs the name of the current branch
#
# Copied with minor modification from
# github.com/robbyrussell/oh-my-zsh@2eb3e9d57cf69f3c2fa557f9047e0a648d80b235
function git_current_branch() {
local ref
ref=$(command git symbolic-ref --quiet HEAD 2> /dev/null) || \
ref=$(command git rev-parse --short HEAD 2> /dev/null)
local ret=$?
if [[ $ret != 0 ]]; then
[[ $ret == 128 ]] && return # no git repo.
ref=$(command git rev-parse --short HEAD 2> /dev/null) || return
fi
echo "${ref#refs/heads/}"
}
# Checks whether working tree is dirty and outputs apropriate
# prompt variable
function git_working_tree_status() {
local changes
changes=$(command git status --porcelain 2> /dev/null | tail -n1)
if [[ -n $changes ]]; then
echo "${PROMPT_GIT_DIRTY}"
else
echo "${PROMPT_GIT_CLEAN}"
fi
}
# Outputs the current tag if one exists
function git_current_tag() {
local ref
ref=$(command git describe --tags --abbrev=0 2> /dev/null)
local ret=$?
[[ $ret != 0 ]] && return # lazy
echo $(echo "($ref)" | tr -d "\n")
}
# Outputs the number of commits ahead of the latest tag
function git_commits_ahead_of_tag() {
local ref
ref=$(command git describe --tags --long 2> /dev/null)
local ret=$?
[[ $ret != 0 ]] && return
echo $(echo $ref | rev | cut -f 2 -d "-" | rev)
}