-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdocuments
93 lines (77 loc) · 1.96 KB
/
documents
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/bash
#
# Manage and create new documents
#
# deprecated
new-doc () {
# Create a document folder if it doesn't exist
if [ ! -d $DOC_PATH ]; then
mkdir $DOC_PATH
fi
if [ -f $DOC_PATH/$1.md ]; then
echo "ERROR. Document already exists. Aborting."
exit 1
fi
# Create new document
touch $DOC_PATH/$1.md
}
open-doc () {
# Check if the document path exists
if [ ! -d $DOC_PATH ]; then
choice=""
while [ $choice != "y" ] && [ $choice != "n" ] ; do
echo "The document path does not exist. Create? (y/n)\n "
read choice
done
# Abort if the user does not want to create the path
if [ "$choice" == "n" ]; then
echo "ERROR. The document path does not exist. Aborting."
exit 1
else
mkdir $DOC_PATH
fi
fi
# Check if the document file exists. If not, query the user
if [ ! -f $DOC_PATH/$1.md ]; then
choice=""
while [ "$choice" != "y" ] && [ "$choice" != "n" ] ; do
echo -ne "The document file does not exist. Create? (y/n): "
read choice
done
# Abort if the user does not want to create a new doc
if [ "$choice" == "n" ]; then
echo "Document NOT created. Aborting."
exit 1
fi
fi
# Edit document
cd $DOC_PATH
vim "$1.md"
}
list-docs () {
# Check if the document path exist
if [ ! -d $DOC_PATH ]; then
echo "ERROR. The document path does not exist. Aborting."
exit 1
fi
# List the documents and their first 3 lines
cd $DOC_PATH
documents=( $(ls *.md) )
for i in ${!documents[*]}; do
echo -ne "> ${documents[$i]}\n${CYAN}$(head -3 ${documents[$i]}) ${NC}\n\n"
done
}
create-sym () {
# Check if the document path exist
if [ ! -d $DOC_PATH ]; then
echo "ERROR. The document path does not exist. Aborting."
exit 1
fi
# Check if the document file exists. If not, query the user
if [ ! -f $DOC_PATH/$1.md ]; then
echo "${RED}ERROR${NC}. The document does not exist! ${ORANGE}Aborting${NC}."
exit 1
fi
# Create a symlink in current directory to document
ln -s "$DOC_PATH/$1.md" "$1"
}