-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbashrc
339 lines (281 loc) · 9.6 KB
/
bashrc
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
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
# .rawrusrc
### Source global definitions
export HAPMOJI=("¯\_(ツ)_/¯" "ʕᵔᴥᵔʔ" "ヽ(´ー`)ノ" "☜(⌒▽⌒)☞" "( ͡° ͜ʖ ͡°)" "(づ ̄ ³ ̄)づ" "◔_◔" "ԅ(≖‿≖ԅ)" "{•̃_•̃}" "(∩`-´)⊃━☆゚.*・。゚" "(っ▀¯▀)" "ヽ( •_)ᕗ")
export SADMOJI=("[¬º-°]¬" "(Ծ‸ Ծ)" "(҂◡_◡)" "ミ●﹏☉ミ" "(⊙_◎)" "(´・_・\`)" "(⊙.☉)7" "⊙﹏⊙" "ᕦ(ò_óˇ)ᕤ" "ε=ε=ε=┌(;*´Д\`)ノ" "ლ(`ー´ლ)" "ʕ •\`ᴥ•´ʔ" "ʕノ•ᴥ•ʔノ ︵ ┻━┻")
# Add local overrides ~/.localrc if it exists
[[ -e "$HOME/.localrc" ]] && source ${HOME}/.localrc
# Add local ~/sbin to PATH if it exists
[[ -s "$HOME/sbin" ]] && export PATH="$PATH:~/sbin"
# Set git editor to vim where available
[[ -s "$(which vim)" && -s "$(which git)" ]] && export GIT_EDITOR=$(which vim)
# Pull in system bashrc if it exists
[[ -s "/etc/bashrc" ]] && . /etc/bashrc
# python3 -m venv $HOME/space/global_python3_venv
[[ -z "${VIRTUAL_ENV}" ]] && \
[[ -d "$HOME/space/state/global_python3_venv" ]] && \
source $HOME/space/state/global_python3_venv/bin/activate
# ruby: non-system gem environment
[[ -s "$(which ruby)" && -s "$(which gem)" ]] && \
[[ -d "$HOME/space/state/ruby_env" ]] && \
export GEM_PATH="$HOME/space/state/ruby_env" && \
export GEM_HOME="$HOME/space/state/ruby_env" && \
export PATH="$PATH:$HOME/space/state/ruby_env"
### PS1 Extensions
# PS1 shrug and table flip
export PS1='$(get_host_identity) - $(cur_python_venv) \w $(git_info)\n |___ $(ps1_reacji) $ '
# Get git-branch and current HEAD
git_info() {
OLDRETVAL=$?
# Any string means this guy is a repo
test -d $PWD/.git && \
echo -en "${ORANGE}$(git_branch)${CLEAR}\n |$(cur_git_commit)\n"
exit ${OLDRETVAL}
}
# Grab current branch git branch if applicable
git_branch() {
OLDRETVAL=$?
BRANCH=$(git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/' || echo '')
if [ -d "${PWD}/.git" ]; then
echo "${BRANCH}"
fi
exit ${OLDRETVAL}
}
# Grab current git commit
cur_git_commit() {
OLDRETVAL=$?
CUR_COMMIT="$(git log --pretty=format:'%h' -n 1 2> /dev/null || echo '')"
test -z "${CUR_COMMIT}" && echo "" || echo -e "-[ Commit: ${ORANGE}${CUR_COMMIT}${CLEAR} ]"
exit ${OLDRETVAL}
}
get_host_identity() {
OLDRETVAL=$?
echo -e "${ORANGE}<[${DARK_YELLOW}$(hostname -s)${ORANGE}]>${CLEAR}"
exit ${OLDRETVAL}
}
# Exit code reactions
ps1_reacji() {
OLDRETVAL=$?
test ${OLDRETVAL} -eq 0 && \
echo -e "${BLUE}${HAPMOJI[$(((${RANDOM}%${#HAPMOJI[@]})))]}${CLEAR} (${OLDRETVAL})" || echo -e "${RED}${SADMOJI[$(((${RANDOM}%${#SADMOJI[@]})))]}${CLEAR} (${OLDRETVAL})"
exit ${OLDRETVAL}
}
ps1_reacji_bear() {
OLDRETVAL=$?
test ${OLDRETVAL} -eq 0 && \
echo -e "${BLUE}ʕ ㅇ ᴥ ㅇʔ${CLEAR} (${OLDRETVAL})" || echo -e "${RED}ʕノ•ᴥ•ʔノ ︵ ┻━┻${CLEAR} (${OLDRETVAL})"
}
cur_python_venv(){
OLDRETVAL=$?
if [ ! -z "${VIRTUAL_ENV}" ]; then
venv_name=$( echo ${VIRTUAL_ENV} | awk -F '/' '{ print $NF }' )
echo -en "(${ORANGE}${venv_name}${CLEAR})"
fi
exit ${OLDRETVAL}
}
# Proper umask
#umask 077
# [TMUX] If were in tmux set the window name to our host
if [ "$TERM" == "screen-256color" ] ||
[ "$TERM" == "screen" ] ||
[ "$TERM" == "tmux" ]; then
printf "\033k$(hostname -s)\033\\"
fi
# Fun Bindings
bind '"\ea\ed"':"\"echo 'Auto Destruct Sequence Has Been Activated!!!'\C-m\""
### Aliases
# Remap clear to force shell stdin to the bottom
alias clear='clear; tput cup $LINES 0'
alias ..='cd ..'
alias ll='ls -alF'
alias la='ls -A'
alias le='less'
alias l='ls -lisaG'
# Quick HTTP Server
alias pyserv='python -c "import SimpleHTTPServer, SocketServer, BaseHTTPServer; SimpleHTTPServer.test(SimpleHTTPServer.SimpleHTTPRequestHandler, type('"'"'Server'"'"', (BaseHTTPServer.HTTPServer, SocketServer.ThreadingMixIn, object), {}))" 9090'
# Quick CLI Pasting
alias dsnip="curl -F 'paste=<-' http://s.drk.sc"
alias sprunge="curl -F 'sprunge=<-' http://sprunge.us"
### Application aliases
# SSH / i2ssh aliases
if [ -s "$(which ssh)" ]; then
alias s=$(which ssh)
fi
if [ -s "$(which i2ssh)" ]; then
alias i=$(which i2ssh)
fi
# APT shorties
if [ -s "$(which apt-get)" ]; then
alias agu='sudo apt-get update; sudo apt-get upgrade -y'
alias agi='sudo apt-get install'
alias acs='sudo apt-cache search'
alias acp='sudo apt-cache policy'
fi
# Git aliases
if [ -s "$(which git)" ]; then
alias gpr='git pull --rebase'
alias gb='git branch'
alias gp='git push'
alias gct='git checkout'
alias gcm='git commit'
alias gd='git diff'
alias gds='git diff --staged'
alias gs='git status'
alias gsu='git status -uno'
alias gg='git grep'
alias glo='git log --oneline'
alias gc='git checkout master ; git pull --rebase upstream master ; git push origin master'
alias gscpp="git stash ; git checkout master ; git pull --rebase upstream master ; git push origin master"
alias gcpp="git checkout master ; git pull --rebase upstream master ; git push origin master"
alias gdsnip='git diff | dsnip'
fi
# Vagrant aliases
VAGRANT="$(which vagrant)"
if [ -s "${VAGRANT}" ]; then
# Vagrant status / Vagrant ssh
vs() {
if [ $# -gt 0 ]; then
${VAGRANT} ssh ${*}
else
${VAGRANT} status
fi
}
alias v="${VAGRANT}"
alias vu="${VAGRANT} up"
alias vup="${VAGRANT} up --provision"
alias vp="${VAGRANT} provision"
fi
# Test-kitchen aliases
## All "kci*" aliases assume that a valid API key
## is present in your env() as ${LINODE_API_KEY}.
TEST_KITCHEN="$(which kitchen)"
if [ -s "${TEST_KITCHEN}" ]; then
# Kitchen login/list
kl() {
if [ $# -gt 0 ]; then
${TEST_KITCHEN} login ${*}
else
${TEST_KITCHEN} list
fi
}
kcil() {
if [ $# -gt 0 ]; then
KITCHEN_YML='./.kitchen-ci.yml' ${TEST_KITCHEN} login ${*}
else
KITCHEN_YML='./.kitchen-ci.yml' ${TEST_KITCHEN} list
fi
}
alias kt="${TEST_KITCHEN} test"
alias kv="${TEST_KITCHEN} verify"
alias kc="${TEST_KITCHEN} converge"
alias kd="${TEST_KITCHEN} destroy"
alias ke="${TEST_KITCHEN} exec"
alias kci="KITCHEN_YML='./.kitchen-ci.yml' ${TEST_KITCHEN}"
alias kcit="KITCHEN_YML='./.kitchen-ci.yml' ${TEST_KITCHEN} test"
alias kciv="KITCHEN_YML='./.kitchen-ci.yml' ${TEST_KITCHEN} verify"
alias kcic="KITCHEN_YML='./.kitchen-ci.yml' ${TEST_KITCHEN} converge"
alias kcid="KITCHEN_YML='./.kitchen-ci.yml' ${TEST_KITCHEN} destroy"
alias kcie="KITCHEN_YML='./.kitchen-ci.yml' ${TEST_KITCHEN} exec"
fi
# VirtualBox aliasing
VBOXMAN="$(which VBoxManage)"
if [ -s "${VBOXMAX}" ]; then
echo "Enabling vboxmanage"
alias vbm="${VBOXMAN}"
alias vbmm="${VBOXMAN} modifyvm"
alias vbmc="${VBOXMAN} controlvm"
alias vbms="${VBOXMAN} startvm"
fi
### Arbitrary functions
# Alert for long running cmds. Usage: sleep 1; alert
if [ -s "$(which say)" ]; then
alias alert="say $*"
else
alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1| sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')"'
fi
alias ialert='i3-nagbar -m "[$?] Job Completed ($( echo -n $( history | tail -n2 | head -n1 | cut -d\ -f 4- ) )")'
snotify() {
# Slack notifications from cli via webhook
PAYLOAD="{ 'text' : '${*}' }"
if [ ! -z "${SLACK_NOTIFY_HOOK}" ]; then
curl -X POST -H 'Content-type: application/json' \
--data "${PAYLOAD}" ${SLACK_NOTIFY_HOOK}
else
echo "No webhook was defined in env['SLACK_NOTIFY_HOOK'], I usually put this in my ~/.localrc."
fi
}
# build single csv string from \n delimited file
csv() {
if [ $# -eq 1 ]; then
while read line; do
echo "'${line}'"
done < $1 | tr '\n' ','
fi
}
# Break elfs into opcodes
disas() {
GCC="$(which gcc)"
if [ -s "${GCC}" ]; then
${GCC} -pipe -S -o - -O -g $* | as -aldh -o /dev/null
else
echo "GCC is not installed"
fi
}
# Create Directory and Change Into It
cmkdir() {
mkdir -p $*
cd $*
}
# Create Executable File
te() {
touch $*
chmod 700 $*
}
# Quickly Generate Password of given length, defaults to 10 characters
genpass() {
test -z "$1" && LENGTH=10 || LENGTH=$1
python -c "from random import choice; import string; print ''.join( [ choice( string.printable.split( '\"')[0] ) for x in range( $LENGTH ) ] );"
}
# Track how long it takes to clone or update a repo
gittime() {
#
# Parameters: ( params prefixed with * are required arguments )
# * source - repository source ([email protected]:scub/deploy-playground.git)
# dest - destination to clone repository to
# verbose - report on more than just runtime
#
SOURCE=${1}
DEST=${2}
VERBOSE=${3}
# If no destination is provided infer what destination we will clone to
test -z "${DEST}" && DEST=$(echo ${SOURCE} | cut -d'/' -f2 | cut -d'.' -f1)
# Check to see if we should say things about what were going to do
if [ ! -z "${VERBOSE}" ]; then
echo -n 'Triggering '
test -d ${DEST} && echo -n "update " || echo -n "clone "
echo -n "from source: ${SOURCE} to ${DEST}"
test -z "${VERBOSE}" && echo "without verbosity" || echo "with increased verbosity."
fi
if [ ! -d "${DEST}" ]; then
RESULTS=$( { time git clone ${SOURCE} ${DEST}; } 2>&1 )
else
pushd "${DEST}" 2>/dev/null
RESULTS=$( { time git pull --rebase origin master; } 2>&1 )
popd 2>/dev/null
fi
# Parse run-time from results (real)
RUNTIME=$(echo $RESULTS | egrep -i 'real' | awk -F 'real ' '{ print $2 }' | cut -d' ' -f1 )
if [ ! -z "${VERBOSE}" ]; then
echo -e "Full results:\n============\n\n${RESULTS}"
echo -e "============\n\n"
fi
echo -n "Runtime: ${RUNTIME}"
}
### Text Color
RED="\033[31m"
DARK_YELLOW="\033[33m"
CYAN="\e[123m"
BLUE="\033[34m"
MAGENTA="\033[35m"
ORANGE="\033[91m"
CLEAR="\033[0m"
clear