-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.io_bash_extras_git
168 lines (153 loc) · 3.52 KB
/
.io_bash_extras_git
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
# -- git -- ##
#
#
# @name gst
# @author Jeremy Grier <jeremy.grier@iostudo.com>
# @description Will call git status for the current directory
function glmine {
#defaults
# @author
if [ -n "${1}" ]; then
author="${1}"
else
author="$( git config --global --get user.email )"
fi
git log --author=${author} .
}
function gfo {
git fetch origin
}
function gst {
git status .
git stash list
}
function gco {
if [ -n "${1}" ]; then
branch_choice="${1}"
else
branch_choice="master"
fi
git checkout "${branch_choice}"
}
function gpo {
if [ -n "${1}" ]; then
branch_choice="${1}"
else
## - ask option to use master as default
exit 127
fi
git pull origin "${branch_choice}"
}
function gaa {
git add --all
}
## ** git cleanup functions ** ##
#**
#
# git clean checkout deleted items
# cleans all of the files in git's staging area ( labeled deleted: )
#
##
function gccd {
git checkout -- $( gst | grep "deleted:" | rev | cut -f 1 -d " " | rev )
}
#**
#
# git clean checkout modified items
# cleans all of the files in git's staging area ( labeled modified: )
#
##
function gccm {
git checkout -- $( gst | grep "modified:" | rev | cut -f 1 -d " " | rev )
}
#**
#
# git clean checkout new file items
# cleans all of the files in git's staging area ( labeled "new file:" )
#
##
function gccn {
git checkout -- $( gst | grep "new file:" | rev | cut -f 1 -d ":" | rev | sed -e 's/^[ ]*\(.*\)/\1/' | grep Data | sed -e 's/[ ]/\\&/g' )
}
#**
#
# git clean checkout new file items
# cleans all of the files in git's staging area ( labeled "new file:" )
#
##
function grcn {
git reset HEAD $( gst | grep "new file:" | rev | cut -f 1 -d ":" | rev | sed -e 's/^[ ]*\(.*\)/\1/' | grep Data | sed -e 's/[ ]/\\&/g' )
}
#**
#
# git clean checkout all items (using above functions) *equivalent to "git checkout ."
# cleans all of the files in git's staging area ( all )
#
##
function gcc {
gccd
gccm
gccn
}
## -- function git-diff-head -- ##
function gdh { git diff HEAD "${1}" ; }
function gml {
if [ -n "${1}" ]; then
branch="${1}"
else
branch="develop"
fi
## -- run command -- ##
git merge ${branch}
}
function gmo {
if [ -n "${1}" ]; then
origin_branch="${1}"
else
origin_branch="develop"
fi
## -- run command -- ##
git merge ${origin_branch}
}
## -- function git log --name-only -- ##
function glno {
git log --name-only
}
## -- branch functions -- ##
function gba {
git branch -ra
}
function gam {
git add -- $( gst | grep "modified:" | rev | cut -f 1 -d " " | rev )
}
# -- bash completion
_git_branch_ioxtras()
{
local cur prev opts base
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
#
# The options found in the config/deploy/ directory.
#
case "${prev}" in
gml)
local branches=$( for x in $( git branch 2>/dev/null | sed 's/*//' ); do echo "${x}" ; done )
COMPREPLY=( $(compgen -W "${branches}" -- ${cur}) )
return 0
;;
gmo)
local branches=$( for x in $( git branch -r 2>/dev/null | sed 's/(*|->)//' ); do echo "${x}" ; done )
COMPREPLY=( $(compgen -W "${branches}" -- ${cur}) )
return 0
;;
gco)
local branches=$( for x in $( git branch 2>/dev/null | sed 's/*//' ); do echo "${x}" ; done )
COMPREPLY=( $(compgen -W "${branches}" -- ${cur}) )
return 0
;;
esac
}
complete -F _git_branch_ioxtras gml
complete -F _git_branch_ioxtras gmo
complete -F _git_branch_ioxtras gco