-
Notifications
You must be signed in to change notification settings - Fork 12
/
.bash_profile
executable file
·318 lines (260 loc) · 11.3 KB
/
.bash_profile
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
# TODO
# Cron jobs for
# brew update && brew upgrade
######################
# Terminal Aliases #
######################
# Aliases: if you use "quotes", the substitution is made here in the _profile
# but if you use 'aposts', the substitution is done at call-time
# You probably want 'single quotes' if you're using variables
# You may just want to use a function instead as I did with cs(){}
# I think Aliases are unavailable in scripts and Functions are
alias h='cd ~'
alias gohome='cd ~'
alias ls='ls -AFG'
alias rm='rm -i' # a safety precaution
alias grep='grep --color'
alias egrep='egrep --color'
alias ll='ls -lh' # longform, human-readable sizes (as opposed to machine-readable)
alias lg='ls | grep'
alias llg='ls -lh | grep'
alias hisg='history | grep' # (hg is taken by mercurial)
alias bug='brew update && brew upgrade'
alias vimrc='sb ~/.vimrc'
alias bprof='sb ~/.bash_profile'
alias this='export PATH="${PATH}:."'
alias sb='/Applications/Sublime\ Text\ 2.app/Contents/SharedSupport/bin/subl -n $@'
alias sba='/Applications/Sublime\ Text\ 2.app/Contents/SharedSupport/bin/subl -a $@'
alias ut='ssh -o ServerAliveInterval=10 [email protected]'
alias utx='ssh -o ServerAliveInterval=10 -X [email protected]'
alias trracker='cs ~/Dropbox/CSyStuff/TTRails/trracker'
alias play_activator='~/Applications/activator-1.0.10/activator ui'
alias blog='cs ~/code/personal_project_use/libraries_to_use/Ruby/octopress/'
CS=~/Dropbox/CSyStuff
PROGRAMMINGGIT="$CS"/ProgrammingGit
alias ca='cs $PROGRAMMINGGIT/StuffIWrote/Scala/CommentAnalyzer/CommentAnalyzer_0'
alias playakka='cs $PROGRAMMINGGIT/StuffIWrote/Scala/akka-redis-websockets-play-scala_translation'
alias notes='cs $CS/Notes'
alias empat='ssh [email protected]' # AOS class beastly Linux machine
# read non-version-controlled files
. ~/more_configs.sh
######################
# Terminal Options #
######################
# 4lolz
set -o vi
# turn on extra metacharacters: (?|*|+|@|!)(pattern)
shopt -s extglob
# R: Let `less` use colors,
# F: Just `cat` if it's only one screen worth of info
# X: "Disables sending the termcap initialization strings to the terminal." (?)
export LESS=-RFX
########################
# Terminal Functions #
########################
# print the length of the input (input needn't be quoted and can have spaces)
# but if the input has \" in it, this will not work; in that case use python
# or something
function len { echo -n "$@" | wc -c; }
# render manpage as postscript in Preview
function pman { man -t $1 | open -fa /Applications/Preview.app ; }
# run the "Really Barebones Minco" iCal interface I made
function minco { python $PROGRAMMINGGIT/StuffIWrote/Python/rbm/rbm.py $@ ; }
# ssh -X into specified CS Server
function uto { ssh -o ServerAliveInterval=30 -X ethanp@$1.cs.utexas.edu ; }
# send file to ut
function uts { scp "$1" [email protected]: ; }
# download movie to Movies dir
function dlmov { cd ~/Desktop/Movies/ && youtube-dl -t $1 && cd - ; }
# pretty-print a raw JSON input file
function json { cat $1 | python -mjson.tool | less; }
# change & show
function cs { cd "$1"; ls; }
# as in Does Directory Have... ( -i := Case Insensitive )
function ddh { ls "$1" | grep -i "$2"; }
# supposed to enable autocomplete for rbenv
if which rbenv > /dev/null; then
eval "$(rbenv init -)"
fi
# 5/27/14
# open mmd as pdf
function mtx {
TEX_NAME=$(basename "$1" | sed s'|.md|.tex|')
PDF_NAME=$(basename "$1" | sed s'|.md|.pdf|')
LATEX_DIR=~/Desktop/Latex
TEX_LOC=$LATEX_DIR/"$TEX_NAME"
multimarkdown -t latex "$1" > "$TEX_LOC"
pdflatex --output-directory "$LATEX_DIR" "$TEX_LOC" > /dev/null
open -a /Applications/Preview.app "$LATEX_DIR"/"$PDF_NAME"
}
# remove the first 49 lines of each *.[mh] file in this- & sub-directories
# assembled from the following:
# stackoverflow.com/questions/9954680/how-to-store-directory-files-listing-into-an-array/15416377#15416377
# stackoverflow.com/questions/316590/how-to-count-lines-of-code-including-sub-directories/316613#316613
# stackoverflow.com/questions/15691942/bash-print-array-elements-on-separate-lines
function decrust {
echo "The following files will have their first 48 lines removed:"
echo
files=($(find . -name "*.[mh]")) # create array of names matching *.[mh]
printf -- '%s\n' "${files[@]}" # kinda cool that printf exists in bash
if [ "$1" == "doit" ]; then
for item in ${files[*]}; do
tail +49 $item > ${item}.copy # put all but first 49 lines in buffer
mv ${item}.copy $item # overwrite original file with buffer
done # doesn't work without the buffer file
# learned my lesson from dedir(), put the do_nothing option in `else`
# because with bash you never know what sort of crap is going to get to
# your else statement
else
echo -e "\ndecrust is currently in dry mode, use \n\n\t$ decrust doit\n\nto actually run it\n"
fi
}
# delete directory
function dedir {
if [[ $# != 1 ]]; then
echo "You must supply a single directory to demolish"
elif [ -d "$1" ]; then
tree $1
echo "Enter 1 to remove $1 from the face of the Earth: "
read response
if (("$response" == "1")); then
rm -fR $1
echo "Action Completed"
else
echo "Action Cancelled"
fi
else
echo "$1 is not a directory."
fi
}
# Compile C programs with useful gcc flags
# ----------------------------------------
# TODO the "right" way to do this is to have a standard
# Makefile that you know your way around
#
# I've removed -O2 & -ffast-math optimization because I figure there are going
# to be more situations where I don't want something optimized out than where
# I really care about the speed of program execution. Though I think it could
# make a significant difference in execution speed.
function compile {
if [[ $# == 0 ]]; then
echo "This is a shortcut for compiling simple .c files with a whole lot of warnings enabled"
echo "Usage: compile <inName> (<outName>)?"
elif [[ $# > 2 ]]; then
echo "You'll have to implement a better compile function to get that to work"
echo "May I suggest using a for loop, or matching *.c & *.h"
elif [[ -f "$1" ]]; then
# I took out -Wstrict-prototypes -Wmissing-prototypes
if [[ $# == 1 ]]; then
gcc -W -Wall -fno-common -Wcast-align -std=c99 -Wredundant-decls\
-Wbad-function-cast -Wwrite-strings -Waggregate-return $1
echo "Your output is in a.out"
else
gcc -W -Wall -fno-common -std=c99 -Wcast-align -Wredundant-decls\
-Wbad-function-cast -Wwrite-strings -Waggregate-return $1 -o $2
fi
else
echo "Usage: compile <inName> (<outName>)?"
echo "In your case, <inName> wasn't a file."
fi
}
# run xl script (opt: -y, --yesterday)
function xlj {
THEPROJECT=~/Dropbox/CSyStuff/ProgrammingGit/StuffIWrote/Java/Minco_XL
THEJAR=out/artifacts/Minco_XL_jar/Minco_XL.jar
java -jar $THEPROJECT/$THEJAR "$*"
}
##########
# PATH #
##########
# PATH="/Library/Frameworks/Python.framework/Versions/2.7/bin:${PATH}"
# PATH="/Library/Frameworks/Python.framework/Versions/3.3/bin:${PATH}" # switch to new Python
PATH="/Users/Ethan/Applications/javacc-5.0/bin:${PATH}"
PATH="/Users/Ethan/Applications/apache-ant-1.8.4/bin:${PATH}"
PATH="$PATH":~/Dropbox/CSyStuff/Google_depot_tools_git/depot_tools # don't remember this
PATH="/Applications/Anaconda/anaconda/bin:$PATH" # allows for "conda" command
PATH="$PATH":/usr/local/share/scala-2.10.1/bin # I hope I'm not using this (TODO verify & remove)
PATH=${PATH}:$HOME/gsutil # this was for getting patent info
PATH="/usr/local/lib/ruby:${PATH}" # not sure here bc I have like 5 Rubys
PATH=$PATH:$HOME/.rvm/bin # allows for "rvm" command
PATH="/Applications/Postgres93.app/Contents/MacOS/bin:$PATH:$PATH" # for use with Postgres.app
# use homebrew's installations of bash and grep
# http://lapwinglabs.com/blog/hacker-guide-to-setting-up-your-mac
# I'm not clear that this is working though...
PATH=/usr/local/Cellar/coreutils/8.23/libexec/gnubin:$PATH
# TODO why doesn't this work when surrounded by either '' or "" ??
FUZZYCD=~/code/personal_project_use/code_to_base_off_of/Ruby/fuzzycd
PATH=$FUZZYCD:$PATH # add fuzzycd, may have to precede RVM in PATH
PATH="/usr/local/bin:${PATH}" # Homebrew comes first
export PATH
# install https://github.com/rupa/z cd utility
. /Users/Ethan/code/personal_project_use/libraries_to_use/ShellUtil/z/z.sh
############
# CDPATH #
############
# These are the places the "cd" command will LOOK, in this order too
CDPATH="::" # Current Directory
CDPATH="${CDPATH}:$HOME" # Global Var == /Users/Ethan
CDPATH="${CDPATH}:${HOME}/Dropbox" # add Dropbox to the list (TODO doesn't work)
export CDPATH
################
# PYTHONPATH #
################
# PYTHONPATH is where Python looks for user-defined Modules/Packages
# after searching the current directory
PYTHONPATH="/usr/local/lib/python2.7/site-packages:$PYTHONPATH"
# PYTHONPATH="/Applications/Anaconda/anaconda/lib/python2.7/site-packages:$PYTHONPATH"
export PYTHONPATH
###############
# CLASSPATH #
###############
# tells java where to look for classes referenced by your program
# I think you're not really supposed to have that in the .bashrc
###############
# JAVA_HOME #
###############
#JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home
#export JAVA_HOME
# I think this was useful for running `pig`
export JAVA_HOME="$(/usr/libexec/java_home)"
# These are only saved _this_ session
HISTSIZE=2000
# These are saved _between_ sessions in .bash_history
HISTFILESIZE=10000
# Load RVM into a shell session *as a function*
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"
# Brew tab-completion (works) [https://github.com/miku/brew-completion]
if [ -f ~/code/brew-completion/brew-completion.sh ]; then
. ~/code/brew-completion/brew-completion.sh
fi
# Must overwrite cd-command after loading rvm bc rvm redefines cd too
source $FUZZYCD/fuzzycd_bash_wrapper.sh
#####################
# The Cool Terminal #
#####################
# based on bbs.archlinux.org/viewtopic.php?pid=1068202
# I think the way this works is that when you "type" a color,
# the terminal starts writing in that color
# Define colornames:
NC='\033[0m' # No Color
yellow='\033[0;33m'
green='\033[0;32m'
bright_cyan='\033[0;96m'
white='\033[0;37m'
red='\033[0;31m'
PROMPT_ERROR="echo \"[\[${red}\]\342\234\227\[${white}\]]\342\224\200\")"
# the \NUMs are the composable pieces of the 'bar' in the prompt
PRE_PROMPT="\[${white}\]\342\224\214\342\224\200\$([[ \$? != 0 ]] && ${PROMPT_ERROR}"
PROMPT="\[${white}\]\342\224\200[\[${green}\]\${DIRSTACK}\[${white}\]]\$(promptFill)"
POST_PROMPT="\n\[${white}\]\342\224\224\342\224\200\342\224\200\342\225\274\[${NC}\]"
# PS1 := prompt-bar
PS1="${PRE_PROMPT}${PROMPT}${POST_PROMPT}"
function promptFill {
NOW=$(date +"[%l:%M %p ]")
if [[ $PREV_ERROR != 0 ]]; then # add a little 'x' to prompt if the last thing bombed out
local string="xx[x]--[${DIRSTACK}]"
fi
echo -ne "--" # -n: no newline at the end; -e: enable interpretation of escape sequences
echo -n $NOW
return $PREV_ERROR
}