/
shrc
executable file
·174 lines (141 loc) · 3.92 KB
/
shrc
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
# 077 would be more secure, but 022 is more useful.
umask 022
# Save more history
export HISTSIZE=100000
export SAVEHIST=100000
# OS variables
[ $(uname -s) = "Darwin" ] && export OSX=1 && export UNIX=1
[ $(uname -s) = "Linux" ] && export LINUX=1 && export UNIX=1
uname -s | grep -q "_NT-" && export WINDOWS=1
# Fix systems missing $USER
[ -z "$USER" ] && export USER=$(whoami)
# Colourful manpages
export LESS_TERMCAP_mb=$'\E[01;31m'
export LESS_TERMCAP_md=$'\E[01;31m'
export LESS_TERMCAP_me=$'\E[0m'
export LESS_TERMCAP_se=$'\E[0m'
export LESS_TERMCAP_so=$'\E[01;44;33m'
export LESS_TERMCAP_ue=$'\E[0m'
export LESS_TERMCAP_us=$'\E[01;32m'
# Set to avoid `env` output from changing console colour
export LESS_TERMEND=$'\E[0m'
# Count CPUs for Make jobs
if [ $OSX ]
then
export CPUCOUNT=$(sysctl -n hw.ncpu)
elif [ $LINUX ]
then
export CPUCOUNT=$(getconf _NPROCESSORS_ONLN)
else
export CPUCOUNT="1"
fi
if [ "$CPUCOUNT" -gt 1 ]
then
export MAKEFLAGS="-j$CPUCOUNT"
fi
# Load GitHub token
[ -s ~/.github_password ] && export GITHUB_PASSWORD=$(cat ~/.github_password)
# Print field by number
field() {
awk {print\ \$$1}
}
# Setup paths
add_to_path_start() {
[ -d $1 ] || return
case "$1" in
*"$PATH"*) return ;;
esac
export PATH="$1:$PATH"
}
add_to_path() {
[ -d "$1" ] || return
case "$1" in
*"$PATH"*) return ;;
esac
export PATH="$PATH:$1"
}
add_to_path_start "/usr/local/bin"
add_to_path_start "/usr/local/sbin"
add_to_path "$HOME/Documents/Scripts"
add_to_path "$HOME/Scripts"
add_to_path "$HOME/Library/Python/2.7/bin"
add_to_path "$HOME/.gem/ruby/1.8/bin"
add_to_path "$HOME/.rbenv/bin"
add_to_path "$HOME/Applications/Sublime Text 2"
add_to_path "/c/Program Files/Sublime Text 2"
quiet_which() {
which $1 1>/dev/null 2>/dev/null
}
quiet_which ack-grep && alias ack=ack-grep
export DIFF=diff
quiet_which colordiff && export DIFF=colordiff && alias diff=colordiff
# Aliases
alias su="/bin/su -"
alias mkdir="mkdir -vp"
alias df="df -H"
alias rm="rm -iv"
alias mv="mv -iv"
alias cp="cp -irv"
alias du="du -sh"
alias make="nice make"
alias less="less --ignore-case --raw-control-chars"
alias rsync="rsync --partial --progress --human-readable --compress"
alias upbrew="scp-to-http.sh mikemcquaid,machomebrew frs.sourceforge.net /home/frs/project/m/ma/machomebrew/Bottles /Library/Caches/Homebrew/"
alias svn="svn-git.sh"
# Platform-specific stuff
if quiet_which brew
then
export BREW_PREFIX=$(brew --prefix)
export ANDROID_SDK_ROOT=$BREW_PREFIX/opt/android-sdk
export ANDROID_HOME=$ANDROID_SDK_ROOT
export RBENV_ROOT=$BREW_PREFIX/opt/rbenv
alias brew="nice brew"
alias bpi="brew pull --install"
fi
if [ $OSX ]
then
export GREP_OPTIONS="--color=auto"
export CLICOLOR=1
add_to_path /Applications/Xcode.app/Contents/Developer/usr/bin
add_to_path /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
alias ls="ls -F"
alias ql="qlmanage -p 1>/dev/null"
alias locate="mdfind -name"
alias vmware-shrink="sudo /Library/Application\ Support/VMware\ Tools/vmware-tools-cli disk shrinkonly"
elif [ $LINUX ]
then
quiet_which keychain && eval `keychain -q --eval --agents ssh id_rsa`
alias ls="ls -F --color=auto"
alias open="xdg-open"
alias agdu="sudo apt-get dist-upgrade"
elif [ $WINDOWS ]
then
quiet_which plink && alias ssh="plink -l mike"
alias ls="ls -F --color=auto"
open() {
cmd /C"$@"
}
fi
# Set up editor
quiet_which vi && export EDITOR="vi"
quiet_which vim && export EDITOR="vim"
if quiet_which subl || quiet_which sublime_text
then
quiet_which subl && export EDITOR="subl"
quiet_which sublime_text && export EDITOR="sublime_text" \
&& alias subl="sublime_text"
export GIT_EDITOR="$EDITOR -w"
export SVN_EDITOR="$GIT_EDITOR"
fi
# Run dircolors if it exists
quiet_which dircolors && eval $(dircolors -b)
# Run rbenv if it exists
quiet_which rbenv && eval "$(rbenv init -)"
# Aliases using variables
alias ed="$EDITOR"
# Save directory changes
cd() {
builtin cd "$@" || return
ls
pwd > ~/.lastpwd
}