-
Notifications
You must be signed in to change notification settings - Fork 21
/
.bashrc
206 lines (156 loc) · 5.13 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
# Environment script.
source $HOME/.bashenv
# Command-line programs that need to invoke our editor should run our
# quick "emacs-no-window" script, so that Emacs runs in text mode right
# at the terminal instead of taking the time to open a separate window.
export EDITOR=$HOME/bin/enw
# A quick way to launch Emacs, opening the current directory if no
# command line arguments are offered.
e () {
if [ -z "$*" ] ;then
set .
fi
(emacs "$@" &)
}
# Go ahead and keep commands with leading whitespace in the shell
# history (as the leading whitespace is, in my case, never significant
# and always the result of an overly generous cut-and-paste), but do
# erase duplicates.
HISTCONTROL=erasedups
# For security, bash should never save command history to disk under one
# of my main accounts. But saving history is okay inside a VM and,
# actually, kind of convenient, because of how often one logs out and
# back in and needs to run verbose and cumbersome boilerplate commands.
if [ "$LOGNAME" != "vagrant" ]
then unset HISTFILE
fi
# Keep plenty of history to avoid having to retype commands.
HISTSIZE=12000
# An excellent pager is of the utmost importance to the Unix experience.
export LESS="-i -j.49 -M -R -z-2"
export PAGER=less
# Put Emacs for Mac OS X in front of its terrible ancient Emacs.
if [ -d /Applications/Emacs.app/Contents/MacOS/bin ]
then
if [[ ":$PATH:" != *":/Applications/Emacs.app/Contents/MacOS/bin:"* ]]
then
PATH="/Applications/Emacs.app/Contents/MacOS:$PATH"
PATH="/Applications/Emacs.app/Contents/MacOS/bin:$PATH"
fi
fi
# Display my username and hostname in the xterm titlebar.
if [ "$TERM" = "xterm" ]
then
echo -ne "\033]0;$USER@$HOST\007"
fi
# The prompt should name the system on which the shell is running, in
# bold so the eye can easily find prompts when scrolling, and also turn
# red if it is a root prompt.
if [ -t 0 -a -z "$ZSH_VERSION" ]
then
PS1="${HOST:-${HOSTNAME}}"
# Keep only the first component of a fully-qualified hostname.
PS1="${PS1%%.*}"
if [ "$USER" = "root" ]
then
PS1="${PS1}#"
else
PS1="${PS1}\$"
fi
if [ -n "$TERM" -a "$TERM" != "dumb" ]
then
# Bold and colorful, with root in red and others in yellow.
PS1="$(tput bold; tput setab 7)\]$PS1\[$(tput sgr0)\]"
if [ "$USER" = "root" ]
then
PS1="\[$(tput setaf 1)$PS1"
else
PS1="\[$(tput setaf 3)$PS1"
fi
fi
PS1="${PS1} "
fi
# Bash should wait forever at its prompt and never time out.
unset TMOUT
# Various shell aliases, some quite traditional: "la" and "ll" go back
# to very early versions of Unix, where you could hard-link "ls" to
# either of those names and get the associated option automatically!
if [ -x /usr/bin/colordiff ] ;then DIFF=colordiff ;else DIFF=diff ;fi
alias a="ag -i"
alias la="/bin/ls -avCF"
alias lf="/bin/ls -vCF"
alias ll="/bin/ls -lv"
alias lla="/bin/ls -alv"
alias ltr="/bin/ls -ltrF"
alias ltra="/bin/ls -ltra"
alias m="less"
alias o="open"
alias vs="git diff-vs-master"
alias xargs="xargs -d '\n'" # I never put multiple filenames on one line
d () {
if [ -t 1 ]
then $DIFF -ur "$@" 2>&1 | less
else $DIFF -ur "$@"
fi
}
function g {
grep -P --color=always "$@" 2>/dev/null | less -FRX
}
gi () {
# Correct something like "gi tstatus" to "git status".
arg1="$1"
shift
gi${arg1:0:1} ${arg1:1} "$@"
}
,w () {
,watch python3 "$@" --
}
# A convenient way to turn core dumping on and off. Note the leading
# comma, which keeps these one-off commands completely orthogonal to
# actual commands installed on the system; the same convention is
# followed in my ~/bin directory.
alias ,coreon="ulimit -c unlimited"
alias ,coreoff="ulimit -c 0"
# Read AWS credentials for Boto from our ~/.s3cfg file.
,aws() {
export AWS_ACCESS_KEY_ID=$(awk '/^access_key / {print $3}' ~/.s3cfg)
export AWS_SECRET_ACCESS_KEY=$(awk '/^secret_key / {print $3}' ~/.s3cfg)
}
# Bash-specific settings.
if [ -n "$BASH" ]
then
# Update the LINES and COLUMNS environment variables each time the
# terminal window gets resized, for programs that care.
shopt -s checkwinsize
# The `**` pattern in a glob should match any number of directories.
shopt -s globstar
fi
# Faster C builds. Maybe I'll forget this is set globally, and it'll
# get me into trouble someday? We'll see!
if [ -x /usr/bin/ccache ]
then
export CC="ccache cc"
fi
# The tty should not intercept Control-S (stop) or Control-Q (start).
if [ -t 0 ]
then stty -ixon
fi
# Do not produce core dumps by default.
ulimit -c 0
# Prevent Ubuntu from doing a painstaking search of its package database
# every time I misspell a command.
if [ -n "$BASH" ]
then unset -f command_not_found_handle
fi
# Turn off history expansion; I use interactive search and quick Emacs
# edits instead, so I only ever invoke the history syntax accidentally!
unset histchars
# Load bash completion customization, if available.
if [ -n "$BASH" -a -f /etc/bash_completion ]
then
source /etc/bash_completion
fi
# Load any site-specific setup I have defined.
if [ -f "$HOME/.localrc" ]
then source "$HOME/.localrc"
fi