summaryrefslogtreecommitdiffstats
path: root/bashrc
blob: b3bdf530d8bcdc7e69293b81c44af675c8816a00 (plain) (blame)
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
# notes {{{
# This file is sourced by all *interactive* bash shells on startup,
# including some apparently interactive shells such as scp and rcp
# that can't tolerate any output.  So make sure this doesn't display
# anything or bad things will happen !
# }}}
# environment {{{
export MPD_HOST=bishamon
export LUA_CPATH='/usr/local/lib/lua/5.1/?.so;/usr/local/lib/lua/5.1/?/init.so;./?.so'
export LUA_PATH='/usr/local/share/lua/5.1/?.lua;/usr/local/share/lua/5.1/?/init.lua;?.lua'
export MANPAGER="${HOME}/.bin/vimmanpager"
export EDITOR='/usr/bin/vim'
export SVN_SSH="${HOME}/.bin/ssh"
export DARCS_SSH="${HOME}/.bin/ssh"
export DARCS_SCP="${HOME}/.bin/scp"
export DARCS_SFTP="${HOME}/.bin/sftp"
export GIT_SSH="${HOME}/.bin/ssh"
export PERL5LIB="${HOME}/.perl:${HOME}/.perl/lib/perl5/site_perl/5.10.0/i686-linux"
export CVS_RSH='ssh'
export TEXINPUTS=".:${HOME}/conf/tex:"
export NHBOT_DARCS_AUTHOR="doy@tozt.net"
export NHBOT_PUBLIC_REPO_BASE="http://tozt.net/code/"
export LESS='-QR'
[ -x /usr/bin/lesspipe ] && export LESSOPEN='|/usr/bin/lesspipe %s'
[ -x /usr/bin/lesspipe.sh ] && export LESSOPEN='|/usr/bin/lesspipe.sh %s'
# }}}
# Test for an interactive shell. {{{
# There is no need to set anything past this point for scp and rcp, and it's
# important to refrain from outputting anything in those cases.
if [[ $- != *i* ]] ; then
	# Shell is non-interactive.  Be done now!
	return
fi
[ -z "$PS1" ] && return # }}}
# Enable colors for ls, etc.  Prefer ~/.dir_colors #64489 {{{
if [[ -f ~/.dir_colors ]]; then
	eval `dircolors -b ~/.dir_colors`
elif [[ -f /etc/DIR_COLORS ]]; then
	eval `dircolors -b /etc/DIR_COLORS`
else
	eval `dircolors -b`
fi # }}}
# Change the window title of X terminals {{{
case ${TERM} in
	xterm*|rxvt*|Eterm|aterm|kterm|gnome)
		PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME%%.*}:${PWD/$HOME/~}\007"'
		;;
	screen*)
		PROMPT_COMMAND='echo -ne "\033k${USER}@${HOSTNAME%%.*}:${PWD/$HOME/~}\033\\"'
		;;
esac # }}}
# aliases {{{
# adding options to common commands {{{
alias ls="ls --color=auto --group-directories-first"
alias grep="grep --color=auto"
alias rm="rm -i"
alias cp="cp -i"
alias mv="mv -i"
alias bc="bc -lq"
alias ncmpc="ncmpc -c"
alias truecrypt="sudo truecrypt -t"
# }}}
# games {{{
alias nao="(TERM=rxvt telnet nethack.alt.org)"
alias cao="(TERM=rxvt /usr/bin/ssh -C -i ~/.ssh/cao_key joshua@crawl.akrasiac.org)"
alias cdo="ssh -C -i ~/.ssh/cao_key crawl@crawl.develz.org"
alias scn="(TERM=xterm-color telnet slashem.crash-override.net)"
alias spork="telnet sporkhack.nineball.org"
alias cgoban="javaws http://files.gokgs.com/javaBin/cgoban.jnlp"
alias counterstrike="wine c:\\Program\ Files\\Sierra\\Half-Life\\hl.exe -game cstrike -console -numericping -nojoy -noipx"
alias halflife="wine c:\\Program\ Files\\Sierra\\Half-Life\\hl.exe" # -console breaks
alias starcraft="wine c:\\Program\ Files\\Starcraft\\StarCraft.exe"
# }}}
# termcast {{{
alias tc="telnet termcast.org"
# }}}
# shells {{{
alias apt='ssh doy@apt.tozt.net'
alias jjaro="ssh doy@jjaro.net"
alias tozt="ssh doy@tozt.net"
alias csil="(TERM=rxvt ssh jluehrs2@csil-core7.cs.uiuc.edu)"
alias ews="ssh jluehrs2@remlnx.ews.uiuc.edu"
alias henzell="ssh henzell@crawl.akrasiac.org"
# }}}
# other {{{
alias wgetff='wget --user-agent="Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.3) Gecko/20070404 Firefox/2.0.0.3"'
alias ..='cd ..'
alias dotperl='rsync -av lib/* ~/.perl/'
function luado { # thanks rici
    local e=$1
    shift
    lua /dev/fd/3 $* 4<&0- <<<$e 3<&0- 0<&4-
}
function setfont {
    printf '\e]710;%s\007' "$1"
}
function mem_usage {
    ps -eo size,ucmd | sort -rn | head -n$([ -z "$1" ] && echo 20 || echo $1)
}
function opened_files {
    strace $* 2>&1 | grep -E '^open\('   | \
                     grep -v ENOENT      | \
                     grep -v O_DIRECTORY | \
                     cut -f2 -d"\"" | \
                     grep -vE '^/proc/'  | \
                     grep -v '^/sys/'    | \
                     grep -v '^/dev/'
}
function alert {
    echo "DISPLAY=$DISPLAY xmessage -center -default okay $1" | at $2
}
function nopaste_moose {
    nopaste --chan=#moose --services=Shadowcat --desc="$1"
}
function gist {
    nopaste --services=Gist --desc="$1"
}
function fm22avi {
    fceux --playmov $1.fm2 --sound 1 --soundq 1 --soundrate 48000 --nospritelim 1 --pal 0 --xscale 1 --yscale 1 --opengl 0 --special 0 $2 --videolog "mencoder - -o $1.avi -ovc x264 -x264encopts qp=0 -oac mp3lame -lameopts mode=3:preset=128 -noskip -nocache -mc 0 -aspect 4/3 NESVSETTINGS"
}
function pdfcat {
    local out=$1
    shift
    gs -q -sPAPERSIZE=letter -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=$out $*
}
function vack {
    vim $(ack -la -- $*)
}
function github-clone {
    git clone git://github.com/$1/$2.git
}
function mod {
    yes | module-setup $1
}
# }}}
# }}}
# bash configuration {{{
source ~/.bash/colors
shopt -s extglob
shopt -s no_empty_cmd_completion
shopt -s checkwinsize
shopt -s histappend
if [[ ${BASH_VERSINFO[0]} -ge 4 ]]; then
    shopt -s globstar
fi
set -o vi
export HISTCONTROL=ignoredups
export HISTFILESIZE=1000000000
export HISTSIZE=1000000000
export PATH="~/.bin/marathon:~/.bin/nethack:~/.bin:/usr/local/sbin:/usr/local/bin:$PATH"
if [[ -z "$PROMPT_COMMAND" ]]; then
    export PROMPT_COMMAND='history -a'
else
    export PROMPT_COMMAND="${PROMPT_COMMAND};history -a"
fi
# prompt {{{
function _set_error {
    __error=$(printf %03d $?)
    if [[ "x${__error//0/}" != "x" ]]; then
        __error_color=$HIRED
    else
        __error_color=$NORM
    fi
}
function _set_vcs {
    local vcs
    local vcs_dirty
    local vcs_branch
    __vcs=''
    function _find_upwards {
        local pwd
        pwd=$(pwd)
        while [[ -n "$pwd" ]]; do
            if [[ -d "$pwd/$1" ]]; then
                return 0
            fi
            pwd=${pwd%/*}
        done
        return 1
    }
    function _find_svn {
        [[ -d '.svn' ]] || return 1
        vcs='svn'
    }
    function _find_darcs {
        if _find_upwards '_darcs'; then
            vcs='darcs'
            return 0
        fi
        return 1
    }
    function _find_git {
        if _find_upwards '.git'; then
            vcs='git'
            return 0
        fi
        return 1
    }

    _find_svn || _find_darcs || _find_git

    case "$vcs" in
        svn)
            vcs_dirty=$([[ -n "$(svn status | grep -v '^?')" ]]; echo $?)
            vcs_branch=
        ;;
        darcs)
            vcs_dirty=$(darcs whatsnew > /dev/null 2>&1; echo $?)
            vcs_branch=
        ;;
        git)
            vcs_dirty=$(git status -a > /dev/null 2>&1; echo $?)
            vcs_branch=$(git symbolic-ref -q HEAD 2>/dev/null || git show-ref --hash=7 HEAD)
            vcs_branch=${vcs_branch#refs/heads/}
            if [[ "x$vcs_branch" == "xmaster" ]]; then
                vcs_branch=''
            fi
        ;;
        *) return 0 ;;
    esac
    if [[ "$vcs_dirty" -eq 0 ]]; then
        vcs_dirty='*'
    else
        vcs_dirty=''
    fi
    if [[ -n "$vcs_branch" ]]; then
        vcs_branch=":$vcs_branch"
    fi
    __vcs="(${vcs:0:1}${vcs_dirty}${vcs_branch})"
}
export PROMPT_COMMAND="_set_error;_set_vcs;$PROMPT_COMMAND"
export PS1="\[\$__error_color\]\$__error \[${HIYELLOW}\][\t] \[${HIGREEN}\]\u@\h \[${HIBLUE}\]\W\[${CYAN}\]\$__vcs \[${HIBLUE}\]\\$\[${NORM}\] "
# }}}
# }}}
# external files {{{
[ -f /etc/bash_completion ] && source /etc/bash_completion
[ -f /etc/profile.d/bash-completion ] && source /etc/profile.d/bash-completion
source ~/.bash/cdhist.sh
source ~/.bash/j.sh
# }}}
# fortune {{{
fortune -n300 -s ~/.fortune | grep -v -E "^$"
# }}}