summaryrefslogtreecommitdiffstats
path: root/bashrc
blob: b11e20da732b2dd0e66924ae9b1d62826a38865d (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
# 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 Shadowcat Pastie Husk"
export PERL_CPANM_OPT="-q --mirror file://${HOME}/perl5/minicpan/ --mirror http://mirrors.kernel.org/cpan/ --mirror http://search.cpan.org/CPAN --prompt"
type -P git > /dev/null 2>&1 && 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 truecrypt="sudo truecrypt -t"
alias prove="prove -rj5"
alias cpan-outdated="cpan-outdated --mirror file://${HOME}/perl5/minicpan/"
alias netstat="netstat -a --inet --numeric-port"
# }}}
# 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\ \(x86\)\\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 dotperl="rsync -av lib/* ${HOME}/perl5/local/"
alias clean_packages='sudo pacman -Rsn $(pacman -Qqdt)'
alias pm="find lib -type f | sort"
alias bootstrap_cpanm="wget -O- -q http://xrl.us/cpanm | perl - App::cpanminus"
function web {
    local port=$1
    if [[ -z $port ]]; then
        plackup -MPlack::App::Directory -e'Plack::App::Directory->new'
    else
        plackup -MPlack::App::Directory -e'Plack::App::Directory->new' --port $port
    fi
}
function perldoc {
    if type -P cpandoc > /dev/null 2>&1; then
        cpandoc "$@"
    else
        command perldoc "$@"
    fi
}
function incoming {
    cpanm http://pause.cpan.org/incoming/$1.tar.gz
}
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 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 {{{
export PROMPT_COMMAND="__err=\$?;$PROMPT_COMMAND;PS1=\"\$(fancy-prompt "\$__err")\""
# }}}
# set the correct perl {{{
if type -a perlbrew > /dev/null 2>&1; then
    function _setup_perlbrew {
        local perl=$PERLBREW_PERL
        [ -z $perl ] && perl="$(readlink ${HOME}/perl5/perlbrew/perls/current)"
        local pwd="${PWD#${HOME}}/"
        if [[ "${pwd:0:6}" == "/work/" ]]; then
            if [[ "$perl" != "work-perl" ]]; then
                perlbrew use work-perl
            fi
        else
            if [[ "$perl" == "work-perl" ]]; then
                perlbrew use perl-5.10.1
            fi
        fi
    }
    export PROMPT_COMMAND="${PROMPT_COMMAND};_setup_perlbrew"
fi
# }}}
# }}}
# fortune {{{
fortune -n300 -s ~/.fortune | grep -v -E "^$"
# }}}