/ mksource.sh
mksource.sh
 1  #! /usr/bin/env sh
 2  
 3  ###############################################################################
 4  # touch sources files from template
 5  ###############################################################################
 6  
 7  readonly today=$(date +%Y-%m-%d)
 8  
 9  readonly prefix='https://raw.githubusercontent.com/Shylock-Hg/config.linux/master/template'
10  
11  while getopts 'n:h' args
12  do
13  	case $args in
14  		n)  #!< name of source file
15                          readonly suffix_cheader='h'
16                          readonly suffix_csource='c'
17                          readonly suffix_python='py'
18                          readonly suffix_ccheader='hh'
19                          readonly suffix_ccsource='cc'
20                          readonly suffix_sh='sh'
21  				
22  			# Makefile
23  			if [ $OPTARG = 'Makefile' ]; then
24                                  curl $prefix/linux.mk -o $PWD/$OPTARG
25  
26  			# c
27                          elif [ ${OPTARG##*.} = $suffix_cheader ]; then
28                                  uppername=${OPTARG%.*}
29                                  uppername=${uppername^^}
30                                  if curl $prefix/template.h -o $PWD/$OPTARG; then
31                                          sed -i  -e "s/\\date.\+/\\date $today/g" \
32                                                  -e "s/_.\+_H_/_${uppername}_H_/g" $PWD/$OPTARG
33                                  fi
34                          elif [ ${OPTARG##*.} = $suffix_csource ]; then
35                                  if curl $prefix/template.c -o $PWD/$OPTARG; then
36  				        sed -i "s/\\date.\+/\\date $today/g" $PWD/$OPTARG
37                                  fi
38  
39  			# c++
40                          elif [ ${OPTARG##*.} = $suffix_ccheader ]; then
41                                  uppername=${OPTARG%.*}
42                                  uppername=${uppername^^}
43                                  if curl $prefix/template.hh -o $PWD/$OPTARG; then
44                                          sed -i  -e "s/\\date.\+/\\date $today/g" \
45                                                  -e "s/_.\+_HH_/_${uppername}_HH_/g" $PWD/$OPTARG
46                                  fi
47                          elif [ ${OPTARG##*.} = $suffix_ccsource ]; then
48                                  if curl $prefix/template.cc -o $PWD/$OPTARG; then
49  				        sed -i "s/\\date.\+/\\date $today/g" $PWD/$OPTARG
50                                  fi
51  			# python
52                          elif [ ${OPTARG##*.} = $suffix_python ]; then
53                                  if curl $prefix/template.py -o $PWD/$OPTARG; then
54  				        sed -i "s/\\date.\+/\\date $today/g" $PWD/$OPTARG
55                                  fi
56                          elif [ ${OPTARG##*.} = $suffix_sh ]; then
57                                  if curl $prefix/template.sh -o $PWD/$OPTARG; then
58  				        sed -i "s/\\date.\+/\\date $today/g" $PWD/$OPTARG
59                                  fi
60                          # shell
61  			else
62  				echo 'error:Unkown file type!'
63  			fi
64  
65  			;;
66  		h)
67                          printf "usage: $0 -n <name-of-source>\neg.$0 -n example.h"
68  			;;
69  		?)
70  			echo "error:Unknown argument $OPTARG!"
71  			;;
72  	esac
73  done
74  
75  shift $((OPTIND - 1))