-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnew
executable file
·48 lines (36 loc) · 882 Bytes
/
new
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/env bash
set -e
function die()
{
echo "$*" 1>&2
exit 1
}
function usagedie()
{
echo "USAGE: new <template> <file>"
echo " new -l"
die $@
}
function check_env()
{
[[ -n $SOURCE_TEMPLATES ]] || die "Source templates dir not set. Use SOURCE_TEMPLATES"
[[ -d $SOURCE_TEMPLATES ]] || die "Source templates dir not found"
}
function check_args()
{
[[ -n $1 ]] || usagedie "No source template provided"
[[ -n $2 ]] || usagedie "No destination file name provided"
}
function main()
{
check_env
if [[ $1 == '--complete' ]] || [[ $1 == '-l' ]]; then
( builtin cd $SOURCE_TEMPLATES; ls -1 )
exit 0
fi
check_args "$@"
local source_template="$SOURCE_TEMPLATES/$1"
[[ -f $source_template ]] || die "Specified source template not found"
command cp -r "$source_template" "$2"
}
main "$@"