-
Notifications
You must be signed in to change notification settings - Fork 0
/
.commonrc
174 lines (145 loc) · 5.89 KB
/
.commonrc
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
# Common Resources
#
# For items that should be run anew by each new shell, even subshells. Includes
# shell styling and things that won't be inherited by subshells. Also includes
# anything that is only intended for interactive shells, but not all shells.
# Only for items which are common across all shell types (bash, zsh, etc.).
#
# This should be sourced by .bashrc, .zshrc, etc.
# Set this to true in the top-level shell files (.common_profile, .commonrc) in
# order to get debug print statements at shell startup time.
SHELL_DEBUG=false
# But, always turn it off in non-interactive shells. Otherwise, printing things
# can break scp and prevent us copying files!! (Are you kidding me??)
[ ! -t 0 ] && SHELL_DEBUG=false
if $SHELL_DEBUG; then
echo "Running .commonrc"
fi
# Provides functions for adding items to PATH.
if [ -f $HOME/.add2path ]; then
source $HOME/.add2path
fi
# A convenient function for swapping files.
function swap() { mv $1 $1._tmp; mv $2 $1; mv $1._tmp $2; }
# MacPorts paths.
prepend2path '/opt/local/bin'
prepend2path '/opt/local/sbin'
# Man should be able to find the corresponding manpath automatically.
#export MANPATH=$MANPATH:/opt/local/share/man
# Homebrew path.
prepend2path '/usr/local/bin'
# Support for ccache compiler and icecream.
prepend2path '/usr/lib/ccache'
export CCACHE_PREFIX=icecc
# Path for Android Tools.
append2path $DEVDIR'/android-sdk/tools'
append2path $DEVDIR'/android-sdk/platform-tools'
append2path $DEVDIR'/android-ndk'
append2path $DEVDIR'/android-ndk/tools'
# Path for Erlang.
append2path '/opt/local/lib/erlang/bin'
# Path to Python tools such as pipenv (and perhaps some other locally installed tools?).
prepend2path "$HOME/.local/bin"
# Include user's private bin if it exists.
prepend2path "$HOME/bin"
# Remove path duplicates, keeping first occurrence.
if [ -n $MANPATH ]; then
export MANPATH=$(echo $MANPATH | awk -F: ' BEGIN { OFS=":"; COLON="no" } { for (i=1;i<=NF;i++) if (arr[$i] != 1) { arr[$i]=1; if (COLON == "yes") printf ":"; else COLON = "yes"; printf $i } } ')
fi
if [ -n $PATH ]; then
export PATH=$(echo $PATH | awk -F: ' BEGIN { OFS=":"; COLON="no" } { for (i=1;i<=NF;i++) if (arr[$i] != 1) { arr[$i]=1; if (COLON == "yes") printf ":"; else COLON = "yes"; printf $i } } ')
fi
# Configure the Homebrew Python Path. Only needed if using Python bindings to a
# brew-installed library from a NON-brew Python!
# In fact, I think even in the above case this is no longer advised. I read that
# there is a config file you can modify instead.
#export PYTHONPATH="/usr/local/lib/python2.7/site-packages:$PYTHONPATH"
# Set Maven Home variable so it can be seen by IntelliJ and others
export M2_HOME='/opt/local/share/java/maven3'
# Some programs, like git and hg, look for the EDITOR variable.
export EDITOR=vim
# Enabling colorized output for programs which support it
export CLICOLOR=true
# For gnuplot support in Octave.
export GNUTERM=x11
# Adds auto-complete and history keeping to Python interpreter.
export PYTHONSTARTUP=$HOME/.pystartup
# Options for less.
# -R allows me to pump colorized output from grep into less, and maintain the ANSI colour sequences.
# -i gives case-insensitive searches. (Can be toggled when in less, by typing -i.)
LESS=-Ri
# Various aliases
if [[ "$OSTYPE" == "darwin"* ]]; then
# OS X ls doesn't have the --color option (and doesn't need it).
alias ls='ls -h'
else
alias ls='ls --color=auto -h'
fi
alias l='ls -A'
alias ll='l -l'
alias grep='GREP_COLOR="1;33" LANG=C egrep --color=auto'
alias fgrep='GREP_COLOR="1;33" LANG=C fgrep --color=auto'
alias egrep='GREP_COLOR="1;33" LANG=C egrep --color=auto'
# We usually want a ps with much more output, but can't add these options
# permanently, because they conflict with other options.
alias psf='ps -eF'
alias apt='sudo apt-get'
alias app='apt-cache'
alias aps='apt-cache search --names-only'
alias apl='dpkg -l'
# Short command to attach my main session, or create if it doesn't exist.
alias tm='tmux attach || tmux new -s main'
# Useful alternative to `ps` which displays memory in MB.
myps() {
ps -eo user,pid,ppid,vsize,rss,pcpu,cputime,cmd --no-headers --sort=-rss \
| awk '{if ($1 ~ /^ntraft$/ && $2 ~ /^[0-9]+$/ && $5/1024 >= 1) {printf "User: %s, PID: %s, PPID: %s, Memory (Virtual): %.2f MB, Memory (Resident): %.2f MB, CPU Time: %s, Command: ", $1, $2, $3, $4/1024, $5/1024, $7; for (i=8; i<=NF; i++) printf "%s ", $i; printf "\n"}}'
}
# Find the first unused port in the range [8888, 9000). For Jupyter notebooks.
findport() {
netstat -aln | awk '
$6 == "LISTEN" {
if ($4 ~ "[.:][0-9]+$") {
split($4, a, /[:.]/);
port = a[length(a)];
p[port] = 1
}
}
END {
for (i = 8888; i < 9000 && p[i]; i++){};
if (i == 9000) {exit 1};
print i
}
'
}
# Pipe webserver from VACC to local.
function sshf() { ssh -Nfl $2\:localhost\:$2 $1; }
function vaccf() { sshf vacc $1; }
alias vaccjup='vaccf 8889'
function vaccpull() { scp -r vacc:$1 ~/Downloads/$2; }
# Make this a function instead of an alias so that oh-my-zsh is forced to
# do filename completions normally.
#alias gdiff='git diff --no-index'
gdiff() {
git diff --no-index "$@"
}
# Set up aliases to list paths vertically, element by element, rather than
# horizontally across the screen.
alias path='echo $PATH | tr -s ":" "\n"'
alias manpath='echo $MANPATH | tr -s ":" "\n"'
# If `keychain` app is present, use it to manage ssh keys.
if command -v keychain >/dev/null 2>&1; then
eval `keychain --eval --agents ssh id_rsa`
fi
# If pyenv is available, allow it to manage the python being invoked in this shell.
if command -v pyenv 1>/dev/null 2>&1; then
eval "$(pyenv init --path)"
eval "$(pyenv init -)"
fi
# Source some files that should only contain system-specific settings that
# should not be shared across machines.
if [ -f $HOME/.localrc ]; then
source $HOME/.localrc
fi
if [ -f $HOME/.local/commonrc ]; then
source $HOME/.local/commonrc
fi