-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmy_profile
288 lines (218 loc) · 6.9 KB
/
my_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
## Personal Bash Profile with useful settings and aliases
## Based on https://natelandau.com/my-mac-osx-bash_profile/
# TODO: not really sure why?
export GNUTERM=x11
# -------------------------------
# 1. ENVIRONMENT CONFIGURATION
# -------------------------------
# Set Paths
# ------------------------------------------------------------
# Provide a variable with the location of this script.
SCRIPT_PATH="$( dirname $BASH_SOURCE[0] )"
export PATH="$PATH:/usr/local/bin"
export PATH="$PATH:/Users/$USER/bin"
export PATH="$PATH:$SCRIPT_PATH/../scripts"
# Change Prompt
# ------------------------------------------------------------
# start underline and print current directory
PS1="$(tput sgr 0 1) \`pwd\`"
# add spaces based on width
PS1+="\`printf '%*s' \$(max 1 \$(( \$((\$(tput cols) - 5)) - \$( pwd | wc -m | grep -o '[0-9]\+') - \$(gitstatus | wc -m | grep -o '[0-9]\+') - $(whoami | wc -m | grep -o '[0-9]\+') - $(hostname | wc -m | grep -o '[0-9]\+')))) ''\`"
# add git status and stop underline
PS1+="\`gitstatus\`$(tput sgr0)| "
# print user and hostname
PS1+="\u @ \h\n| =>"
export PS1
export PS2="|>"
# Set Default Editor
# ------------------------------------------------------------
export EDITOR=/usr/bin/vim
if [ -f ~/.git-completion.bash ]; then
. ~/.git-completion.bash
fi
# -------------------------------
# 2. TERMINAL ALIASES AND FUNCTIONS
# -------------------------------
alias edit="vim"
alias cp="cp -iv"
function mv ()
{
dir="$2"
tmp="$2"; tmp="${tmp: -1}"
[ "$tmp" != "/" ] && dir="$(dirname "$2")"
[ -a "$dir" ] ||
mkdir -p "$dir" &&
/bin/mv -iv "$@"
}
alias ls="ls -FGlAhp"
alias less="less -FSRXc"
alias mkdir="mkdir -pv"
mcd() { mkdir $1; cd $1; }
cd() { builtin cd "$@"; ls; }
alias cd..='cd ../'
alias ..='cd ../'
alias ...='cd ../../'
alias .3='cd ../../../'
alias .4='cd ../../../../'
alias .5='cd ../../../../../'
alias .6='cd ../../../../../../'
alias ~="cd ~"
alias clr="clear"
alias cls="clear"
alias c="clear"
alias finder="open -a Finder ./"
trash () { command mv "$@" ~/.Trash ; }
# alias show_options="shopt"
# ql () { qlmanage -p "$*" >& /dev/null; }
# mans () {
# man $1 | grep -iC2 --color=always $2 | less
# }
# -------------------------------
# 3. FILE AND FOLDER MANAGEMENT
# -------------------------------
zipf () { zip -r "$1".zip "$1" ; }
alias numFiles='echo $(ls -1 | wc -l)'
cdf () {
currFolderPath=$( /usr/bin/osascript <<EOT
tell application "Finder"
try
set currFolder to (folder of the front window as alias)
on error
set currFolder to (path to desktop folder as alias)
end try
POSIX path of currFolder
end tell
EOT
)
echo "cd to \"$currFolderPath\""
cd "$currFolderPath"
}
extract () {
if [ -f $1 ] ; then
case $1 in
*.tar.bz2) tar xjf $1 ;;
*.tar.gz) tar xzf $1 ;;
*.bz2) bunzip2 $1 ;;
*.rar) unrar e $1 ;;
*.gz) gunzip $1 ;;
*.tar) tar xf $1 ;;
*.tbz2) tar xjf $1 ;;
*.tgz) tar xzf $1 ;;
*.zip) unzip $1 ;;
*.Z) uncompress $1 ;;
*.7z) 7z x $1 ;;
*) echo "'$1' cannot be extracted via extract()" ;;
esac
else
echo "'$1' is not a valid file"
fi
}
# ---------------------------
# 4. SEARCHING
# ---------------------------
alias qfind="find . -name "
spotlight () { mdfind "kMDItemDisplayName == '$@'wc"; }
# ---------------------------
# 5. PROCESS MANAGEMENT
# ---------------------------
findPid () { lsof -t -c "$@" ; }
alias memhogstop='top -l 1 -o rsize | head -20'
alias memhogsps='ps wwaxm -o pid,stat,vsize,rss,time,comm | head -10'
alias memhogs=memhogsps
alias cpuhogs='ps wwaxr -o pid,stat,%cpu,time,comm | head -10'
alias memtop='top -R -F -s 10 -o rsize'
alias cputop='top -R -F -s 10 -o cpu'
my_ps() { ps $@ -u $USER -o pid,%cpu,%mem,start,time,bsdtime,comm ; }
# ---------------------------
# 6. NETWORKING
# ---------------------------
alias myip='dig +short myip.opendns.com @resolver1.opendns.com'
myiip () {
local ip i
ip=""
i=0
while [[ -z $ip && $i < 10 ]]; do
ip=`ipconfig getifaddr en${i}`
if [[ ! -z $ip ]]; then
break
fi
i=$((i + 1))
done
echo $ip
}
netexp () {
echo "Pinging Network..."
ping `myiip | sed 's/\([0-9]*\.[0-9]*\.[0-9]*\.\)[0-9]*/\1255/'` -c5 -q > /dev/null
eval 'arp -a'
}
findPort () {
lsof -nP -iTCP:$1 | grep LISTEN ;
}
alias netcons="lsof -i"
alias openports="lsof -i | grep LISTEN"
alias suopenports="sudo lsof -i | grep LISTEN"
alias sudopenports=suopenports
alias lsock="sudo /usr/sbin/lsof -i -P"
alias lsockU="sudo /usr/sbin/lsof -nP | grep UDP"
alias lsockT="sudo /usr/sbin/lsof -nP | grep TCP"
alias users="w -h"
vnc () {
eval "open vnc://$1"
}
# ---------------------------------------
# 7. SYSTEMS OPERATIONS & INFORMATION
# ---------------------------------------
alias cleanupDS="find . -type f -name '*.DS_Store' -ls -delete"
alias finderShowHidden='defaults write com.apple.finder ShowAllFiles TRUE'
alias finderHideHidden='defaults write com.apple.finder ShowAllFiles FALSE'
alias editHosts='sudo vim /etc/hosts'
# ---------------------------------------
# 8. APPLICATIONS
# ---------------------------------------
alias chrome="/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --new-window"
google (){
eval "/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --new-window https://google.com/search?q='$@'"
}
alias inbox="/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --new-window https://inbox.google.com"
# ---------------------------------------
# 9. HELPER FUNCTIONS
# ---------------------------------------
## based on https://coderwall.com/p/pn8f0g/show-your-git-status-and-branch-in-color-at-the-command-prompt
function git_branch {
local git_status="$(git status 2> /dev/null)"
local on_branch="On branch ([^${IFS}]*)"
local on_commit="HEAD detached at ([^${IFS}]*)"
if [[ $git_status != "" ]]; then
local branch_msg="(";
else
local branch_msg=" "
fi
if [[ $git_status =~ "Untracked files:" || $git_status =~ "Changes not staged for commit:" ]]; then
branch_msg+="> "
elif [[ $git_status =~ "" ]]; then
branch_msg+=""
fi
if [[ $git_status =~ $on_branch ]]; then
local branch=${BASH_REMATCH[1]}
branch_msg+="$branch"
elif [[ $git_status =~ $on_commit ]]; then
local commit=${BASH_REMATCH[1]}
branch_msg+="$commit"
fi
if [[ $git_status =~ "Your branch is ahead of" ]]; then
branch_msg+=" +"
local num=`git status | grep -o '[0-9]\+'`
branch_msg+="$num"
elif [[ $git_status =~ "" ]]; then
branch_msg+=""
fi
if [[ $git_status =~ "Changes to be committed:" ]]; then
branch_msg+="*"
elif [[ $git_status =~ "" ]]; then
branch_msg+=""
fi
if [[ $git_status != "" ]]; then
branch_msg+=")"
fi
echo "$branch_msg"
}