-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path.bash_git
More file actions
180 lines (157 loc) · 5.29 KB
/
Copy path.bash_git
File metadata and controls
180 lines (157 loc) · 5.29 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
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
169
170
171
172
173
174
175
176
177
178
179
180
# _ _ _ _
# | |__ __ _ ___| |__ __ _(_) |_
# | '_ \ / _` / __| '_ \ / _` | | __|
# | |_) | (_| \__ \ | | | | (_| | | |_
# |_.__/ \__,_|___/_| |_|____\__, |_|\__|
# |_____|___/
# +----------------------------------------------------------------------------+
# | Aliases |
# +----------------------------------------------------------------------------+
alias gs="git status"
alias gc="git checkout"
alias gc-="git checkout - && clear"
alias gcn="git checkout -b "
alias ga="git add -A && git commit"
alias gd="git diff"
alias gpr="git pull --rebase"
alias grh="git reset --hard"
alias gru="git remote update"
alias repofiles="git ls-files-root --cached --others --exclude-standard"
alias nukeshit="git branch --merged| egrep -v \"(^\*|master|develop)\" | xargs git branch -d"
alias gb="git branch"
alias gcm="git commit"
alias gsp="git stash pop"
alias gst="git stash"
alias grv="git remote -v"
alias gra="git rebase --abort"
alias grc="git rebase --continue"
alias ga.="git add ."
alias gad="git add"
alias gcml="git commit --amend --no-edit"
alias gcp="git cherry-pick"
alias gpf="git push -f"
alias grs="git reset --soft HEAD~1"
alias gbd="git branch -D"
alias gds="git diff --staged"
alias filehis="git log --full-history --"
# +----------------------------------------------------------------------------+
# | Functions |
# +----------------------------------------------------------------------------+
# Interactive Git rebase from root
function grir {
git rebase -i --root $(git rev-parse --abbrev-ref HEAD)
}
# Git push current branch
function gp {
branch_name="$(git symbolic-ref HEAD 2>/dev/null --short)"
git push -u origin "${branch_name}"
}
# Git add all & push
function gap {
ga && gp
}
# Git log shortcut
function gl {
if [ ${1} ]; then
git log -${1}
else
git log
fi
}
# Git interactive rebase shortcut
function gri {
if [ ${1} ]; then
git rebase -i HEAD~${1}
else
git rebase -i HEAD~10
fi
}
# Amend previous commit with all current changes - "Git AMend Last"
function gaml {
git add .
git commit --amend --no-edit
}
# gaml + gpf
function gamlf {
gaml
gpf
}
# Same as "gaml" but without "git add ."
function gcml {
git commit --amend --no-edit
}
# View changes introduced by a single commit - "Git CHanges"
function gch {
git diff ${1}~ ${1}
}
# Generate lists of commit messages with certain substring + their authors
function cmgrep {
git log --grep="${1}" --pretty="format:%an:%B" | sed '/^[[:space:]]*$/d' | grep ${1} > ${1}-commits
git log --grep="${1}" --pretty="format:%an" > ${1}-authors
cat ${1}-authors | grep -v "^\s*$" | sort | uniq -c | sort -bnr > ${1}-leaderboard
cat ${1}-commits | wc -l
}
# Refresh the default branch
function ref {
branch_name=$(git remote show origin | grep "HEAD branch" | cut -d ":" -f 2)
git checkout $branch_name && gpr && nukeshit
}
# View files affected by a single commit - "Git Files"
function gfi {
git diff-tree --no-commit-id --name-only -r ${1}
}
# +----------------------------------------------------------------------------+
# | Git branch in prompt |
# +----------------------------------------------------------------------------+
# Colors
red="\033[0;31m"
white="\033[0;37m"
green="\033[0;32m"
yellow="\033[0;33m"
purple="\033[0;35m"
cyan="\033[0;36m"
# Brackets needed around non-printable characters in PS1
ps1_red='\['"$red"'\]'
ps1_green='\['"$green"'\]'
ps1_white='\['"$white"'\]'
ps1_purple='\['"$purple"'\]'
ps1_cyan='\['"$cyan"'\]'
# Print the branch name and status to be displayed in the command line prompt
function parse_git_branch() {
gitstatus=`git status 2> /dev/null`
if [[ `echo $gitstatus | grep "Changes to be committed"` != "" ]]
then
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1***)/'
elif [[ `echo $gitstatus | grep "Changes not staged for commit"` != "" ]]
then
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1**)/'
elif [[ `echo $gitstatus | grep "Untracked"` != "" ]]
then
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1*)/'
elif [[ `echo $gitstatus | grep "nothing to commit"` != "" ]]
then
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
else
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1?)/'
fi
}
# Echo a non-printing color character depending on whether or not the current git branch is the master
# Does NOT print the branch name
# Use the parse_git_branch() function for that.
function parse_git_branch_color() {
br=$(parse_git_branch)
if [[ $br == "(main)" || $br == "(main*)" || $br == "(main**)" || $br == "(main***)" ]]; then
echo -e "${yellow}"
else
echo -e "${green}"
fi
}
case "$0" in
-bash|*/bash)
export PS1="$ps1_red\u:$ps1_white\W\[\$(parse_git_branch_color)\]\$(parse_git_branch) $ps1_red\$$ps1_white "
;;
-zsh|*/zsh)
;;
*)
;;
esac