|
@@ -4,7 +4,7 @@
|
4
|
4
|
usage() {
|
5
|
5
|
local self
|
6
|
6
|
self="$(basename "$0")"
|
7
|
|
- warn "usage: $self [-f|--force] FILE [[+]TEMPLATE]"
|
|
7
|
+ warn "usage: $self [-f|--force] [+TEMPLATE] FILE"
|
8
|
8
|
warn "usage: $self -l|--list"
|
9
|
9
|
exit 2
|
10
|
10
|
}
|
|
@@ -28,8 +28,8 @@ lstemplates() {
|
28
|
28
|
#
|
29
|
29
|
# Print list of valid templates
|
30
|
30
|
#
|
31
|
|
- echo +pya
|
32
|
|
- echo +shellfu
|
|
31
|
+ echo pya
|
|
32
|
+ echo shellfu
|
33
|
33
|
echo Bash
|
34
|
34
|
echo Lua
|
35
|
35
|
echo Perl
|
|
@@ -41,13 +41,9 @@ lstemplates() {
|
41
|
41
|
#shellcheck disable=SC2016
|
42
|
42
|
mktemplate() {
|
43
|
43
|
#
|
44
|
|
- # Print template $1 for $FilePath
|
|
44
|
+ # Print template $Template for $FilePath
|
45
|
45
|
#
|
46
|
|
- # Template may be a name of built-in template (starting with
|
47
|
|
- # plus sign) or language name (actually *interpreter* name).
|
48
|
|
- #
|
49
|
|
- local tmplname="${1:-$Template}"
|
50
|
|
- case "$tmplname" in
|
|
46
|
+ case "$Template" in
|
51
|
47
|
sh)
|
52
|
48
|
echo "#!/bin/sh"
|
53
|
49
|
echo ''
|
|
@@ -82,7 +78,7 @@ mktemplate() {
|
82
|
78
|
echo "if __name__ == '__main__':"
|
83
|
79
|
echo ' '
|
84
|
80
|
;;
|
85
|
|
- +pya)
|
|
81
|
+ pya)
|
86
|
82
|
echo '#!/usr/bin/python'
|
87
|
83
|
echo '"""'
|
88
|
84
|
echo 'A simple application'
|
|
@@ -120,7 +116,7 @@ mktemplate() {
|
120
|
116
|
echo 'if __name__ == '__main__':'
|
121
|
117
|
echo ' App.main(sys.argv)'
|
122
|
118
|
;;
|
123
|
|
- +shellfu)
|
|
119
|
+ shellfu)
|
124
|
120
|
echo "#!/bin/bash"
|
125
|
121
|
echo ""
|
126
|
122
|
echo '#shellcheck disable=SC1090'
|
|
@@ -143,9 +139,6 @@ mktemplate() {
|
143
|
139
|
echo ''
|
144
|
140
|
echo 'main "$@"'
|
145
|
141
|
;;
|
146
|
|
- "")
|
147
|
|
- mktemplate "$(guess_language)"
|
148
|
|
- ;;
|
149
|
142
|
*)
|
150
|
143
|
die "unknown template or language: $Template"
|
151
|
144
|
;;
|
|
@@ -179,12 +172,13 @@ main() {
|
179
|
172
|
-f|--force) careful=false; shift ;;
|
180
|
173
|
-l|--list) lstemplates; exit 0 ;;
|
181
|
174
|
-*) usage ;;
|
|
175
|
+ +*) Template="${1:1}"; shift ;;
|
182
|
176
|
*) break ;;
|
183
|
177
|
esac done
|
184
|
178
|
FilePath="$1"
|
185
|
|
- Template="$2"
|
186
|
179
|
test -n "$FilePath" || usage
|
187
|
180
|
test -f "$FilePath" && $careful && die "file already exists: $FilePath"
|
|
181
|
+ test -n "$Template" || Template=$(guess_language)
|
188
|
182
|
mktemplate > "$FilePath"
|
189
|
183
|
chmod +x "$FilePath"
|
190
|
184
|
}
|