my bashrc
back
状況:
- いくつものホストに何回もログインする。
- いくつかのホストはホームディレクトリを nfs で共有している (がすべてではない)。
- ホストによってプロンプトの色を変えている (同じウインドウからあっちこっちにログインすると混乱するので)。
ちなみに emacs -nw のステータスバーの色もホストによって変わるようになっている。
- ssh-agent を使っている。
- GNU screen を使っている。
- 文字列処理をすることが異様に多い。
umask 022
ulimit -c 0
export PAGER=less
export LESS='-X -i -P ?f%f:(stdin). ?lb%lb?L/%L.. [?eEOF:?pb%pb\%..]'
export LESSOPEN="| $HOME/bin/lesspipe.sh %s"
export JLESSCHARSET=japanese-ujis
export RSYNC_RSH=ssh
export CVS_RSH=ssh
export CVSROOT=~/CVSROOT
export LYNX_CFG=~/rc/lynx.cfg
export PYTHONSTARTUP=~/rc/pythonrc
export PYTHONPATH=~/lib/python:.
export TEXINPUTS=.:$HOME/work/tex:
unset LANG
PATH=~/.OpenOffice.org1.0.1:~/bin/sawfish-tools:~/bin:/usr/local/bin:/usr/X11R6/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin:/usr/java/bin
shopt -u sourcepath
if [[ "$PS1" ]]; then
if [ $PWD = /export/home/yusuke ]; then cd ~; fi
unset MAIL
IGNOREEOF=10
HISTSIZE=50000
HISTFILESIZE=50000
shopt -s histappend
shopt -s histverify
shopt -s histreedit
shopt -s checkwinsize
shopt -u hostcomplete
shopt -s checkhash
shopt -s no_empty_cmd_completion
function i {
if [ "$1" ]; then history 1000 | grep "$@"; else history 30; fi
}
function I {
if [ "$1" ]; then history | grep "$@"; else history 30; fi
}
function dispstatus {
if [[ "$STY" ]]; then echo -en "\033k$1\033\134"; fi
}
h2=`expr $HOSTNAME : '\(..\).*'`
u2=`expr $USER : '\(..\).*'`
case "$HOSTNAME" in
apple*) col=31;;
mango*) col=36;;
grape*) col=32;;
giko*) col=33;;
*) col=1;;
esac
if [[ "$EMACS" ]]; then
stty -echo nl
PS1="$u2@$h2\w\$ "
else
if [[ "$SHELLTYPE" = session ]]; then
PS1='$h2$ ';
unset SHELLTYPE
else
PS1="$u2@$h2\[\e[${col}m\]\w[\!]\$\[\e[m\] "
fi
PS0="$u2@$h2:\[\e[${col}m\]\W[\!]\$\[\e[m\] "
eval `SHELL=sh tset -sQI`
stty dec crt erase ^H eof ^D quit ^\\ start ^- stop ^-
fi
. ~/rc/cdhist.sh
function showexit {
local s=$?
dispstatus "${PWD/\/home\/yusuke/~}"
if [[ $s -eq 0 ]]; then return; fi
echo "exit $s"
}
PROMPT_COMMAND=showexit
function px {
local tmp=$PS1; PS1=$PS0; PS0=$tmp;
}
function h { command -v $1; }
function wi {
case `type -t "$1"` in
alias|function) type "$1";;
file) L `command -v "$1"`;;
function) type "$1";;
esac
}
function j { jobs -l; }
function P { perl -e 'sub f{'"$*"';}print &f(@ARGV),"\n";'; }
function wng { wn $1 -grepn -grepa -grepv; }
function tmp { cd ~/tmp; }
function m { dispstatus Mutt; mutt "$@"; }
function s { m -f +$1; }
function ib { s inbox; }
function ob { s outbox; }
function ie { s ie; }
function ref { s ref; }
function nyu { s nyu; }
export SSH_AGENT_LOG=$HOME/.ssh/agent.log
if ssh-add -l >/dev/null 2>&1; then
:
elif [ 2 = "$?" ]; then
export SSH_AUTH_SOCK=$HOME/.ssh/sock.`hostname`
if ssh-add -l >/dev/null 2>&1; then
:
elif [ 2 = "$?" -a ! "$SSH_CLIENT" ]; then
rm -f $SSH_AUTH_SOCK
eval `ssh-agent -a $SSH_AUTH_SOCK`
echo -n `date` : 'ssh-agent started at' `hostname` : $SSH_AUTH_SOCK : $SSH_AGENT_PID >>$SSH_AGENT_LOG
fi
fi
function sshon1 {
if ! (ssh-add -l 2>&1 | grep '(RSA1)' >&2 ); then
ssh-add -t 60m ~/.ssh/identity &&
echo `date` : 'identity is added at' `hostname` >>$SSH_AGENT_LOG
fi
}
function sshon2 {
if ! (ssh-add -l 2>&1 | grep '(DSA)' >&2 ); then
ssh-add -t 60m ~/.ssh/id_dsa_orange &&
echo `date` : 'id_dsa_orange is added at' `hostname` >>$SSH_AGENT_LOG
fi
}
alias sshon=sshon2
function ssh1 { sshon1 && command ssh -1 "$@"; }
function ssh2 { sshon2 && command ssh -2 "$@"; }
function ap { dispstatus Apple; ssh2 apple "$@"; }
function ma { dispstatus Mango; ssh2 mango "$@"; }
function gr { dispstatus Grape; ssh2 grape "$@"; }
function slin { dispstatus Slinky; ssh2 slinky "$@"; }
function wg { tail ~/.wgetlog; }
function lynx { dispstatus Lynx; command lynx "$@"; }
function import { python -ic "import $1"; }
alias p=pyone
function start { svc -t /home/yusuke/.mp3play; svc -o /home/yusuke/.mp3play; }
function stop { svc -d /home/yusuke/.mp3play; }
function n { svc -i /home/yusuke/.mp3play; }
function ju { cat "$@" | juman -e -C localhost; }
function kn { cat "$@" | juman -e -C localhost | knp -tab; }
alias ls='ls -F'
alias ll='ls -o'
alias la='ls -lag'
alias g='env -u LC_CTYPE grep -i'
alias r='env -u LC_CTYPE grep -ir'
alias G='env -u LC_CTYPE grep'
alias F='env -u LC_CTYPE fgrep'
alias c=cat
alias rmi='rm -i'
alias mvi='mv -i'
alias cpi='cp -i'
alias lld='ls -ld'
alias ..='cd ..'
alias 644='chmod 644'
alias 755='chmod 755'
alias ox='od -Ax -tx1'
complete -d cd
complete -c man
complete -c h
complete -c wi
complete -v unset
complete -W "`echo ~/.mp3play/mp3/*`" mp
complete -W "`echo ~/Mail/*`" s
if [ -f ~/.bashrc_local ]; then
. ~/.bashrc_local
fi
if [ -f ~/.bashrc_remote ]; then
. ~/.bashrc_remote
fi
fi
Yusuke Shinyama