-
Notifications
You must be signed in to change notification settings - Fork 1
/
.bashrc
342 lines (289 loc) · 10.9 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
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
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
##############################################################################
#
# ~/.bashrc
# ---------
# Executed by bash(1) for non-login shells.
#
# See /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples.
#
# @author Isis Agora Lovecruft, 0x2cdb8b35
# @date 10 July 2012
# @version 0.1.0
#_____________________________________________________________________________
#
# Changelog:
# ----------
# v0.2.0 Added ttytter though Tor alias and rearranged exports and aliases.
# v0.1.0 Properly added a changelog for vc.
##############################################################################
## If not running interactively, don't do anything
[ -z "$PS1" ] && return
##
## History
################
## Don't put duplicate lines in the history. See bash(1) for more options
## ... or force ignoredups and ignorespace
HISTCONTROL=ignoredups:ignorespace
## Append to the history file, don't overwrite it:
shopt -s histappend
## For setting history length see HISTSIZE and HISTFILESIZE in bash(1)
HISTSIZE=1000
HISTFILESIZE=2000
##
## Display
################
## Check the window size after each command and, if necessary,
## update the values of LINES and COLUMNS.
shopt -s checkwinsize
## Make less more friendly for non-text input files, see lesspipe(1)
[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"
## Set variable identifying the chroot you work in (used in the prompt below)
if [ -z "$debian_chroot" ] && [ -r /etc/debian_chroot ]; then
debian_chroot=$(cat /etc/debian_chroot)
fi
## If the command-not-found package is installed, use it
if [ -x /usr/lib/command-not-found -o -x /usr/share/command-not-found/command-not-found ]; then
function command_not_found_handle {
## Check because c-n-f could've been removed in the meantime
if [ -x /usr/lib/command-not-found ]; then
/usr/bin/python /usr/lib/command-not-found -- "$1"
return $?
elif [ -x /usr/share/command-not-found/command-not-found ]; then
/usr/bin/python /usr/share/command-not-found/command-not-found -- "$1"
return $?
else
printf "%s isn't a fucking command.\n" "$1" >&2
printf "If you're drunk then you should go for a bike ride, or at least stop coding.\n" "$1" >&2
return 127
fi
}
fi
## uncomment for a colored prompt
force_color_prompt=yes
if [ -n "$force_color_prompt" ]; then
if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
## We have color support; assume it's compliant with Ecma-48
## (ISO/IEC-6429). (Lack of such support is extremely rare, and such
## a case would tend to support setf rather than setaf.)
color_prompt=yes
else
color_prompt=no
fi
fi
if [ "$color_prompt" = yes ]; then
if [ "$USER" != "root" ]; then
PS1='${debian_chroot:+($debian_chroot)}\[\033[33m\]\u\[\033[32m\]@\[\033[36m\]\h\[\033[32m\]:\[\033[32m\]\w\[\033[33m\]\$ \[\033[0m'
else
## If root make the prompt red so that we notice we're in a root shell
PS1='${debian_chroot:+($debian_chroot)}\[\033[33m\]\u\[\033[32m\]@\[\033[36m\]\h\[\033[32m\]:\[\033[32m\]\w\[\033[31m\]\$ \[\033[0m'
fi
else
PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
fi
unset color_prompt force_color_prompt
## Let's make pretty things!
$HOME/scripts/bash_pretty_login.py
###############################################################################
## Environment & Paths
###############################################################################
## gpg-agent config
#######################
if [ -f "$HOME/.gpg-agent-info" ]; then
. "$HOME/.gpg-agent-info"
export GPG_AGENT_INFO
## We don't use the following
#export SSH_AUTH_SOCK
fi
GPG_TTY=$(tty)
export GPG_TTY
## Environment variables
########################
## Sourced to $HOME/.bashrc.env
. $HOME/.bashrc.env
##############################################################################
## Functions
##############################################################################
function goth
{
while test -z "$LIGHT" ; do
LIGHT=$(cat /proc/acpi/ibm/light | grep "status:" | cut -c 8-)
done
if [[ "$LIGHT" == " on" ]] || [[ "$LIGHT" == "on" ]] ; then
sudo echo "off" > /proc/acpi/ibm/light \
&& LIGHT="off"
elif [[ "$LIGHT" == " off" ]] || [[ "$LIGHT" == "off" ]] ; then
sudo echo "on" > /proc/acpi/ibm/light \
&& LIGHT="on"
else
LIGHT="off"
echo; echo "The day star hates you too."; echo;
fi
}
function extract () {
if [ -f $1 ] ; then
case $1 in
*.tar.bz2)tar xvjf $1 && cd $(basename "$1" .tar.bz2) ;;
*.tar.gz)tar xvzf $1 && cd $(basename "$1" .tar.gz) ;;
*.tar.xz)tar Jxvf $1 && cd $(basename "$1" .tar.xz) ;;
*.bz2)bunzip2 $1 && cd $(basename "$1" /bz2) ;;
*.rar)unrar x $1 && cd $(basename "$1" .rar) ;;
*.gz)gunzip $1 && cd $(basename "$1" .gz) ;;
*.tar)tar xvf $1 && cd $(basename "$1" .tar) ;;
*.tbz2)tar xvjf $1 && cd $(basename "$1" .tbz2) ;;
*.tgz)tar xvzf $1 && cd $(basename "$1" .tgz) ;;
*.zip)unzip $1 && cd $(basename "$1" .zip) ;;
*.Z)uncompress $1 && cd $(basename "$1" .Z) ;;
*.7z)7z x $1 && cd $(basename "$1" .7z) ;;
*)echo "don't know how to extract '$1'..." ;;
esac
else
echo "'$1' is not a valid file!"
fi
}
function only () {
if [ -z "`ps -Af | grep -o -w ".*$1" | grep -v grep | grep -v only`" ]; then
$@
fi
}
##############################################################################
## Aliases
##############################################################################
# Alias definitions.
# You may want to put all your additions into a separate file like
# ~/.bash_aliases, instead of adding them here directly.
# See /usr/share/doc/bash-doc/examples in the bash-doc package.
if [ -f ~/.bash_aliases ]; then
. ~/.bash_aliases
fi
## Enable color support of ls and also add handy aliases
if [ -x /usr/bin/dircolors ]; then
test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
alias ls='ls --color=auto'
alias dir='dir --color=auto'
alias vdir='vdir --color=auto'
alias grep='grep --color=auto'
alias fgrep='fgrep --color=auto'
alias egrep='egrep --color=auto'
fi
## More ls aliases
alias ll='ls -alF'
alias la='ls -A'
alias l='ls -CF'
## Add an "alert" alias for long running commands. Use like so:
## $ sleep 10; alert
alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')"'
#################################
## Extra user defined alaises:
#################################
##
## Editing
##############
alias e='emacs -nw'
alias ec='emacsclient -t'
alias es='emacs -nw --daemon'
alias N='emacs -nw $HOME/NOTES.gpg'
##
## Sudo & Apt
##############
alias s='sudo '
alias ag='apt-get'
alias acs='apt-cache search'
##
## Development
################
alias dev='cd /home/isis/dev'
alias back='cd $OLDPWD'
alias rms='rm ./*~'
alias rmp='rm ./\#*#'
alias rme='rm ./*~ && rm ./\#*#'
alias rmc='rm ./*.pyc'
alias tagsc='find . -name "*.[ch]" | xargs etags'
alias tagsp='find . -type f -name "*.py" | xargs etags'
alias removepound="sed -e 's/#.*//;/^$/d'"
alias removeslash="cpp -fpreprocessed"
alias boilerpy="boilerplate.sh $HOME/scripts/boilerplate-python $1 "
alias boilersh="boilerplate.sh $HOME/scripts/boilerplate-bash $1 "
alias gitdate='. gitdate.sh'
alias ipython='ipython --no-banner'
alias pathooni="if [[ \"$PYTHONPATH\" == \"\" ]] ; then export PYTHONPATH=$HOME/dev/torproject/ooni-probe && cd $PYTHONPATH && tmux source-file $HOME/.tmux/tmux.oonidev ; else unset PYTHONPATH; fi"
##
## Logs & Processes
###################
alias 30='dmesg | tail -n 30 | ccze -A'
alias 300='dmesg | tail -n 300 | ccze -A'
alias fuck='sudo killall '
alias damn='sudo kill -9 `pgrep $2` '
##
## Drives
###################
#alias chronophasia='sudo mount /dev/sdb1 /media/usb0 && truecrypt -t --mount=/media/usb0/Private -k "" --volume-type=normal --protect-hidden=no --protection-password="" /media/truecrypt1'
##
## Networking
#################
alias check='ping -c 3 google.com'
alias fwup="firewall.client.sh"
alias fwdown="sudo iptables -F; sudo iptables -X; sudo iptables -A INPUT -j ACCEPT; sudo iptables -A FORWARD -j ACCEPT; sudo iptables -A OUTPUT -j ACCEPT"
alias fwcheck="sudo iptables -L"
alias fwnew="cd /var/lib/fwsnort && sudo mv fwsnort.save fwsnort.old && sudo fwsnort -C \"ESTABLISHED,RELATED\" --ipt-sync && cd $PWD"
alias eip='ip_external.sh'
alias iip="sudo /sbin/ifconfig wlan0|grep inet|head -1|sed 's/\:/ /'|awk '{print $3}'"
## Moved to scripts/ so muttrc can call it:
#alias sprunge="curl --socks4a 127.0.0.1:59050 -A 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:11.0) Gecko/20100101 Firefox/11.0' -F 'sprunge=<-' http://sprunge.us"
##
## Display
###############
alias trans="transset -d $DISPLAY 0.8 "
##
## Tor Aliases
###############
alias tor='sudo -u debian-tor /usr/local/bin/tor -f /etc/tor/torrc'
alias arm='sudo -u debian-tor arm'
alias mutt="mutt-patched -F $HOME/.mailrc/muttrc"
alias muttor="coproc mailwithtor; mutt-patched -F $HOME/.mailrc/muttrc.tor"
alias offlineimap="offlineimap -c /home/isis/.mailrc/offlineimaprc"
alias torofflineimap="usewithtor offlineimap -c $HOME/.mailrc/offlineimaprc-tor"
alias mairix="mairix -f $HOME/.mailrc/mairixrc"
alias twitter="usewithtor ttytter | ccze -A"
##
## Fucking around
#################
alias hieroglyph="echo -e \"\033(0\""
alias pytebeat="aoss $HOME/dev/pytebeat/pytebeat.py"
alias hyde='$HOME/dev/web/hyde/hyde.py'
alias music='mocp -m $HOME/music -T $HOME/.moc/darkdot_theme -R ALSA'
##############################################################################
## enable programmable completion features (you don't need to enable
## this, if it's already enabled in /etc/bash.bashrc and /etc/profile
## sources /etc/bash.bashrc).
if [ -f /etc/bash_completion ] && ! shopt -oq posix; then
. /etc/bash_completion
fi
##############################################################################
## TMUX
##############################################################################
#if which tmux 2>&1 >/dev/null; then
# ## If no tmux session is started; start a new session:
# if test -z ${TMUX}; then
# ## Now .tmux.conf.setup is bound to C-h-R, so do:
# tmux
#
# ## Actually, iptables-persistent seems to work now...
# ## ...but if it doesn't, call this from .tmux.conf.setup, so
# ## that it is not backgrounded by tmux:
# #$HOME/scripts/firewall.client.sh
# fi
# ## When quitting tmux, try to attach:
# while test -z ${TMUX}; do
# tmux attach || break
# done
#fi
if test $(which tmux) == "/usr/bin/tmux" ; then
# If tmux owns zero processes
if [[ $(pgrep tmux | wc -l) -eq "0" ]] ; then
tmux
#else
## XXX need to attach to one, never both!
#tmux attach || break
fi
fi