-
Notifications
You must be signed in to change notification settings - Fork 0
/
view.sh
141 lines (134 loc) · 4.19 KB
/
view.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# note viewing
list()
{
case "$#" in
0)
if ! tree -D "${DIRECTORY}" -P "*.${EXTENSION}" 2>/dev/null; then
ls -l "${DIRECTORY}/*.${EXTENSION}"
fi
;;
1)
if [[ "$1" = "help" || "$1" = "usage" ]]; then
_usage "note list"
echo "Lists contents of the notes directory"
else
error "too many arguments for note list"
list help
fi
;;
*)
error "too many arguments for note list"
list help
;;
esac
}
info()
{
case "$#" in
0)
error "too few arguments for note info"
info help
;;
1)
name=$( basename "$1" ".${EXTENSION}" )
if [[ "$1" = "help" || "$1" = "usage" ]]; then
_usage "note info <name of note>"
echo "Prints the metadata of an existing note"
elif [ ! -f "${DIRECTORY}/${name}.${EXTENSION}" ]; then
error "$name.${EXTENSION} does not exist!"
else
echo "Name: ${name}.${EXTENSION}"
echo "Last change: $(stat -c %z "${DIRECTORY}/${name}.${EXTENSION}")"
echo "Git history:"
PWD=$(pwd)
cd "${DIRECTORY}" || exit 1
git log -p -- "${name}.${EXTENSION}"
cd "${PWD}" || exit 1
fi
;;
*)
error "too many arguments for note info"
info help
;;
esac
}
show()
{
case "$#" in
0)
error "too few arguments for note show"
show help
;;
1)
name=$( basename "$1" ".${EXTENSION}" )
if [[ "$1" = "help" || "$1" = "usage" ]]; then
_usage "note show <name of note>"
echo "Prints an existing note to stdout"
elif [ ! -f "${DIRECTORY}/${name}.${EXTENSION}" ]; then
error "${name}.${EXTENSION} does not exist!"
read -rp "Would you like to create it now? (Y/n)" choice
case "${choice}" in
(n*|N*)
echo "Aborting..."
;;
*)
add "${name}"
;;
esac
else
cat "${DIRECTORY}/${name}.${EXTENSION}"
fi
;;
*)
error "too many arguments for note show"
show help
;;
esac
}
open()
{
case "$#" in
0)
error "too few arguments for note open"
open help
;;
1)
if [[ "$1" = "help" || "$1" = "usage" ]]; then
_usage "note open <name of note> [html|pdf]"
echo "Opens the note in the specified format (html by default)"
else
open "$1" html
fi
;;
2)
name=$( basename "$1" ".${EXTENSION}" )
if [ ! -f "${DIRECTORY}/${name}.${EXTENSION}" ]; then
error "${name}.${EXTENSION} does not exist!"
read -rp "Would you like to create it now? (Y/n)" choice
case "${choice}" in
(n*|N*)
echo "Aborting..."
;;
*)
add "${name}"
;;
esac
else
case "$2" in
html)
# Couple to vimwiki and use the pandoc conversion script to create the HTML file.
wiki2html_pandoc 1 "markdown" "${EXTENSION}" "${OUTPUT_DIR}" "${DIRECTORY}/${name}.${EXTENSION}" "${OUTPUT_DIR}/${CSS_FILE}" "-" "-" "-"
;;
*)
pandoc "${DIRECTORY}/${name}.${EXTENSION}" -s -o "${DIRECTORY}/${name}.$2"
;;
esac
xdg-open "${DIRECTORY}/${name}.$2"
fi
;;
*)
error "too many arguments for note open"
open help
;;
esac
}