-
Notifications
You must be signed in to change notification settings - Fork 0
/
run-template.sh
116 lines (100 loc) · 3.5 KB
/
run-template.sh
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
#!/usr/bin/env bash
## Declare defaults:
_def_name="haskell-template-hebele"
_def_title="Haskell Project Template"
_def_github="vst/haskell-template-hebele"
_def_author="Vehbi Sinan Tunalioglu"
_def_maintainer="[email protected]"
_def_copyright="Copyright (c) 2024 Vehbi Sinan Tunalioglu"
## Initialize variables:
_var_name="${_def_name}"
_var_title="${_def_title}"
_var_github="${_def_github}"
_var_author="${_def_author}"
_var_maintainer="${_def_maintainer}"
_var_copyright="${_def_copyright}"
## Let's start:
cat <<EOF
You are about to configure the Haskell Template Project. I will ask
you some questions. Then, I will configure your project according to
your answers.
EOF
read -p "Do you want to proceed? (y/N) " -n 1 -r
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
>&2 echo "Exiting..."
fi
echo
echo
echo "1/6. Project Name: The project name must be a valid Haskell package name. See <https://cabal.readthedocs.io/en/3.4/cabal-package.html#pkg-field-name>."
echo
read -p "Enter the project name [${_def_name}]: " _var_name
_var_name="${_var_name:-"${_def_name}"}"
echo
echo
echo "2/6. Project Title: The project title appearing on the README header, CLI header etc..."
echo
read -p "Enter the project title [${_def_title}]: " _var_title
_var_title="${_var_title:-"${_def_title}"}"
echo
echo
echo "3/6. GitHub Repository: This must be in the form of <repository-owner>/<repository-name>."
echo
read -p "Enter the GitHub repository [${_def_github}]: " _var_github
_var_github="${_var_github:-"${_def_github}"}"
echo
echo
echo "4/6. Author: Who is the author? See <https://cabal.readthedocs.io/en/3.4/cabal-package.html#pkg-field-author>"
echo
read -p "Enter the author [${_def_author}]: " _var_author
_var_author="${_var_author:-"${_def_author}"}"
echo
echo
echo "5/6. Maintainer: Who is the maintainer? See <https://cabal.readthedocs.io/en/3.4/cabal-package.html#pkg-field-maintainer>"
echo
read -p "Enter the maintainer [${_def_maintainer}]: " _var_maintainer
_var_maintainer="${_var_maintainer:-"${_def_maintainer}"}"
echo
echo
echo "6/6. Copyright: What is the copyright notice? See <https://cabal.readthedocs.io/en/3.4/cabal-package.html#pkg-field-copyright>"
echo
read -p "Enter the copyright [${_def_copyright}]: " _var_copyright
_var_copyright="${_var_copyright:-"${_def_copyright}"}"
echo
## Confirmation:
echo
echo "Here is what you want:"
echo "======================"
echo
cat <<EOF
1. Project Name : ${_var_name}
2. Project Title : ${_var_title}
3. GitHub Repository : ${_var_github}
4. Author : ${_var_author}
5. Maintainer : ${_var_maintainer}
6. Copyright : ${_var_copyright}
EOF
echo
read -p "Do you want to proceed? (y/N) " -n 1 -r
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
>&2 echo "Exiting..."
fi
echo
_files() {
find . -type d \( -path ./dist -o -path ./dist-newstyle -o -path ./.direnv -o -path ./.git \) -prune -o -type f -a -not -name "run-template.sh" -print
}
_update() {
_file="${1}"
_fpath_def="$(echo "${_def_name}" | sed "s/\-/_/g")"
_fpath_new="$(echo "${_var_name}" | sed "s/\-/_/g")"
sed -i "s|${_def_github}|${_var_github}|g" "${_file}"
sed -i "s|${_def_copyright}|${_var_copyright}|g" "${_file}"
sed -i "s|${_def_author}|${_var_author}|g" "${_file}"
sed -i "s|${_def_maintainer}|${_var_maintainer}|g" "${_file}"
sed -i "s|${_def_name}|${_var_name}|g" "${_file}"
sed -i "s|${_def_title}|${_var_title}|g" "${_file}"
sed -i "s|${_fpath_def}|${_fpath_new}|g" "${_file}"
}
_files | sort | while read -r _path; do
echo "Processing ${_path}"
_update "${_path}"
done