-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathreadme-gen
executable file
·151 lines (135 loc) · 4.37 KB
/
readme-gen
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
#!/bin/bash
# GPL License
#
# Copyright (c) 2019 Meyers Tom
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
# Simple bash script to generate README's
# Build and maintained by Tom Meyers
# it uses "variables" in template README's
# to populate data and generate a good looking and consistent file
name=$(basename "$0")
directory="/var/cache/readme/"
userdir="$HOME/.cache/readme/"
# Default template
theme="visual"
# print out help information
function help() {
printf "%s OPTIONS:\n" "$name"
printf "\t %s -h|--help \t\t Print help information\n" "$name"
printf "\t %s \t\t\t Answer questions interactivaly to generate readme\n" "$name"
printf "\t %s -l|--list\t\t Return a list of all possible readme templates\n" "$name"
printf "\t %s -t|--theme\t\t Use the theme present in said list\n" "$name"
printf "\t %s -a|--add\t\t Add a homemade readme template \n" "$name"
printf "\t %s -c|--config\t\t Instead of generating a readme interactivaly use a config to generate the readme from. \n" "$name"
printf "\n\n"
printf "EXTRA INFO\n"
printf "\t Sample config can be found here: https://www.github.com/F0xedb/README-generator\n"
printf "\t Documentation: https://www.github.com/F0xedb/README-generator/wiki\n"
}
# interactivaly get the project data
function generate() {
read -r -p "What is your project name? " repo
read -r -p "What is your github name/organization? " org_name
read -r -p "What is your name/id? " usr_name
read -r -p "What is your email? " usr_email
read -r -p "What is the title? " title
read -r -p "Give us a short description? " desc
read -r -p "What is your documentation url? " doc
read -r -p "What is your license? " license
read -r -p "What is your image url? " image_url
read -r -p "What is your image width in px? " width
read -r -p "What is your image height in px? " height
}
# generate the readme
function execute() {
if [[ -f "$directory""$theme" ]]; then
sed "s;repo;$repo;g" "$directory""$theme" >README.md
else
sed "s;repo;$repo;g" "$userdir""$theme" >README.md
fi
sed -i "s;org_name;$org_name;g" README.md
sed -i "s;usr_name;$usr_name;g" README.md
sed -i "s;usr_email;$usr_email;g" README.md
sed -i "s;title_var;$title;g" README.md
sed -i "s;desc_var;$desc;g" README.md
sed -i "s;doc_var;$doc;g" README.md
sed -i "s;license_var;$license;g" README.md
sed -i "s;image_url;$image_url;g" README.md
sed -i "s;width_img;$width;g" README.md
sed -i "s;height_img;$height;g" README.md
}
# add a template to the template directory
function add() {
if [[ ! -d "$userdir" ]]; then
mkdir -p "$userdir"
fi
if [[ -f "$1" ]]; then
cp "$1" "$userdir"
else
printf "You can only add files to the list"
exit 1
fi
}
# handle user input
function handler() {
case "$1" in
"-h" | "--help")
help
exit 0
;;
"-a" | "--add")
add "$2"
exit 0
;;
"-l" | "--list")
if [[ -d "$directory" ]]; then
ls "$directory"
fi
if [[ -d "$userdir" ]]; then
ls "$userdir"
fi
exit 0
;;
"-t" | "--theme")
if [[ -f "$directory""$2" || -f "$userdir""$2" ]]; then
theme="$2"
else
printf "Theme's can only be files inside %s or %s use $name -l for a list" "$directory" "$userdir"
exit 1
fi
;;
"-c" | "--config")
if [[ -f "$2" ]]; then
source "$2"
else
printf "Invalid config"
exit 2
fi
;;
esac
}
handler "$1" "$2"
if [[ -f README.md ]]; then
mv README.md README_old.md
fi
if [[ "$1" != "-c" && "$1" != "--config" ]]; then
generate
fi
execute