-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.sh
executable file
·81 lines (76 loc) · 1.86 KB
/
script.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
#!/bin/bash
# Get information from the user
echo "Path To the Directory : "
read path
echo "Name of save file : "
read file
echo "Heading of the file : "
read heading
# function to read type of list
typeoffun(){
echo -e "Type of list :\n 1. Bulleted\n 2. Ordered"
read listtype
if [ $listtype == "bullet" ] || [ $listtype == "bulleted" ] || [ $listtype == "b" ] || [ $listtype == 1 ]
then
echo "list will be bulleted"
listtype="b"
elif [ $listtype == 'order' ] || [ $listtype == 'ordered' ] || [ $listtype == 'o' ] || [ $listtype == 2 ]
then
echo -e "Sort by : \n 1. Date \n 2. Name \n 3. Size \n 4. Type \n 5. Permissions"
read sortby
if [ $sortby == 1 ]
then
echo "list will be ordered by date"
sortby="-t"
elif [ $sortby == 2 ]
then
echo "list will be ordered by name"
sortby="-k"
elif [ $sortby == 3 ]
then
echo "list will be ordered by size"
sortby="-S"
elif [ $sortby == 4 ]
then
echo "list will be ordered by type"
sortby="-T"
elif [ $sortby == 5 ]
then
echo "list will be ordered by permissions"
sortby="-p"
else
echo "list will be ordered by name"
sortby="-k"
exit
fi
listtype="o"
else
echo -e "list type not recognized \n accepted values are : \n For bulleted list : [bullet, bulleted, b] \n For Ordered List : [order, ordered, o])"
typeoffun
exit
fi
}
#calling function to read list
typeoffun
#saving names of files in .list.csv file
ls $sortby $path >> .list.csv
echo "# $heading " > $file
declare -i x=1
while read line
do
echo -e "\n" >> $file
if [[ $listtype == "b" ]]
then
echo -e "- $line" >> $file
else
echo -e "$x. $line" >> $file
fi
echo -e "\n" >> $file
echo "\`\`\` ${line##*.} " >> $file
cat "$path/$line" >> ./$file
echo -e "\n" >> $file
echo "\`\`\`" >> $file
x=x+1
done < .list.csv
#removing .list.csv file
rm .list.csv