-
Notifications
You must be signed in to change notification settings - Fork 88
/
Copy pathmakemd-tables
executable file
·56 lines (42 loc) · 1.93 KB
/
makemd-tables
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
#!/usr/bin/env bash
#
# Shorten and secure URL's in a [GFM](https://guides.github.com/features/mastering-markdown/#GitHub-flavored-markdown)
# file's linking syntax (i.e. square brackets followed by parentheses as demonstrated above.)
# 'Shorten' by removing unnecessary `www` hostnames and 'secure' by converting `http:` schemes to `https:`.
#
# Written By: Derek Callaway [decal (AT) sdf {D0T} org]
# Last Modified: Sat Apr 14 02:27:36 DST 2018
# Tested On: Ubuntu Bash in Windows Subsystem for Linux
#
[ ! -d scripts ] && echo
[ -f scripts/shared/colors ] && source scripts/shared/colors
[ -f scripts/shared/env ] && source scripts/shared/env
if [ ! "$1" ]
then echo -ne "${reset}"
echo -e "${yellowf}usage${boldon}:${reset} ${bluef}${ulon}$0${reset} ${greenb}MDFILE${reset}"
echo -e " ${greenb}MDFILE${reset} ${italicson}markdown file containing links to rewrite${reset}"
echo
exit 1
fi
# for ardme in $(find . -type f -name 'README.md' -print | egrep '^[.]?/[a-z-]+/README.md$')
for ardme in $*
do declare -i acnt=$(egrep -i '^[|]' $ardme | wc -l)
[ $acnt -ne 0 ] && continue # keep going, no lines start with pipes, i.e. no markdown table
cp -av "$ardme" "${ardme}.orig"
echo '| _Folder Name_ | _Description of Contents_' >> "${ardme}.new"
echo '|:----------------|--------------------------------------------------------------------------------------------------------------------------------------------------------' >> "${ardme}.new"
#cd $(dirname $ardme)
(while read line
do declare aname=$(echo $line | awk -F: '{print$1}') adesc=$(echo $line | cut -d ':' -f2-)
cd $(dirname $ardme)
declare alink=$(ls -1 -- ${aname}.*)
cd ..
echo "| [${aname}](${alink}) | $adesc " >> "${ardme}.new"
done) < $ardme
#cd ..
echo >> "${ardme}.new"
echo '* * *' >> "${ardme}.new"
echo >> "${ardme}.new"
mv -v "${ardme}.new" "${ardme}"
done
exit 0