#!/bin/bash
#filename:touchscript
#USAGE:touchscript [sh|pl|py] filename
#writer:codewalkertse
#email:xyy.xx.victor@gmail.com
#creat at 2012-12-04
#update 2013-11-17
INFO=$(cat <<”EOF”
#auth:codewalker
#mail:001@codewalker.me
EOF
)
if [ $# -eq 2 ];then
if [ -f $2 ];then
echo “file:$2 existed.”
exit 1
fi
case $1 in
sh|SH)
echo “creat a bash script:$2”
echo “#!/bin/bash” > $2
echo $INFO >> $2
chmod 700 $2;;
pl|PL)
echo “creat a perl script:$2”
echo “#!/usr/bin/perl -w” > $2
echo $INFO >> $2
echo “use strict;” >> $2
chmod 700 $2;;
py|Py)
echo “creat a python script:$2”
echo “#!/usr/bin/python2” >> $2
echo “” >> $2
echo $INFO >> $2
echo “” >> $2
echo “def main():” >> $2
echo “” >> $2
echo “if __name__ == \“__main__:\“” >> $2
echo “ main()” >> $2
chmod 700 $2;;
*)
echo “USAGE:mytouch sh|pl|py filename”;;
esac
read -p “Do you vim it?[y]“ is_vim
case $is_vim in
y|Y|yes|Yes)
vim $2;;
*)
echo “you chose not edit it!”;;
esac
elif [ $# -eq 1 ];then
if [ -f $1 ];then
echo “file:$1 exice.”
exit 1
fi
echo “creat empty file: $1”;
touch $1
else
echo ‘ARGS ERROR’
echo ‘USAGE:mytouch sh|pl|py filename’;
fi
exit 1