-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy path.githelpers
174 lines (144 loc) Β· 4.87 KB
/
.githelpers
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
#!/bin/bash
# *********************************** Gary Bernhardt's pretty log ***********************************
show_git_head() {
pretty_git_log -1
git show -p --pretty="tformat:"
}
pretty_git_log() {
HASH="%C(yellow)%h%Creset"
RELATIVE_TIME="%Cgreen(%ar)%Creset"
AUTHOR="%C(bold blue)<%an>%Creset"
REFS="%C(red)%d%Creset"
SUBJECT="%s"
FORMAT="$HASH}$RELATIVE_TIME}$AUTHOR}$REFS $SUBJECT"
git log --graph --pretty="tformat:${FORMAT}" $* |
# Replace (2 years ago) with (2 years)
sed -Ee 's/(^[^<]*) ago\)/\1)/' |
# Replace (2 years, 5 months) with (2 years)
sed -Ee 's/(^[^<]*), [[:digit:]]+ .*months?\)/\1)/' |
# Line columns up based on } delimiter
column -s '}' -t |
# Page only if we need to
less -FXRS
}
# / *********************************** Gary Bernhardt's pretty log ***********************************
# *********************************** git cherry-drop ***********************************
cherry_drop() {
set -e
REF_TO_DROP=`git show $1 --pretty=format:%H -q`
HEAD=`git show HEAD --pretty=format:%H -q`
shift
# Stash changes if they exist
if ! git diff-index --quiet HEAD --; then
git stash && DIRTY=1
fi
if [[ $REF_TO_DROP == $HEAD ]]; then
# Easy way to undo a commit:
git reset --hard HEAD
else
# Rebase the commit out:
git rebase --keep-empty --onto $REF_TO_DROP~1 $REF_TO_DROP
fi
# Unstash changes if they were stashed:
[ -n "$DIRTY" ] && git stash pop
# Great success:
exit 0
}
# *********************************** / git cherry-drop ***********************************
# *********************************** git goodmorning ***********************************
goodmorning_echo_red() {
RED='\033[0;31m'
NC='\033[0m' # No Color
echo "${RED}--------- $1 ---------${NC}"
}
goodmorning_echo_yellow() {
YELLOW='\033[0;33m'
NC='\033[0m' # No Color
echo "${YELLOW}--------- $1 ---------${NC}"
}
goodmorning_echo_green() {
GREEN='\033[0;32m'
NC='\033[0m' # No Color
echo "${GREEN}--------- $1 ---------${NC}"
}
goodmorning_empty_lines() {
for i in `seq 1 $1`;
do
echo ""
done
}
semver() {
printf "%03d%03d%03d%03d" $(echo "$1" | tr '.' ' ')
}
goodmorning_check_bundler() {
GEMFILE_VER=$(cat Gemfile.lock | grep "BUNDLED WITH" -A1 | grep -v BUNDLED | awk '{print $1}')
BUNDLER_VER=$(bundler --version | grep "Bundler version " | sed 's/[^0-9.]*//g')
if [ $(semver $BUNDLER_VER) -lt $(semver $GEMFILE_VER) ]; then
goodmorning_echo_yellow "Updating bundler from $BUNDLER_VER to $GEMFILE_VER... "
gem install bundler -v $GEMFILE_VER
goodmorning_empty_lines 2
fi
}
goodmorning() {
set -e
clear
BASE_BRANCH=${1:-"master"}
CUR_BRANCH=$(git rev-parse --abbrev-ref HEAD)
if [[ "$CUR_BRANCH" == "$BASE_BRANCH" ]]; then
goodmorning_echo_green "Updating $BASE_BRANCH..."
else
goodmorning_echo_green "Switching to $BASE_BRANCH and updating..."
git checkout $BASE_BRANCH
fi
git pull --prune
goodmorning_empty_lines 3
if [ -f Gemfile ]; then
goodmorning_check_bundler
goodmorning_echo_green "Running bundle install..."
# Use reverse grep to filter out dozens of unchanged lines,
# such as "Using rake 10.5.0"
bundle install | grep -v Using | grep -v "Fetching source index" | grep -v "Fetching gem metadata" || goodmorning_echo_yellow "Failed to bundle install!"
goodmorning_empty_lines 3
fi
if [ -f package.json ]; then
goodmorning_echo_green "Running yarn install..."
# Safer:
# yarn install --pure-lockfile --check-files && yarn postinstall
# Faster:
yarn install --pure-lockfile || goodmorning_echo_yellow "Failed to yarn install!"
goodmorning_empty_lines 3
fi
# All done unless we're in a Rails project..
if [ ! -f bin/rails ]; then
goodmorning_echo_green "Finished!"
exit 0
fi
if [ -f bin/spring ]; then
RAKE_CMD="bin/spring rake"
elif [ -f bin/rake ]; then
RAKE_CMD="bin/rake"
else
RAKE_CMD="rake"
fi
goodmorning_echo_green "Running $RAKE_CMD db:migrate..."
$RAKE_CMD db:migrate db:test:prepare || goodmorning_echo_yellow "Failed to ready the database!"
# Avoid noise generated from running migration on master:
if [ -f db/structure.sql ]; then
git checkout db/structure.sql
fi
if [ -f db/schema.rb ]; then
git checkout db/schema.rb
fi
goodmorning_empty_lines 3
goodmorning_echo_green " ππππππ Finished! You're up to date πππππππ"
exit 0
}
# *********************************** / git goodmorning ***********************************
# *********************************** git fbr ***********************************
fbr() {
local branches branch
branches=$(git branch -vv)
branch=$(echo "$branches" | fzf +m)
git checkout $(echo "$branch" | sed "s/\*//" | awk '{print $1}' | sed "s/.* //")
}
# *********************************** / git fbr ***********************************