-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbash_profile_gerard.bash
324 lines (258 loc) · 6.18 KB
/
bash_profile_gerard.bash
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
PATHS=(
/usr/local
/usr/local/bin
~/bin
~/Library/Android/sdk/platform-tools
~/Library/Android/sdk/tools
~/Library/Android/sdk/tools/bin
~/rubygems/bin
)
# add the paths one by one, if the exist
for P in "${PATHS[@]}"; do
if [ -d "$P" ]; then
PATH=$PATH:$P
fi
done
# otherwise it requires root to install gems
export GEM_HOME=~/rubygems
source ~/esoteric/git-prompt.sh
###
# Detect ZSH
###
if [[ "$SHELL" == "/bin/zsh" ]]; then
ISZSH=true
# git completion is build-in. Nice.
autoload -Uz compinit && compinit
else
ISZSH=false
fi
###
# Detect windows subsystem for linux
###
if grep -q Microsoft /proc/version 2>/dev/null; then
ISWSL=true
else
ISWSL=false
fi
export EDITOR=nano
export VISUAL=nano
export ANDROID_HOME=~/Library/Android/sdk/
# Add fancy colors to ls.
alias ls="ls -G"
# Show as list layout, with colors.
alias ll='ls -lG'
# Show as list layout, with colors, and hidden files.
alias la='ls -lGa'
# Extract a compressed tarball
alias untar='tar -zxvf'
if ! [ -x "$(command -v pico)" ]; then
alias pico='nano'
fi
# Find out where gitx is installed on my system.
gitx_path=$(find ~/Applications /Applications -iname "gitx.app" -type d -maxdepth 1 2>/dev/null)
if ! [ -x "$(command -v mate)" ]; then
CODE_PATH=/mnt/c/Users/Gerard/AppData/Local/Programs/Microsoft\ VS\ Code/Code.exe
if [ -f "$CODE_PATH" ]; then
mate() {
if [ "$#" -lt 1 ]; then
"$CODE_PATH"
else
"$CODE_PATH" $1
fi
}
fi
fi
###
# Open the given, or current, directory in gitx.
###
gitx() {
if [[ "$ISWSL" == true ]] ; then
# note - this opens in a new window each time.
APP="/mnt/c/Program Files (x86)/GitExtensions/GitExtensions.exe"
if [ "$#" -lt 1 ]; then
$(nohup "${APP}" browse </dev/null >/dev/null 2>&1 &)
else
$(cd $1; nohup "${APP}" browse </dev/null >/dev/null 2>&1 &)
fi
else
if [ "$#" -lt 1 ]; then
${gitx_path}/Contents/Resources/gitx
else
${gitx_path}/Contents/Resources/gitx --git-dir=$1
fi
fi
}
###
# Find the first xcode project in the current folder, or specified folder.
###
xcode() {
if [ "$#" -lt 1 ]; then
open $(find . -name "*.xcodeproj" -d -print -quit)
else
open $(find $1 -name "*.xcodeproj" -d -print -quit)
fi
}
qfind() {
if [ "$#" -lt 1 ]; then
echo "fatal: no file to search for specified"
return 1
fi
RES=$(find . -iname "$1" -not -path '*/\.*' | head -n 1)
if [ -z "$RES" ]; then
echo $(find . -iname "$1*" -not -path '*/\.*' | head -n 1)
else
echo $RES
fi
}
qopen() {
if [ "$#" -lt 1 ]; then
echo "fatal: no file to search for specified"
return 1
fi
# First argument represents the file or pattern searched for
FILE=$(qfind "$1")
if [ -z "$FILE" ]; then
echo "error: file not found"
return 1
fi
return $(open $FILE)
}
qmate() {
if [ "$#" -lt 1 ]; then
echo "fatal: no file to search for specified"
return 1
fi
# First argument represents the file or pattern searched for
FILE=$(qfind "$1")
if [ -z "$FILE" ]; then
echo "error: file not found"
return 1
fi
return $(mate $FILE)
}
qcd() {
if [ "$#" -lt 1 ]; then
echo "fatal: no folder to search and open specified"
return 1
fi
FOLDER=$(find . -name "$1" -type d -print -quit)
if [ -z "$FOLDER" ]; then
echo "error: folder not found"
return 1
fi
cd "$FOLDER"
}
###
# Search for a file, and blame it. Anything specified after the first argument
# is directly passed onto the git blame command.
###
qblame() {
if [ "$#" -lt 1 ]; then
echo "fatal: did not specify a file name or pattern"
return 1
fi
# Grab all but the first argument. This is later directly passed into
# the git blame command.
ARGS=${@:2}
FILEPATH=$(qfind "$1")
if [ -z "$FILEPATH" ]; then
echo "error: file not found in current checkout"
return 1
fi
# -c effectively removes file in which the line of code was introduced.
git blame -c "$FILEPATH" $ARGS
}
###
# Crude way of measuring write speed
###
disk_write_speed() {
if [ "$#" -lt 1 ]; then
echo "fatal: no file specified"
return 1
fi
if [ -f "$1" ]; then
echo "error: file exists"
fi
res=$(dd if=/dev/zero of=$1 bs=1g count=1 && rm $1)
}
###
# Generate a random UTF-8 icon based on the current time of day.
###
get_random_utf_icon() {
ICONS=("♤" "♙" "☚" "☋" "☍" "☧" "☏" "☇" "♇" "♫" "♆" "☈" "♅"
"♗" "♚" "♩" "♕" "☱" "♞" "♯" "☟" "☩" "♬" "♁" "♭" "☼"
"♧" "☜" "☉" "✐" "☌" "♘" "☛" "☒" "♔" "♛" "☽" "☨" "☭"
"☡" "☻" "♜" "☊" "★" "♢" "*" "♖" "♝" "♃" "✎" "☬" "♮"
"☫" "♡" "❥" "♪" "☤" "☾" "☥" "♄" "☞" )
# WSL - right now - has a much smaller range of supported
# UTF8 characters.
if [[ "$ISWSL" == true ]] ; then
ICONS=("■" "±" "║" "©" "£" "░" "¤" "≡")
fi
RANDOM=$$$(date +%s)
WINNER=${ICONS[$RANDOM % ${#ICONS[@]} ]}
echo ${WINNER}
}
###
# Return a red color when running as root, non-red otherwise.
###
get_icon_color() {
if [ "$EUID" -ne 0 ]; then
# Not root
echo "\[\033[0;37m\]"
else
# Running as root
echo "\[\033[1;31m\]"
fi
}
###
# Determine the hostname to show on prompt.
###
show_host() {
echo "\[\033[0;37m\]\u\[\033[0;90m\]@\[\033[0;90m\]\h "
}
show_dir() {
echo "\\W"
}
###
# Rebase if possible; otherwise merge.
###
rebase() {
git stash -u && git fetch
git rebase
if ! [ $? -eq 0 ]; then
echo "Rebase failed, merging instead"
git rebase --abort
git merge
if ! [ $? -eq 0 ]; then
echo "Fatal: Merge failed, aborting"
git merge --abort
return -1
else
echo "Merge successful"
fi
else
echo "Rebase successful"
fi
git stash pop
}
###
# git pull; also include submodules.
###
gpa() {
git pull --recurse-submodule
}
if [[ "$ISZSH" == true ]] ; then
#for i in {1..256}; do print -P "%F{$i}Color : $i"; done;
RED="%F{9}"
GREEN="%F{70}"
GRAY="%F{251}"
DARKGRAY="%F{239}"
WHITE="%F{256}"
YELLOWGREEN="%F{184}"
setopt PROMPT_SUBST
export PROMPT="${GRAY}%n${DARKGRAY}@%m${GREEN} %1~%f%b${YELLOWGREEN}\$(__git_ps1)${WHITE} $(get_random_utf_icon) "
else
export PS1="$(show_host)\[\033[32m\]$(show_dir)\[\033[33m\]\$(__git_ps1)$(get_icon_color) $(get_random_utf_icon) \[\033[00m\]"
fi
#RPROMPT='[%F{yellow}%?%f]'