forked from ff6347/github-utilities
-
Notifications
You must be signed in to change notification settings - Fork 1
/
create_toc_of_folder.sh
executable file
·66 lines (61 loc) · 1.68 KB
/
create_toc_of_folder.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
#!/bin/sh
# create list with the first 7 lines of all scripts in markdown
# author: @fabiantheblind
# the headlines are formated to point to github raw files
# TODO:
# make a interface to add raw links right now it points to a fixed location
# should maybe be a python script
usage="$(basename "$0") [-h] [-p path] -- program to create TOC (table of contents) of a folder
where:
-h show this help text
-n number of lines to fetch from files
-p path to github repository for direct links to raw file e.g.
https://raw.github.com/fabiantheblind/auto-typo-adbe-id/master/fabiantheblind/"
path=
numlines=7
while getopts :h:p:n: option
do
case "$option" in
h) echo "$usage"
exit
;;
p) path=$OPTARG
;;
n) numlines=$OPTARG
;;
:) printf "missing argument for -%p\n" "$OPTARG" >&2
echo "$usage" >&2
exit 1
;;
\?) printf "illegal option: -%p\n" "$OPTARG" >&2
echo "$usage" >&2
exit 1
;;
esac
done
if [ $# -eq 0 ]
then
echo "No arguments supplied"
echo "$usage" >&2
exit 1
fi
if [ -e "TOC.md" ]; then
echo "\"TOC.md\" already exists. I will remove it"
rm TOC.md
fi
numfiles=(*)
numfiles=${#numfiles[@]}
echo "There are $numfiles .jsx / .txt / .sh files in this directory"
#echo ls -l | grep -c "^-.*"
echo "##Autogenerated TOC " >> TOC.md;
for file in *.{jsx,json,txt,sh}; do
if [ -e "$file" ]; then
echo "###[${file}]($path${file}) " >> TOC.md;
#echo " \n" >> TOC.md;
head -$numlines "${file}" >> TOC.md;
echo "" >> TOC.md;
echo "-------------- " >> TOC.md;
echo "" >> TOC.md;
fi
done
open TOC.md