summaryrefslogtreecommitdiffstats
path: root/bashrc
blob: d54e377092c67d06a85babade4ad447ed67b9d01 (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
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
343
344
345
346
347
348
349
350
# 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 PATH="${HOME}/.bin/marathon:${HOME}/.bin/nethack:${HOME}/.bin:/usr/local/sbin:/usr/local/bin:/usr/lib/ccache/bin:$PATH"
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=$(which 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 RSYNC_RSH="${HOME}/.bin/ssh"
export PERL5LIB="${HOME}/perl5/local/:${HOME}/perl5/local/lib/perl5/site_perl/5.10.0/i686-linux"
export CVS_RSH="${HOME}/.bin/ssh"
export TEXINPUTS=".:${HOME}/conf/tex:"
export LESS='-QR'
export NOPASTE_SERVICES="Codepeek PastebinCom Rafb Shadowcat Pastie Husk"
export PERL_CPANM_OPT="--mirror file://${HOME}/perl5/minicpan/ --mirror http://mirrors.kernel.org/cpan/ --mirror http://search.cpan.org/CPAN --prompt --skip-installed"
[ -x `which git` ] && export GIT_EXEC_PATH="${HOME}/.bin/git:"`git --exec-path`
[ -x /usr/bin/lesspipe ] && export LESSOPEN='|/usr/bin/lesspipe %s'
[ -x /usr/bin/lesspipe.sh ] && export LESSOPEN='|/usr/bin/lesspipe.sh %s'
[ -f $HOME/perl5/perlbrew/etc/bashrc ] && source $HOME/perl5/perlbrew/etc/bashrc
# }}}
# 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 {{{
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|screen*)
		PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME%%.*}:${PWD/$HOME/~}\007"'
		;;
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"
alias prove="prove -rj5"
alias cpan-outdated="cpan-outdated --mirror file://${HOME}/perl5/minicpan/"
# }}}
# games {{{
alias nao="(TERM=rxvt telnet nethack.alt.org)"
alias cao="(TERM=rxvt /usr/bin/ssh -C -i ${HOME}/.ssh/cao_key joshua@crawl.akrasiac.org)"
alias cdo="ssh -C -i ${HOME}/.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 bishamon='ssh bishamon'
alias apt="ssh ${USER}@apt.tozt.net"
alias jjaro="ssh ${USER}@jjaro.net"
alias tozt="ssh -t ${USER}@tozt.net tmux a"
alias henzell="ssh henzell@crawl.akrasiac.org"
# }}}
# tmux sessions {{{
alias main='tmux a -t main'
alias work='tmux a -t work'
alias docs='tmux a -t docs'
alias misc='tmux a -t misc'
# }}}
# 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/* ${HOME}/perl5/local/"
alias clean_packages='sudo pacman -Rsn $(pacman -Qqdt)'
function webcam {
    local width=$1
    local height=$2
    if [[ -z $width ]];  then width=640;  fi
    if [[ -z $height ]]; then height=480; fi
    mplayer tv:// -tv driver=v4l2:width=$width:height=$height:device=/dev/video0 -fps 15 -vf screenshot
}
function webcam_record {
    local width=$1
    if [[ -z $width ]];  then width=640;  else shift; fi
    local height=$1
    if [[ -z $height ]]; then height=480; else shift; fi
    mencoder tv:// -tv driver=v4l2:width=$width:height=$height:device=/dev/video0:forceaudio:adevice=/dev/dsp -ovc lavc -oac mp3lame -lameopts cbr:br=64:mode=3 -o $1
}
function luado { # thanks rici
    local e=$1
    shift
    lua /dev/fd/3 $* 4<&0- <<<$e 3<&0- 0<&4-
}
function moose {
    perl -Moose -E "$*"
}
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 github-clone {
    if [[ -z $2 ]]; then
        git clone git@github.com:$USER/$1.git
    else
        git clone git://github.com/$1/$2.git
    fi
}
function mod {
    yes | module-setup $1
}
function svup {
    svc -u "$HOME/.services/$1"
    svstat "$HOME/.services/$1"
}
function svdn {
    svc -d "$HOME/.services/$1"
    svstat "$HOME/.services/$1"
}
function svst {
    svstat "$HOME/.services/$1"
}
# }}}
# }}}
# 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
# }}}
# 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
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
    local vcs_dir
    local vcs_state
    local vcs_local_commits
    __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 $?)
            if [[ "$vcs_dirty" -eq 0 ]]; then
                vcs_dirty='*'
            else
                vcs_dirty=''
            fi
            vcs_branch=
        ;;
        darcs)
            vcs_dirty=$(darcs whatsnew > /dev/null 2>&1; echo $?)
            if [[ "$vcs_dirty" -eq 0 ]]; then
                vcs_dirty='*'
            else
                vcs_dirty=''
            fi
            vcs_branch=
        ;;
        git)
            local git_dir
            local git_base
            git_dir=$(git rev-parse --git-dir)
            vcs_branch=$(git symbolic-ref -q HEAD 2>/dev/null)
            vcs_dirty=''
            if git diff --no-ext-diff --ignore-submodules --quiet --exit-code; then
                :
            else
                vcs_dirty="${vcs_dirty}*"
            fi
            if git diff-index --cached --quiet --ignore-submodules HEAD; then
                :
            else
                vcs_dirty="${vcs_dirty}+"
            fi
            if [[ -z "${vcs_branch}" ]]; then
                vcs_branch=$(git rev-parse --short HEAD)
            else
                vcs_branch=${vcs_branch#refs/heads/}
                if git show-ref -q --verify "refs/remotes/origin/$vcs_branch"; then
                    git_base=$(git merge-base HEAD origin/$vcs_branch)
                    if [[ "${git_base}" == "$(git rev-parse HEAD)" ]]; then
                        vcs_local_commits="-$(git rev-list HEAD..origin/$vcs_branch | wc -l)"
                    elif [[ "${git_base}" == "$(git rev-parse origin/$vcs_branch)" ]]; then
                        vcs_local_commits="+$(git rev-list origin/${vcs_branch}..HEAD | wc -l)"
                    else
                        vcs_local_commits="+$(git rev-list ${git_base}..HEAD | wc -l)-$(git rev-list ${git_base}..origin/$vcs_branch | wc -l)"
                    fi
                fi
            fi
            if [[ -e "${git_dir}/MERGE_HEAD" ]]; then
                vcs_state='merge'
            fi
            if [[ -d "${git_dir}/rebase-apply" || -d "${git_dir}/rebase-merge" ]]; then
                vcs_state='rebase'
            fi
            if [[ -e "${git_dir}/BISECT_START" ]]; then
                vcs_state='bisect'
            fi
            if [[ "x$vcs_branch" == "xmaster" ]]; then
                vcs_branch=''
            fi
        ;;
        *) return 0 ;;
    esac
    if [[ -n "$vcs_branch" ]]; then
        vcs_branch=":$vcs_branch"
    fi
    if [[ -n "$vcs_state" ]]; then
        vcs_state="(${vcs_state:0:1})"
    fi
    if [[ "$vcs_local_commits" == "-0" ]]; then
        vcs_local_commits=''
    fi
    if [[ -n "$vcs_local_commits" ]]; then
        vcs_local_commits=":$vcs_local_commits"
    fi
    __vcs="(${vcs:0:1}${vcs_dirty}${vcs_branch}${vcs_local_commits}${vcs_state})"
}
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}\] "
# }}}
# set the correct perl {{{
if [ -x $(which perlbrew) ]; then
    function _setup_perlbrew {
        local perl="$(readlink ${HOME}/perl5/perlbrew/perls/current)"
        local pwd="${PWD#${HOME}}/"
        if [[ "${pwd:0:6}" == "/work/" ]]; then
            if [[ "$perl" != "work-perl" ]]; then
                perlbrew switch work-perl
            fi
        else
            if [[ "$perl" == "work-perl" ]]; then
                perlbrew switch perl-5.10.1
            fi
        fi
    }
    export PROMPT_COMMAND="${PROMPT_COMMAND};_setup_perlbrew"
fi
# }}}
# }}}
# fortune {{{
fortune -n300 -s ~/.fortune | grep -v -E "^$"
# }}}