~python #=============================================================== # # bash-2.05 ์ดํ ๋ฒ์ ์ ์ํ ๊ฐ์ธ์ $HOME/.bashrc ํ์ผ # # ์ ํ์ผ์ ๋ํ๋ชจ๋ ์์ ์ํ ๊ฒ์ ๋๋ค. # ๋ณ์นญ(alias)์ด๋ ํจ์, ํ๋กฌํํธ๊ฐ์ # ๋ํ๋ชจ๋์ฉ ๊ธฐ๋ฅ๋ค์ ์ฌ๊ธฐ์ ๋๋ฉด ๋ฉ๋๋ค. # # ์๋๋ ์๋ผ๋ฆฌ์ค๋ฅผ ์ํด ๋์์ธ ๋์์ต๋๋ค. # --> ๋ฆฌ๋ ์ค์ฉ์ผ๋ก ์์ # ์ด ํ์ผ์ ๋๋ฌด ๋ง์ ๊ฒ์ ํฌํจํ๊ณ ์์ง๋ง # ๋จ์ง ์์ ๋ผ๋ ๊ฒ์ ๊ธฐ์ตํ์ธ์. # ์ฌ๋ฌ๋ถ ํ์์ ๋ฐ๋ผ ์์ ํด์ ์ฐ๊ธฐ ๋ฐ๋๋๋ค. # #=============================================================== # --> ๋ณธ ๋ฌธ์ ์ ์์ ์ํ ์ฃผ์. #----------------------------------- # ํ์ํ๋ค๋ฉด ์ ์ญ ์ ์๋ฅผ source #----------------------------------- if [ -f /etc/bashrc ]; then . /etc/bashrc # --> ์๋ค๋ฉด /etc/bashrc ๋ฅผ ์ฝ์. fi #------------------------------------------------------------- # ์์ง ์ธํธ๋์ง ์์๋ค๋ฉด $DISPLAY ๋ฅผ ์๋์ผ๋ก ์ธํ # ์ด ๋ถ๋ถ์ ๋ฆฌ๋ ์ค์ ์๋ผ๋ฆฌ์ค์ฉ์ ๋๋ค - ํ์ํ๋๋ก ๊ณ ์ณ ์ฐ์ธ์... #------------------------------------------------------------- if [ -z ${DISPLAY:=""} ]; then DISPLAY=$(who am i) DISPLAY=${DISPLAY%%\!*} if [ -n "$DISPLAY" ]; then export DISPLAY=$DISPLAY:0.0 else export DISPLAY=":0.0" # ์คํจํ ๊ฒฝ์ฐ๋ฅผ ๋๋น(fallback) fi fi #--------------- # ๋ช ๊ฐ์ง ์ธํ #--------------- set -o notify set -o noclobber set -o ignoreeof set -o nounset #set -o xtrace # ๋๋ฒ๊น ์ฉ shopt -s cdspell shopt -s cdable_vars shopt -s checkhash shopt -s checkwinsize shopt -s mailwarn shopt -s sourcepath shopt -s no_empty_cmd_completion shopt -s histappend histreedit shopt -s extglob # programmable completion์ ์ ์ฉ #----------------------- # ์ธ์ฌ๋ง, motd ๋ฑ๋ฑ... #----------------------- # ๋จผ์ ์๊น์ ๋ช ๊ฐ ์ ์: red='\e[0;31m' RED='\e[1;31m' blue='\e[0;34m' BLUE='\e[1;34m' cyan='\e[0;36m' CYAN='\e[1;36m' NC='\e[0m' # No Color # --> ์ข๊ตฐ์. ๋์ค์์ "ansi.sys"๋ฅผ ์ฐ๋ ๊ฒ๊ณผ ๋๊ฐ์ ํจ๊ณผ๊ฐ ์๋ค์. # ๊ฒ์ ์ ๋ฐฑ๊ทธ๋ผ์ด๋์์ ๊ฐ์ฅ ์ข๊ฒ ๋ณด์ ๋๋ค..... echo -e "${CYAN}This is BASH ${RED}${BASH_VERSION%.*}${CYAN} - DISPLAY on ${RED}$DISPLAY${NC}\n" date if [ -x /usr/games/fortune ]; then /usr/games/fortune -s # ํ๋ฃจ๋ฅผ ์ฆ๊ฒ๊ฒ.... :-) fi function _exit() # ์์์ ์ข ๋ฃ์ ์คํํ ํจ์ { echo -e "${RED}๋์ค์ ๋ ๋ด์${NC}" } trap _exit 0 #--------------- # ์ ํ๋กฌํํธ #--------------- function fastprompt() { unset PROMPT_COMMAND case $TERM in *term | rxvt ) PS1="[\h] \W > \[\033]0;[\u@\h] \w\007\]" ;; *) PS1="[\h] \W > " ;; esac } function powerprompt() { _powerprompt() { LOAD=$(uptime|sed -e "s/.*: \([^,]*\).*/\1/" -e "s/ //g") TIME=$(date +%H:%M) } PROMPT_COMMAND=_powerprompt case $TERM in *term | rxvt ) PS1="${cyan}[\$TIME \$LOAD]$NC\n[\h \#] \W > \[\033]0;[\u@\h] \w\007\]" ;; linux ) PS1="${cyan}[\$TIME - \$LOAD]$NC\n[\h \#] \w > " ;; * ) PS1="[\$TIME - \$LOAD]\n[\h \#] \w > " ;; esac } powerprompt # ์ข ๋๋ฆด์ง๋ ๋ชจ๋ฅผ ๊ธฐ๋ณธ ํ๋กฌํํธ์ ๋๋ค. # ๋๋ฌด ๋๋ฆฌ๋ฉด fastprompt ๋ฅผ ์ฐ์ธ์.... #=============================================================== # # ๋ณ์นญ(alias)๊ณผ ํจ์๋ค # # ๋ ผ์์ ์ฌ์ง๊ฐ ์์ง๋ง ๋ช๋ช ํจ์๋ค์ ์กฐ๊ธ ๋ฉ์น๊ฐ ํฐ๋ฐ(์ฆ, 'lowercase') # ์ ์ํฌ์คํ ์ด์ ์ ๋จ์ด 512๋ฉ๊ฐ๊ฑฐ๋ ์... # ์ด ํ์ผ ํฌ๊ธฐ๋ฅผ ์ค์ด๊ณ ์ถ๋ค๋ฉด ์ด๋ฐ ํจ์๋ค์ ์คํฌ๋ฆฝํธ๋ก ๋นผ๋ ๋ฉ๋๋ค. # # ๋ง์ ํจ์๋ค์ bash-2.04 ์์ ์์ ๊ฑฐ์ ๊ทธ๋๋ก ๊ฐ๋ค ์ผ์ต๋๋ค. # #=============================================================== #------------------------- # ๊ฐ์ธ์ ์ธ ๋ณ์นญ๋ค(Aliases) #------------------------- alias rm='rm -i' alias cp='cp -i' alias mv='mv -i' # -> ํ์ผ์ ์ค์๋ก ํ๊ฒฉ์ ์ ํ์ง ์๊ฒ. alias h='history' alias j='jobs -l' alias r='rlogin' alias which='type -all' alias ..='cd ..' alias path='echo -e ${PATH//:/\n}' alias print='/usr/bin/lp -o nobanner -d $LPDEST' # LPDEST ๊ฐ ์ ์๋์ด ์๋ค๊ณ ๊ฐ์ alias pjet='enscript -h -G -fCourier9 -d $LPDEST' # enscript ๋ก ์์ ์ถ๋ ฅํ๊ธฐ(Pretty-print) alias background='xv -root -quit -max -rmode 5' # ๋ฐฑ๊ทธ๋ผ์ด๋ ๋ฐฐ๊ฒฝ ๊ทธ๋ฆผ alias vi='vim' alias du='du -h' alias df='df -kh' # 'ls' ๊ทธ๋ฃน(์ฌ๋ฌ๋ถ์ด GNU ls ๋ฅผ ์ด๋ค๊ณ ๊ฐ์ ) alias ls='ls -hF --color' # ํ์ผํ์ ์ธ์์ ์ํด ์๊น์ ์ถ๊ฐ alias lx='ls -lXB' # ํ์ฅ์๋ณ๋ก ์ ๋ ฌ alias lk='ls -lSr' # ํฌ๊ธฐ๋ณ๋ก ์ ๋ ฌ alias la='ls -Al' # ์จ๊ฒจ์ง ํ์ผ ๋ณด๊ธฐ alias lr='ls -lR' # ์ฌ๊ท์ ls alias lt='ls -ltr' # ๋ ์ง๋ณ๋ก ์ ๋ ฌ alias lm='ls -al |more' # 'more'๋ก ํ์ดํ ๊ฑธ๊ธฐ alias tree='tree -Cs' # 'ls'์ ๋ฉ์ง ๋์ฉํ # ๋ง์ถค 'less' alias more='less' export PAGER=less export LESSCHARSET='latin1' export LESSOPEN='|/usr/bin/lesspipe.sh %s 2>&-' # lesspipe.sh ์ด ์๋ค๋ฉด ์ด๊ฑธ ์ฐ์ธ์ export LESS='-i -N -w -z-4 -g -e -M -X -F -R -P%t?f%f \ :stdin .?pb%pb\%:?lbLine %lb:?bbByte %bb:-...' # ์คํ ๋ง ์คํ์ฉ - ์์ฃผ ๊ฐ์ธ์ ์ :-) alias xs='cd' alias vf='cd' alias moer='more' alias moew='more' alias kk='ll' #---------------- # ์ฌ๋ฐ๋ ๊ฑฐ ๋ช ๊ฐ #---------------- function xtitle () { case $TERM in *term | rxvt) echo -n -e "\033]0;$*\007" ;; *) ;; esac } # ๋ณ์นญ๋ค(aliases)... alias top='xtitle Processes on $HOST && top' alias make='xtitle Making $(basename $PWD) ; make' alias ncftp="xtitle ncFTP ; ncftp" # .. ๊ณผ ํจ์๋ค function man () { xtitle The $(basename $1|tr -d .[:digit:]) manual man -a "$*" } function ll(){ ls -l "$@"| egrep "^d" ; ls -lXB "$@" 2>&-| egrep -v "^d|total "; } function xemacs() { { command xemacs -private $* 2>&- & } && disown ;} function te() # xemacs/gnuserv ๋ํผ { if [ "$(gnuclient -batch -eval t 2>&-)" == "t" ]; then gnuclient -q "$@"; else ( xemacs "$@" & ); fi } #----------------------------------- # ํ์ผ & ๋ฌธ์์ด ๊ด๋ จ ํจ์๋ค: #----------------------------------- function ff() { find . -name '*'$1'*' ; } # ํ์ผ ์ฐพ๊ธฐ function fe() { find . -name '*'$1'*' -exec $2 {} \; ; } # ํ์ผ์ ์ฐพ์์ $2 ์ ์ธ์๋ก ์คํ function fstr() # ์ฌ๋ฌ ํ์ผ์ค์์ ๋ฌธ์์ด ์ฐพ๊ธฐ { if [ "$#" -gt 2 ]; then echo "Usage: fstr "pattern" [files] " return; fi SMSO=$(tput smso) RMSO=$(tput rmso) find . -type f -name "${2:-*}" -print | xargs grep -sin "$1" | \ sed "s/$1/$SMSO$1$RMSO/gI" } function cuttail() # ํ์ผ์์ ๋์ n ์ค์ ์๋ผ๋. ๊ธฐ๋ณธ๊ฐ์ 10 { nlines=${2:-10} sed -n -e :a -e "1,${nlines}!{P;N;D;};N;ba" $1 } function lowercase() # ํ์ผ์ด๋ฆ์ ์๋ฌธ์๋ก ๋ณ๊ฒฝ { for file ; do filename=${file##*/} case "$filename" in */*) dirname==${file%/*} ;; *) dirname=.;; esac nf=$(echo $filename | tr A-Z a-z) newname="${dirname}/${nf}" if [ "$nf" != "$filename" ]; then mv "$file" "$newname" echo "lowercase: $file --> $newname" else echo "lowercase: $file not changed." fi done } function swap() # ํ์ผ์ด๋ฆ ๋๊ฐ๋ฅผ ์๋ก ๋ฐ๊ฟ { local TMPFILE=tmp.$$ mv $1 $TMPFILE mv $2 $1 mv $TMPFILE $2 } #----------------------------------- # ํ๋ก์ธ์ค/์์คํ ๊ด๋ จ ํจ์๋ค: #----------------------------------- function my_ps() { ps $@ -u $USER -o pid,%cpu,%mem,bsdtime,command ; } function pp() { my_ps f | awk '!/awk/ && $0~var' var=${1:-".*"} ; } # ์ด ํจ์๋ ๋ฆฌ๋ ์ค์ 'killall' ์คํฌ๋ฆฝํธ์ ๊ฑฐ์ ๋น์ทํ์ง๋ง # ์๋ผ๋ฆฌ์ค์๋, ์ ๊ฐ ์๋ ํ, ์ด์ ๋น์ทํ ๊ฒ์ด ์์ต๋๋ค. function killps() # ํ๋ก์ธ์ค ์ด๋ฆ์ผ๋ก kill { local pid pname sig="-TERM" # ๊ธฐ๋ณธ ์๊ทธ๋ if [ "$#" -lt 1 ] || [ "$#" -gt 2 ]; then echo "Usage: killps [-SIGNAL] pattern" return; fi if [ $# = 2 ]; then sig=$1 ; fi for pid in $(my_ps| awk '!/awk/ && $0~pat { print $1 }' pat=${!#} ) ; do pname=$(my_ps | awk '$1~var { print $5 }' var=$pid ) if ask "Kill process $pid <$pname> with signal $sig?" then kill $sig $pid fi done } function my_ip() # IP ์ฃผ์ ์์๋ด๊ธฐ { MY_IP=$(/sbin/ifconfig ppp0 | awk '/inet/ { print $2 } ' | sed -e s/addr://) MY_ISP=$(/sbin/ifconfig ppp0 | awk '/P-t-P/ { print $3 } ' | sed -e s/P-t-P://) } function ii() # ํ์ฌ ํธ์คํธ ๊ด๋ จ ์ ๋ณด๋ค ์์๋ด๊ธฐ { echo -e "\nYou are logged on ${RED}$HOST" echo -e "\nAdditionnal information:$NC " ; uname -a echo -e "\n${RED}Users logged on:$NC " ; w -h echo -e "\n${RED}Current date :$NC " ; date echo -e "\n${RED}Machine stats :$NC " ; uptime echo -e "\n${RED}Memory stats :$NC " ; free my_ip 2>&- ; echo -e "\n${RED}Local IP Address :$NC" ; echo ${MY_IP:-"Not connected"} echo -e "\n${RED}ISP Address :$NC" ; echo ${MY_ISP:-"Not connected"} echo } # ๊ธฐํ ์ ํธ๋ฆฌํฐ: function repeat() # ๋ช ๋ น์ด๋ฅผ n ๋ฒ ๋ฐ๋ณต { local i max max=$1; shift; for ((i=1; i <= max ; i++)); do # --> C ํํ์ ๋ฌธ๋ฒ eval "$@"; done } function ask() { echo -n "$@" '[y/n] ' ; read ans case "$ans" in y*|Y*) return 0 ;; *) return 1 ;; esac } #========================================================================= # # PROGRAMMABLE COMPLETION - ์ค์ง BASH 2.04 ์ดํ์์๋ง ๋์ # (๊ฑฐ์ ๋๋ถ๋ถ์ bash 2.05 ๋ฌธ์์์ ๊ฐ์ ธ์์ต๋๋ค) # ๋ช ๊ฐ์ง ๊ธฐ๋ฅ๋ค์ ์ฐ๋ ค๋ฉด bash-2.05 ๊ฐ ํ์ํ ๊ฒ๋๋ค. # #========================================================================= if [ "${BASH_VERSION%.*}" \< "2.05" ]; then echo "programmable completion ์ ์ฐ๋ ค๋ฉด bash 2.05 ์ด์์ผ๋ก ์ ๊ทธ๋ ์ด๋๊ฐ ํ์ํฉ๋๋ค." return fi shopt -s extglob # ๊ผญ ํ์ํจ set +o nounset # ์ด๋ ๊ฒ ์ ํ๋ฉด programmable completion ๋ช ๊ฐ์ง๋ ์คํจํจ # ์ฎ๊ธด์ด: ์ด ์ดํ๋ ์ ๋ชจ๋ฅด๊ฒ ๋ค์. :( complete -A hostname rsh rcp telnet rlogin r ftp ping disk complete -A command nohup exec eval trace gdb complete -A command command type which complete -A export printenv complete -A variable export local readonly unset complete -A enabled builtin complete -A alias alias unalias complete -A function function complete -A user su mail finger complete -A helptopic help # currently same as builtins complete -A shopt shopt complete -A stopped -P '%' bg complete -A job -P '%' fg jobs disown complete -A directory mkdir rmdir complete -A directory -o default cd complete -f -d -X '*.gz' gzip complete -f -d -X '*.bz2' bzip2 complete -f -o default -X '!*.gz' gunzip complete -f -o default -X '!*.bz2' bunzip2 complete -f -o default -X '!*.pl' perl perl5 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 '!*.+(jpg|gif|xpm|png|bmp)' xv gimp complete -f -o default -X '!*.mp3' mpg123 complete -f -o default -X '!*.ogg' ogg123 # This is a 'universal' completion function - it works when commands have # a so-called 'long options' mode , ie: 'ls --all' instead of 'ls -a' _universal_func () { case "$2" in -*) ;; *) return ;; esac case "$1" in \~*) eval cmd=$1 ;; *) cmd="$1" ;; esac COMPREPLY=( $("$cmd" --help | sed -e '/--/!d' -e 's/.*--\([^ ]*\).*/--\1/'| \ grep ^"$2" |sort -u) ) } complete -o default -F _universal_func ldd wget bash id info _make_targets () { local mdef makef gcmd cur prev i COMPREPLY=() cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]} # if prev argument is -f, return possible filename completions. # we could be a little smarter here and return matches against # `makefile Makefile *.mk', whatever exists case "$prev" in -*f) COMPREPLY=( $(compgen -f $cur ) ); return 0;; esac # if we want an option, return the possible posix options case "$cur" in -) COMPREPLY=(-e -f -i -k -n -p -q -r -S -s -t); return 0;; esac # make reads `makefile' before `Makefile' if [ -f makefile ]; then mdef=makefile elif [ -f Makefile ]; then mdef=Makefile else mdef=*.mk # local convention fi # before we scan for targets, see if a makefile name was specified # with -f for (( i=0; i < ${#COMP_WORDS[@]}; i++ )); do if [[ ${COMP_WORDS[i]} == -*f ]]; then eval makef=${COMP_WORDS[i+1]} # eval for tilde expansion break fi done [ -z "$makef" ] && makef=$mdef # if we have a partial word to complete, restrict completions to # matches of that word if [ -n "$2" ]; then gcmd='grep "^$2"' ; else gcmd=cat ; fi # if we don't want to use *.mk, we can take out the cat and use # test -f $makef and input redirection COMPREPLY=( $(cat $makef 2>/dev/null | awk 'BEGIN {FS=":"} /^[^.# ][^=]*:/ {print $1}' | tr -s ' ' '\012' | sort -u | eval $gcmd ) ) } complete -F _make_targets -X '+($*|*.[cho])' make gmake pmake _configure_func () { case "$2" in -*) ;; *) return ;; esac case "$1" in \~*) eval cmd=$1 ;; *) cmd="$1" ;; esac COMPREPLY=( $("$cmd" --help | awk '{if ($1 ~ /--.*/) print $1}' | grep ^"$2" | sort -u) ) } complete -F _configure_func configure # cvs(1) completion _cvs () { local cur prev COMPREPLY=() cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]} if [ $COMP_CWORD -eq 1 ] || [ "${prev:0:1}" = "-" ]; then COMPREPLY=( $( compgen -W 'add admin checkout commit diff \ export history import log rdiff release remove rtag status \ tag update' $cur )) else COMPREPLY=( $( compgen -f $cur )) fi return 0 } complete -F _cvs cvs _killall () { local cur prev COMPREPLY=() cur=${COMP_WORDS[COMP_CWORD]} # get a list of processes (the first sed evaluation # takes care of swapped out processes, the second # takes care of getting the basename of the process) COMPREPLY=( $( /usr/bin/ps -u $USER -o comm | \ sed -e '1,1d' -e 's#[]\[]##g' -e 's#^.*/##'| \ awk '{if ($0 ~ /^'$cur'/) print $0}' )) return 0 } complete -F _killall killall killps # Local Variables: # mode:shell-script # sh-shell:bash # End: