-
Notifications
You must be signed in to change notification settings - Fork 6
/
template
executable file
·184 lines (124 loc) · 3.11 KB
/
template
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
#!/bin/bash
# This is a short script that will copy a file template
# for the user to the desired location.
#
# Not the prettiest script, but it does the job.
#
# Created by Jamie Bodeau on 11/29/2017
# Customization variables --------------------------------
username="Jamie Bodeau"
# Templates ----------------------------------------------
usage=$(cat<<EOF
Usage Method 1: template [filename].[extension]
Usage Method 2: template [flags] [template name] [filename]
Flags:
-h help message
Template options:
py Python
cpp C++
c C
EOF
)
pythonPath="/usr/bin/env python"
py=$(cat<<EOF
#!$pythonPath
# $username
# Imports -------------------------------------------------
import sys
# Classes -------------------------------------------------
# Functions -----------------------------------------------
# Main Execution ------------------------------------------
if __name__ == "__main__":
for line in sys.stdin:
print line
EOF
)
cpp=$(cat<<EOF
// $username
// Headers -----------------------------------------------
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
using namespace std;
// Prototypes --------------------------------------------
// Main Execution ----------------------------------------
int main(int argc, char** argv){
// Exit main
return EXIT_SUCCESS;
}
// Functions ---------------------------------------------
EOF
)
c=$(cat<<EOF
// $username
// Headers -----------------------------------------------
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
// Prototypes --------------------------------------------
// Main Execution ----------------------------------------
int main(int argc, char** argv){
// Exit main
return EXIT_SUCCESS;
}
// Functions ---------------------------------------------
EOF
)
# Functions ----------------------------------------------
print_usage(){
cat <<< "$usage"
}
copy_template(){
if [ $# -gt 1 ]; then
template=$1
destination=$2
cat <<< "$template" > "$destination"
else
echo "Error in copy_template: Not enough args"
fi
}
# Main Execution -----------------------------------------
# Make sure we have some arguments
if [ $# -lt 1 ]; then
print_usage
exit 1
fi
# Complete action
case "$1" in
# Python -----------------------
py)
echo Copying python template.
copy_template "${py}" "$2"
chmod u+x "$2"
;;
*.py)
echo Copying python template.
copy_template "${py}" "$1"
chmod u+x "$1"
;;
# C++ ---------------------------
cpp)
echo Copying C++ template.
copy_template "${cpp}" "$2"
;;
*.cpp)
echo Copying C++ template.
copy_template "${cpp}" "$1"
;;
# C -----------------------------
c)
echo Copying C template.
copy_template "${c}" "$2"
;;
*.c)
echo Copying C template.
copy_template "${c}" "$1"
;;
# Default -----------------------
*) print_usage
exit 1
;;
esac
# Success
exit 0