# -*- mode: sh; coding: euc-jp; -*- # # $Id: .bashrc,v 2.76 2007/08/02 07:16:50 hirose31 Exp hirose31 $ # # bash invocation script file. # initialize shell variables, aliases et cetera. # # /etc/profile # # ~/.bash_profile # ├ ~/.bash.d/${HOST}_profile # └ ~/.bashrc # ├ ~/.aliases_sh # └ ~/.bash.d/${HOST}_rc # ## basic if [ -z "$OSNAME" ]; then OSNAME=`uname -s`; export OSNAME OSRELEASE=`uname -r`; export OSRELEASE fi my_uname= my_uid=-1 my_gname= my_gid=-1 case $OSNAME in Linux) my_uid=$(id -u) my_uname=$(id -un) my_gid=$(id -g) my_gname=$(id -gn) ;; SunOS) # assume SunOS 5.x (Solaris) my_uid=$(/usr/xpg4/bin/id -u) my_uname=$(/usr/xpg4/bin/id -un) my_gid=$(/usr/xpg4/bin/id -g) my_gname=$(/usr/xpg4/bin/id -gn) ;; CYGWIN*) ;; FreeBSD) ;; esac ### ======================================================================== ### bash configuration ### ======================================================================== # setprompt user host user_color{_bold} host_color{_bold} termtitle # '\u' '\h' red_bold yellow setprompt() { _user="$1" _host="$2" _color_user="$3" _color_host="$4" _termtitle="$5" # \[〜\] は文字幅ゼロになるの。 # 色定義のエスケープ開始 _colesc="\[\e[" # エスケープ終端 _cse="\]" # 色を元に戻す _colreset="${_colesc}0m${_cse}" for i in user host; do _c='' _cin=$(eval echo \$_color_$i) case ${_cin} in black*) _c=30;; red*) _c=31;; green*) _c=32;; yellow*) _c=33;; blue*) _c=34;; magenta*) _c=35;; cyan*) _c=36;; gray*) _c=37;; *) _c='';; esac if [ -n "$_c" ]; then case ${_cin} in *_bold) _c="${_c};1";; esac fi eval "_color_$i=\"${_colesc}${_c}m${_cse}\"" done ### user part if [ -n "${_user}" ]; then if [ -n "${_color_user}" ]; then PS1="${_color_user}${_user}${_colreset}@" else PS1="${_user}@" fi else PS1= fi ### host part if [ -n "${_color_host}" ]; then PS1="${PS1}${_color_host}${_host}${_colreset}" else PS1="${PS1}${_host}" fi if [ -n "$INREC" ]; then PS1="${PS1}(REC)" fi ### job# part # \j は 2.04 以降が必要 bash_vers_major=`echo ${BASH_VERSION%%.*}` if [ $bash_vers_major -ge 2 ]; then if [ "${BASH_VERSION%.*}" \> "2.03" ]; then PS1="${PS1}${WINDOW:+:$WINDOW\j}" else PS1="${PS1}${WINDOW:+:$WINDOW}" fi fi ### cwd part PS1="${PS1}[\w]\\$ " # KTerm の title を弄っている。 # \033[ じゃなくて \033] なのに注意。 # 0: ウインドウタイトルとアイコンタイトル # 1: アイコンタイトル # 2: ウインドウタイトル # # o Bash-Prompt-HOWTO.txt # o Xterm-Title.txt # o rxvt の doc/xterm.seq # case $TERM in kterm|xterm|mlterm|cygwin|vt102) if [ -z "$_termtitle" ]; then _termtitle="${_host}:\w" fi PS1="\[\e]0;${_termtitle}\007\]${PS1}" ;; esac export PS1 } # check interactive shell or not # sh なら PS1 が設定されているか否かで、 # bash なら $- に i があるか否かで判断できる。 if [ `expr "$-" : '.*i'` != 0 ]; then ### interactive ulimit -c unlimited ### Prompt if [ -e ~/.myhostname ]; then _host=$(cat ~/.myhostname) else _host='\h' fi if [ $my_uid != '0' ]; then setprompt '' $_host '' '' else setprompt 'R' $_host 'red_bold' '' fi ### bash 1.x or 2.x bash_vers_major=`echo ${BASH_VERSION%%.*}` # bash2 なら ${BASH_VERSINFO[0]} で major version が得られる case ${bash_vers_major} in 2|3) ## bash-2.x # off: 複数行のコマンドを別々に history に保存 shopt -s cmdhist # OpenSSH のハングを防ぐため。 shopt -s huponexit shopt -s histappend if [ "${BASH_VERSION%.*}" \> "2.03" ]; then shopt -s extglob set +o nounset complete -A signal kill killall killall5 complete -A command man eman type xargs complete -A user su id groups complete -A alias alias a unalias [ -r ~/.bash_completion ] && . ~/.bash_completion fi if [ "${BASH_VERSION%.*}" \> "2.04" ]; then # Language complete -f -o default -X '!*.pl' perl perl5 complete -f -o default -X '!*.sh' sh bash complete -f -o default -X '!*.rb' ruby complete -f -o default -X '!*.(class|jar)' java # Compression complete -f -o default -X '*.+(zip|ZIP)' zip complete -f -o default -X '!*.+(zip|ZIP)' unzip complete -f -o default -X '*.+(z|Z)' compress complete -f -o default -X '!*.+(z|Z)' uncompress # 展開の時に補完が効かなくなるのでコメントアウト # complete -f -o default -X '!*.tar.@(gz|bz2)' tar complete -f -o default -X '*.+(gz|GZ)' gzip complete -f -o default -X '!*.+(gz|GZ)' gunzip complete -f -o default -X '*.+(bz2|BZ2)' bzip2 complete -f -o default -X '!*.+(bz2|BZ2)' bunzip2 # Postscript,pdf,dvi..... complete -f -o default -X '!*.ps' gs ghostview ps2pdf ps2ascii complete -f -o default -X '!*.dvi' dvips dvipdf xdvi dviselect dvitype complete -f -o default -X '!*.pdf' acroread pdf2ps complete -f -o default -X '!*.+(pdf|ps)' gv complete -f -o default -X '!*.texi*' makeinfo texi2dvi texi2html texi2pdf complete -f -o default -X '!*.tex' tex latex slitex complete -f -o default -X '!*.lyx' lyx complete -f -o default -X '!*.+(htm*|HTM*)' lynx html2ps # Multimedia complete -f -o default -X '!*.+(jp*g|gif|xpm|png|bmp)' xv gimp ee display complete -f -o default -X '!*.+(mp3|MP3)' mpg123 mpg321 complete -f -o default -X '!*.+(ogg|OGG)' ogg123 # apt-* complete -W 'update upgrade install remove clean' apt-get complete -W 'add gencaches showpkg showsrc stats dump dumpavail unmet search show depends whatdepends ' apt-cache complete -W 'update upgrade dist-upgrade download search install reinstall show remove clean purge' aptitude # portage complete -W '--clean --depclean --info --search --sync --unmerge' emerge complete -W 'belongs check depgraph files list size uses which' equery # fink complete -W 'install remove purge selfupdate update-all configure list apropos describe index validate scanpackages cleanup show-deps' fink # 後続のファイル名の補完が効かなくなるのでやめ。 # complete -W 'asn1parse ca ciphers crl crl2pkcs7 dgst dh dhparam dsa dsaparam enc engine errstr gendh gendsa genrsa nseq ocsp passwd pkcs12 pkcs7 pkcs8 prime rand req rsa rsautl s_client s_server s_time sess_id smime speed spkac verify version x509 ' openssl # jstart complete -W 'd-dev d-trouble d-unyou intra kan kiso tech zen blog tsng' jstart fi ;; 1) ## bash-1.x ;; *) ## unknown ;; esac ignoreeof=2 # n times C-d , and exit ### fix PWD. -- 『FreeBSD 徹底入門』 #alias oldcd='cd' # fixme #unalias cd \cd if [ X"$OLDPWD" = X"`pwd -P`" ]; then \cd; export PWD else \cd $OLDPWD fi #alias cd='oldcd' #unalias oldcd # XON/XOFF(Ctrl+S/Ctrl+Q)を無効にする stty -ixon erase  if [ -n "${SSH_AUTH_SOCK}" ]; then echo ${SSH_AUTH_SOCK} > ~/.my-ssh-agent echo ${DISPLAY} >> ~/.my-ssh-agent fi case $OSNAME in Linux) ### for GNU ls --color option if [ -r $HOME/.dir_colors ]; then alias ls='ls --color=tty' eval `dircolors -b ~/.dir_colors` fi if [ -e /etc/debian_version ]; then alias man='LC_MESSAGES=ja_JP.eucJP man' fi ;; SunOS) case $OSRELEASE in 5.*) # solaris alias ups='/usr/ucb/ps' ;; esac ;; esac else ### not interactive : fi # private group or not/ if [ "$my_gname" = "$my_uname" -a $my_uid -ge 100 ]; then umask 0002 fi ### /bash configuration ---------------------------------------------------- ### ======================================================================== ### read configuration files ### ======================================================================== if test "X$HOST" = "X"; then HOST=`echo $HOSTNAME | sed 's/\..*//'` if test "X$HOST" = "X"; then HOST=`hostname | sed 's/\..*//'` fi fi test -f ${HOME}/.aliases_sh && . ${HOME}/.aliases_sh test -f ${HOME}/.bash.d/${DOMAIN}_rc && . ${HOME}/.bash.d/${DOMAIN}_rc test -f ${HOME}/.bash.d/${HOST}_rc && . ${HOME}/.bash.d/${HOST}_rc bash=${BASH_VERSION%.*}; bmajor=${bash%.*}; bminor=${bash#*.} if [ "$PS1" ] && [ $bmajor -ge 2 ] && [ $bminor \> 04 ] \ && [ -r ${HOME}/.bash_completion ]; then export BASH_COMPLETION=~/.bash_completion export BASH_COMPLETION_DIR=~/.bash_completion.d . ${HOME}/.bash_completion fi ### /read configuration files ==============================================