forked from h5bp/html5please
-
Notifications
You must be signed in to change notification settings - Fork 1
/
new_feature.sh
executable file
·84 lines (68 loc) · 1.76 KB
/
new_feature.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
#!/bin/bash
# Function Abstracting Prompts
promptValue() {
read -p "$1"": " val
echo $val
}
feature=
featureslug=
status=
tags=
kind=
while [ -z "$feature" ]
do
feature=$(promptValue "Enter Feature Name")
done
# Make feature name slug friendly
featureslug=$(
echo $feature |
# Use sed to replace spaces with hyphens
sed -E -e "s/ +/-/" -e "s/[^A-Za-z0-9\-]//g" |
# BSD sed doesnt accept \L, so use tr instead for case conversion
tr "[A-Z]" "[a-z]"
)
while [ -z "$status" ]
do
status=$(promptValue "Enter Status (use,avoid, or caution)")
case $status in
use|avoid|caution) : ;;
*) status= ;;
esac
done
while [ -z "$tags" ]
do
tags=$(promptValue "Enter Tags (one or more of: gtie6,gtie7,gtie8,prefixes,polyfill, fallback, or none)")
if [ -n "$tags" ]
then
set $(echo $tags)
while [ $# -gt 0 ]
do
case "$1" in
gtie6|gtie7|gtie8|gtie9|prefixes|polyfill|fallback|noie|nomobile|nooldmobile|none) shift ;;
*) echo "Unknown Tag: $1" 1>&2; tags= ; break ;;
esac
done
fi
done
while [ -z "$kind" ]
do
kind=$(promptValue "Enter Type (css,html,js,api or svg)")
case $kind in
css|html|js|api|svg) : ;;
*) kind= ;;
esac
done
# Creating markdown file in posts folder
POSTS_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )/posts"
[ -e "$POSTS_DIR/$featureslug.md" ] && echo "$featureslug.md already exists" && exit 1
cat > $POSTS_DIR/$featureslug.md <<EOF
feature: $feature
status: $status
tags: $tags
kind: $kind
polyfillurls:
…
EOF
echo "Created file $POSTS_DIR/$featureslug.md" 1>&2
# Open it in your editor for adding content
[ -n "$EDITOR" ] && $EDITOR "$POSTS_DIR/$featureslug.md"