我的Bash配置文件:.bashrc
时间:2007-04-19 来源:naihe2010
今天,一个朋友要我的shell配置文件。我忽然想到,自己的shell配置,实在应该在一个安全稳妥的地方,保存一下。
于是,把它贴在这里。也算是一个共享精神吧!
下一篇,粘的是Vim的配置文件:.vimrc,这篇是.bashrc
PS1="[\u@\h:\w]$ "
# ~/tl &
# make a trash function
# when rm a file or a directory, it will be mv to .trash
function moveto_trash(){
declare -r ext=`date +%Y%m%d%H%M%S`
declare -a item
declare -i index=0
declare -x ask="n"
declare -x current=`pwd`
declare -x dir
for i in $*
do
case $i in
-d) continue
;;
-f) continue
;;
-R) continue
;;
-r) continue
;;
-i) ask="y"
;;
-*) printf "%s" "argument: $i is not valid\n"
continue
;;
*) if [ -e $i ]; then
if [ "$i" = "$current" ]; then
echo "$i is current directory"
continue
fi
item[$index]=$i
index=`expr $index + 1`
else
echo "$i is not exist"
fi
esac
done
if [ $index -gt 0 ]; then
if [ $ask = "y" ]; then
echo "Move ${item[*]} into the trash? [y/n]"
read ans
case $ans in
n) return;;
N) return;;
no) return;;
NO) return;;
esac
fi
echo "Move ${item[*]} into trash"
for i in ${item[*]}
do
dir=`dirname $i`
if [ "$dir" != "$current" ]; then
old=`echo $i | awk -F/ '{print $NF}'`
else
old=$i
fi
mv $i ~/.trash/$old.$ext
done
fi
}
# delete the old file function from .trash
function delete_older(){
now=`date +%Y%m%d%H%M%S`
then=`echo $1|awk -F. '{print $NF}'`
older=`expr $now - $then`
long=`expr 1000000 \* $2`
if [ $older -gt $long ]; then
echo "$1 is $2 days old now, remove it from trash [y/n]"
read ans
case $ans in
n) return
;;
N) return
;;
esac
rm -r $1
fi
}
# delete old files
for i in `ls ~/.trash`; do delete_older ~/.trash/$i 1; done
alias rm='moveto_trash'
# play file, directoy, or anything
function play(){
declare -a marg
declare -a dir
declare -a file
declare -a list
declare -x arg=0
declare -x mi=0
declare -x di=0
declare -x ii=0
for i in $*
do
if [ $arg -eq 1 ]; then
marg[$mi]=$i
mi=`expr $mi + 1`
arg=0
elif [ "`echo $i | cut -c 1`" = "-" ]; then
marg[$mi]=$i
mi=`expr $mi + 1`
arg=1
elif [ -d $i ]; then
dir[$di]=$i
di=`expr $di + 1`
elif [ -f $i ]; then
file[$ii]=$i
ii=`expr $ii + 1`
fi
done
if [ $di -gt 0 ]; then
for temp in `ls -R ${dir[*]}`
do
tempdir=`echo $temp | awk -F: '{print $1}'`
if [ -d $tempdir ]; then
temp_dir=$tempdir
elif [ -f $temp_dir/$temp ]; then
file[$ii]=$temp_dir/$temp
ii=`expr $ii + 1`
fi
done
fi
if [ $mi -gt 0 ]; then
mplayer ${marg[*]} ${file[*]}
else
mplayer ${file[*]}
fi
}
# save local files to my email
function save(){
for i in $*; do
split -b 15m $i
sub=`basename $i`
k=1
for j in `ls xa*`; do
mutt -s "$sub($k)" -a $j [email protected] < /dev/null && \
echo "send $i's $k part to [email protected], OK"
k=`expr $k + 1`
done
echo "save the $i, OK"
done
}
alias ls="ls --color=auto"
alias ll="ls -l"
alias la="ls -a"
alias lS="ls -lS"
alias ~="cd ~ && ll"
alias .="ll"
alias ..="cd .. && ll"
alias ca="cd ~/.aMule/Incoming"
alias cT="cd ~/.aMule/Temp"
alias cf="cd ~/file && ll"
alias ct="cd ~/technology && ll"
alias df="df -m"
alias gcj="gcj -C"
alias javac="gcj -C"
alias vi="vi -b"
alias vo="vi -o"
alias view="vim -o"
alias cvs="cvs -d ~/project"
alias shutdown="/sbin/shutdown -h now"
alias reboot="/sbin/shutdown -r now"
相关阅读 更多 +