-
Notifications
You must be signed in to change notification settings - Fork 0
/
geekcode
executable file
·94 lines (79 loc) · 2.38 KB
/
geekcode
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
#!/bin/sh
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# Copyright 2021 Jeremy Brubaker <јЬruЬаkе@оrіоnаrtѕ.іо>
#
# abstract: convert a commented geekcode file into a proper geekcode
#
# Defaults {{{1
#
DEFAULT_WIDTH=72
VERSION='1.0'
GEEKCODE="$HOME/.geekcode"
# Documentation {{{1
#
print_help() (
cat <<EOF
Usage: $0 [option]
Convert a commented geekcode file into a proper geekcode
See https://github.com/telavivmakers/geek_code for the Geek Code specification.
-f FILE get geekcode from FILE
-w WIDTH use WIDTH as the maximum line width (Default: $DEFAULT_WIDTH)
-b output Geek Code Block delimiters
-v display version info and exit
-h display this help and exit
EOF
) >&2
print_version() (
cat <<EOF
$0 $VERSION
Copyright (C) 2021 Orion Arts
License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Written by Jeremy Brubaker.
EOF
) >&2
# Process options {{{1
#
width=$DEFAULT_WIDTH
block='n'
while getopts 'f:w:bvh' opt; do
case $opt in
f) GEEKCODE=$OPTARG ;;
w) width=$OPTARG ;;
b) block='y' ;;
v) print_version; exit ;;
h|?) print_help; exit ;;
esac
done
# Generate geekcode {{{1
#
if [ ! -r "$GEEKCODE" ]; then
printf "%s not found. Exiting!\n" "$GEEKCODE" >&2
exit 1
fi
if [ "$block" = "y" ]; then
version=$(head -1 "$GEEKCODE" | sed -e 's/^# *//')
printf "%s\n" "-----BEGIN GEEK CODE BLOCK-----"
printf "%s\n" "$version"
fi
< "$GEEKCODE" sed -e '/^#/d' -e 's/ *#.*$//' \
| tr '\n' ' ' \
| sed -e 's/ *$//' \
| fold -w"$width" -s
printf "%s\n" ""
if [ "$block" = "y" ]; then
printf "%s\n" "------END GEEK CODE BLOCK------"
fi