-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdreamnote
More file actions
executable file
·112 lines (102 loc) · 3.85 KB
/
dreamnote
File metadata and controls
executable file
·112 lines (102 loc) · 3.85 KB
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
#!/usr/bin/env bash
###############################################################################
# Script execution options #
###############################################################################
# set -o errexit # exit when a command fails
# set -o pipefail
# set -o nounset # exit when using undeclared variable
# set -o xtrace # verbose
###############################################################################
# Main function #
###############################################################################
# The main function contains variable definition and the getopts loop that
# allow to handle the command line arguments.
function main() {
# find main script directory
SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
SOURCE="$(readlink "$SOURCE")"
[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
done
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
local xdg_config="${XDG_CONFIG_HOME:-$HOME/.config}"
local config_file="${xdg_config}/dreamnote/dreamrc"
local py_stat_dir="${DIR}/lib/stat.py"
local template=http://www.latextemplates.com/templates/books/2/book_2.zip
local current_dir; current_dir=$(pwd)
local tex_contents="contents"
local -A today
today[day]=$(date +"%d")
today[month_number]=$(date +"%m")
today[month_letter]=$(date +"%B")
today[year]=$(date +"%Y")
local regex_date="^[0-9]{4}-(0[1-9]|1[0-2])-([0-2][0-9]|3[0-1])$"
# shellcheck source=lib/functions.sh
source "${DIR}/lib/functions.sh"
if [ -f "$config_file" ]; then
# shellcheck source=dreamrc.template
source "$config_file"
else
echo "No configuration file found !"
exit 1
fi
while getopts ":hi:aA:cs" opt
do
case $opt in
i|init)
initialize "$template" "$tex_contents" "$current_dir" "$config_file" "$OPTARG" "$dn_root"
exit 0
;;
a|add)
dreamnote_missing "$dn_root"
create_part_chapt "${today[day]}" "${today[month_number]}" "${today[month_letter]}" "${today[year]}" "$dn_root" "$tex_contents"
snapshot "$dn_root"
exit 0
;;
A)
dreamnote_missing "$dn_root"
if [[ $OPTARG =~ $regex_date ]]; then
today[day]=$(date -d "$OPTARG" '+%d')
today[month_number]=$(date -d "$OPTARG" '+%m')
today[month_letter]=$(date -d "$OPTARG" '+%B')
today[year]=$(date -d "$OPTARG" '+%Y')
create_part_chapt "${today[day]}" "${today[month_number]}" "${today[month_letter]}" "${today[year]}" "$dn_root" "$tex_contents"
else
echo "Bad date format ! See help for more informations"
fi
snapshot "$dn_root"
exit 0
;;
c|compile)
output_pdf "$dn_root"
exit 0
;;
h|help)
usage
exit 0
;;
s)
dreamnote_missing "$dn_root"
"${venv_root}/bin/python3" "$py_stat_dir" "${dn_root}/${tex_contents}"
exit 0
;;
\?)
echo "Invalid option: -$OPTARG" >&2
exit 1
;;
:)
echo "Option -$OPTARG requires an argument." >&2
exit 1
;;
esac
done
shift $(($OPTIND-1))
}
###############################################################################
# Launch Main #
###############################################################################
main "$@"
# \usepackage[english]{babel} % Replace english by french ?
# voir les usepackage utilisé dans mon autre carnet de rêve.
# ecrire des tests avec bats pour prendre en main bats.