2005年09月15日

.tcshrc

以前 .tcshrc を書いて bash ぽくしてから、便利になったというようなことを書いたと思います。
そろそろ .tcshrc が落ち着いてきたので、ここで公開しようと思います。
かなりマニアックに設定しているので、
クォーティングを区別して利用できる人じゃないと、
理解できないかもしれません(笑)
# B-shell 系と C-shell 系のクォートの挙動が違うことをしってないと厳しいです。。。

が、理解できたときは便利な .tcshrc の参考として利用できるのではないでしょうか?
実際の業務で激しく利用しながら、アップデートを重ねているものなので、
参考にしてみてください☆
「proxy1 か proxy2 を経由しないとどのサーバ/ネットワーク機器にも接続できない」
という環境と考えながら読んでみて下さいね。

ちなみに各 alias の ssh トンネルがどういう用途のためなのかを理解できた人は、
トンネルマスターと呼んであげます。
# さながらクイズのようですけど。。。

それからそれから、このコンフィグは .tcshrc として使っていますが、
.cshrc として読み込んでもつかえますよー♪
# print revision
set hostname=`hostname`
if ("$hostname" == "proxy1"  ||  "$hostname" == "proxy2") then
        sh -c 'echo ".tcshrc rev.38" 1>&2'
endif


# initial setting
setenv USERNAME k-square
setenv HOMEDIR /home/${USERNAME}


# http://www.linux.or.jp/JM/html/tcsh/man1/tcsh.1.html
# default path setting
setenv PATH  /usr/local/bin:/usr/ccs/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/usr/ucb:/bin:/sbin:/usr/X11R6/bin:/usr/X/bin:/usr/openwin/bin:/usr/dt/bin:~/bin:${PATH}
if ( -d /home/k-square/GNU/bin ) then
        setenv PATH /home/k-square/GNU/bin:${PATH}
endif


# basical environmental setting
setenv MANPATH /usr/share/man
setenv PAGER less
setenv EDITOR vi
setenv EXINIT 'set exrc number noautoindent showmode showmatch tabstop=8 backspace=2'
setenv BLOCKSIZE k
umask 022


# additional setting
setenv NPX_PLUGIN_PATH /usr/j2se/j2re1_3_0/plugin/sparc


# cvs setting
if ( -d /opt/repository ) then
        setenv CVSROOT /opt/repository
else
        setenv CVSROOT /var/repository
endif
setenv CVS_ROOT CVS_ROOT


# japanese setting
# http://optik2.mtk.nao.ac.jp/~kawanomo/linux/slackware-9.1/tcsh.html
unsetenv LC_ALL
#setenv LANG ja_JP.eucJP
setenv LANG C
setenv OUTPUT_CHARSET EUC_JP
setenv JLESSCHARSET japanese-euc
set dspmbyte=euc
set dspkanji=euc
unset nokanji


# console setting (color)
# http://www2u.biglobe.ne.jp/~hsaka/tool.html#tcsh_prompt
# printf "\033]2;ssh-tonnel\007"
setenv TERM vt100
if ( "`tty`" == "/dev/console" ) then
        resize
endif
unset autologout
unset noclobber
set nobeep
set symlinks=ignore
set autolist
set filec
set notify
set color
set colorcat
if ( ${?tcsh} ) then
        if ( ${?color} ) then
                if ( "${USER}" == "root" ) then
                        #red background
                        #set prompt='%{\e[1;37;41m\e]2;[%n@%m] %~\a\n\e[0;34;41m[%n@%m] %~\e[1;37;41m\n%}$ '
                        #black background
                        set prompt='%{\e[1;37;40m\e]2;[%n@%m] %~\a\n\e[1;31;40m[%n@%m] %~\e[1;37;40m\n%}$ '
                else
                        set prompt='%{\e[0;37;40m\e]2;[%n@%m] %~\a\n\e[0;33;40m[%n@%m] %~\e[0;37;40m\n%}$ '
                endif
        else
                set prompt='%{\e]2;[%n@%m] %~\a\n[%n@%m] %~\n%}$ '
        endif
else
        # for csh
        set prompt="\
[${USER}@${HOST}] `pwd`\
$ "
endif
set prompt2='> '


# history setting
if ( ${?tcsh} ) then
        set histfile=${HOMEDIR}/.tcsh_history_$user
        set history=(9999 '%Y/%W/%D %T %h %R\n')
        set savehist=(9999 merge)
else
        set histfile=${HOMEDIR}/.csh_history_$user
        set history=9999
        set savehist=9999
endif
touch $histfile
chmod 600 $histfile


# complete setting (only tcsh)
# http://www2u.biglobe.ne.jp/~hsaka/tool.html#tcsh_complete
if ( ${?tcsh} ) then
        set complete=enhance
        set noglob
        complete {cc,gcc,g++}           'c/-[IL]/d/'    \
                                        'n/-c/f:*.c/'   \
                                        'n/*/f:*.[fco]/'

        complete {f77,g77}              'c/-[IL]/d/'    \
                                        'n/-c/f:*.f/'   \
                                        'p/*/f:*.[fco]/'

        complete gzip                   'n/-d/f:*.{gz,Z,tgz,TGZ}/'      \
                                        'n/*/f:^*.{gz,Z,tgz,TGZ}/'
        complete {gunzip,gzcat,zcat}    'n/*/f:*.{gz,Z,tgz,TGZ}/'
        complete com{,press}            'n/*/f:^*.Z/'
        complete unc{,ompress}          'n/*/f:*.Z/'
        complete tar                    'n/{,-}[crtux]*z*f/f:*.{tar.gz,tar.Z,tgz,TGZ}/' \
                                        'n/{,-}[crtux]*f/f:*.tar/'      \
                                        'n/*/f/'

        complete {vi,xvi,m,more}        'n/*/f:^*.{o,a,so,so.*}/'
        complete {jlatex,'tex2*'}       'n/*/f:*.tex/'
        complete {ghostview,'gv*'}      'c/-l/(andscape)/'      \
                                        'n/*/f:*.{ps,eps,pdf}/'
        complete lpr                    'n/*/f:*.{ps,eps}/'
        complete 'ps?*'                 'n/*/f:*.{ps,eps}/'
        complete 'tgif*'                'n/*/f:*.obj/'
        complete {netscape,Mo,Mosaic,lynx,Lynx} \
                                        'n/*/f:*.{htm,html}/'

        complete ps                     'n/-*u/u/'

        complete {,j}{man,whatis}       'n/-M/d/'       \
                                        'n/*/c/'

        complete {which,where}          'p/1/c/'

        complete alias                  'p/1/a/'
        complete unalias                'n/*/a/'
        complete set                    'p/1/s/'
        complete unset                  'n/*/s/'
        complete {set,print}env         'p/1/e/'
        complete unsetenv               'n/*/e/'

        complete {cd,gt,gb,chdir,pushd} 'p/1/d/'        \
                                        'n/-*/d/'
        unset noglob
endif


# alias setting
alias ls 'ls -F'
alias ll 'ls -laF'
if ( "`uname`" == "SunOS" ) then
        if ( -x /home/k-square/GNU/bin/ls ) then
                if ( ${?tcsh} ) then
                        alias ls 'ls-F'
                        alias ll 'ls -laF'
                else
                        if (${?color}) then
                                alias ls 'ls -F --color=auto'
                                alias ll 'ls -laF --color=auto'
                        endif
                endif
        endif
else if ( "`uname`" == "Linux" ) then
        alias ls 'ls -F --color=auto'
        alias ll 'ls -laF --color=auto'
endif
alias h 'history 20'
alias rm '/bin/rm -i'
alias rmf '/bin/rm -rf'


if ("$hostname" == "proxy1"  ||  "$hostname" == "proxy2") then
        # when you connect to proxy use command as below.
        # ssh  -L 65432:127.0.0.1:65432 ${USERNAME}@192.168.1.1;
        # ssh  -L 65432:127.0.0.1:65432 ${USERNAME}@192.168.1.2;

        # personalized alias
        alias cleanup   '/bin/rm -f  `find  '"${HOMEDIR}/trackinglog"' -daystart -name '"${USERNAME}.*"' -type f -mtime +1`'
        alias gnu-dist  "cd ${HOMEDIR}; tar cvf - GNU | ssh \!^ 'chmod 750 ${HOMEDIR}; tar xvf -;'"
        # ssh develop1 'tar cvf - GNU' | tar xvf -
        alias c-mynote  'ssh -L 65432:127.0.0.1:3389 admin@192.168.1.11'
        # sed -e 's/^setenv USERNAME k-square$/setenv USERNAME user01/'  /home/k-square/.tcshrc > /home/user01/.tcshrc

        # network devices
        alias c-l3sw    'ssh -1 ${USERNAME}@192.168.64.1'
        alias c-fw      'ssh -1  netadmin@192.168.64.2'
        alias c-l2sw    'telnet 192.168.64.3'

        # old solaris servers
        alias c-www   'ssh user@192.168.128.1'

        # standard solaris servers
        alias c-host1 'scp -q ~/.tcshrc ${USERNAME}@192.168.128.2:~/ >&/dev/null;    ssh ${USERNAME}@192.168.128.2;'
        
        # windows servers
        alias c-host2 'ssh -L 65432:127.0.0.1:3389 -R 8080:192.168.1.11:8080  admin@192.168.128.3;'

        # linux servers
        alias c-host3 'scp -q ~/.tcshrc ${USERNAME}@192.168.128.4:~/ >&/dev/null; ssh  -R 8080:192.168.1.11:8080  ${USERNAME}@192.168.128.4;'
endif


if ("$hostname" == "develop1"  ||  "$hostname" == "develop2") then
        # development server
        setenv PATH /var/tmp/k-square/development/sparc-sun-solaris2.8/bin:/var/tmp/k-square/development/bin:/usr/local/bin:/usr/ccs/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/usr/ucb:/bin:/sbin:/usr/X11R6/bin:/usr/X/bin:/usr/openwin/bin:/usr/dt/bin:~/bin:${PATH}
        setenv LD_LIBRARY_PATH /var/tmp/k-square/development/sparc-sun-solaris2.8/lib:/var/tmp/k-square/development/lib
        setenv CC 'gcc'
        setenv CFLAGS  '-O2'
        alias ls 'ls -F'
        alias ll 'ls -laF'
endif



if ("$hostname" == "spool1"  ||  "$hostname" == "spool2") then
        # spool server
        setenv PATH ${PATH}:/opt/iplanet/ims/bin/msg/admin/bin:/opt/VRTS/bin
        alias hashdir 'cd  /opt/iplanet/ims/bin/msg/admin/bin; ./hashdir'
        set imtalog="/opt/iplanet/ims/msg-spool/log/imta"
        set poplog="/opt/iplanet/ims/msg-spool/log/pop"
        set maillog="/opt/iplanet/spool/log/spool"
        set maildir="/opt/iplanet/spool/msg-spool/store/partition/primary"
endif


if ("$hostname" == "smtp1"  ||  "$hostname" == "smtp2") then
        # smtp relay server
        set queue="/opt/iplanet/ims/msg-`hostname`/imta/queue/tcp_local"
        set maillog="/var/log/ims/`hostname`"
        set ldaplog="/opt/iplanet/ids/slapd-`hostname`/logs"
endif


##### Memo: Convenient Key-Sequence on csh/tcsh
# Ctrl + c : Kill Current Process on this Terminal Window
# Ctrl + z : Pause Current Process on this Terminal Window
# Ctrl + d : Terminate Current Process on this Terminal Window
# 
# Ctrl + a : Move to Head of Current Commandline
# Ctrl + e : Move to End of Current Commandline
# Ctrl + u : Clear Current Commandline
# Ctrl + l : Clear Terminal Window
Posted by k-square : 2005年09月15日 23:41 | Linux/UNIX
コメント
コメントする









名前、アドレスを登録しますか?