-
Notifications
You must be signed in to change notification settings - Fork 0
/
onenote
executable file
·151 lines (134 loc) · 3.73 KB
/
onenote
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
140
141
142
143
144
145
146
147
148
149
150
151
#!/usr/bin/env bash
TASK_VERSION_NO_NEWLINE="2.5.2"
task_number=${1}
consume_input=${2}
progname=$(basename ${0})
newline="\n"
linefeed=$'\n'
consume_arg="-"
output=""
default_pipe_editor="vipe"
pipe_editor=${ONENOTE_PIPE_EDITOR:-${default_pipe_editor}}
vercomp () {
if [[ $1 == $2 ]]
then
return 0
fi
local IFS=.
local i ver1=($1) ver2=($2)
# fill empty fields in ver1 with zeros
for ((i=${#ver1[@]}; i<${#ver2[@]}; i++))
do
ver1[i]=0
done
for ((i=0; i<${#ver1[@]}; i++))
do
if [[ -z ${ver2[i]} ]]
then
# fill empty fields in ver2 with zeros
ver2[i]=0
fi
if ((10#${ver1[i]} > 10#${ver2[i]}))
then
return 1
fi
if ((10#${ver1[i]} < 10#${ver2[i]}))
then
return 2
fi
done
return 0
}
vercomp $(task --version) ${TASK_VERSION_NO_NEWLINE}
vercomp_result=$?
test ${vercomp_result} = 2
legacy_version=$?
if [ $legacy_version -eq 0 ]; then
newline="###NEWLINE###"
fi
usage() {
echo "Usage: ${progname} <task_id>
Edit multiline taskwarrior notes in vi/vim.
Setup a 'notes' UDA for taskwarrior:
task config uda.notes.type string
task config uda.notes.label Notes
Notes can also be piped to standard in:
echo \"foo\" | ${progname} <task_id> -
CAVEATS:
OneNote depends on a pipe editor being installed and in your path. It defaults
to the 'vipe' pipe editor, available on Linux in the 'moreutils' package. To
use a custom pipe editor, set the environment variable 'ONENOTE_PIPE_EDITOR'.
"
if [ $legacy_version -eq 0 ]; then
echo "
Due to a current bug in taskwarrior less than ${TASK_VERSION_NO_NEWLINE} newlines are represented
internally by the marker ${newline}:
https://github.com/GothenburgBitFactory/taskwarrior/issues/2107
"
fi
}
# Override the system task binary and pipe editor in testing env.
if [ -n "${ONENOTE_TEST_HARNESS}" ]; then
task() {
if [ "${1}" = "_get" ]; then
echo "${ONENOTE_TEST_NOTES}"
elif [ "${1}" = "_config" ]; then
if [ -n "${ONENOTE_MISSING_NOTES}" ]; then
echo ""
else
echo "uda.notes.label\nuda.notes.type"
fi
else
local notes="${3}"
# TODO: This also strips out the single quotes added to work around
# https://github.com/GothenburgBitFactory/taskwarrior/issues/2645
# The below line should be used instead if that bug is fixed.
# echo "${notes:6}"
echo "${notes:7:-1}"
fi
}
fi
if [ "$(command -v ${pipe_editor})" = "" ]; then
echo
echo "ERROR: The '${pipe_editor}' binary must be installed and in your path!"
echo
usage
exit 1
fi
if [ $# -lt 1 ] || [ $# -gt 2 ]; then
usage
exit 1
else
if [ $# -eq 2 ]; then
if [ "${2}" != "${consume_arg}" ]; then
usage
exit 1
else
while IFS=$'\n' read -r line; do
if [ -z "${output}" ]; then
output="${line}"
else
output="${output}${linefeed}${line}"
fi
done
# TODO: The extra single quotes are added to work around
# https://github.com/GothenburgBitFactory/taskwarrior/issues/2645
# The below line should be used instead if that bug is fixed.
# task ${task_number} modify notes:"${output}"
task ${task_number} modify notes:"'${output}'"
fi
else
if [ "$(task _config | grep 'uda.notes.type')" = "" ] || [ "$(task _config | grep 'uda.notes.label')" = "" ]; then
usage
exit 1
fi
notes="$(task _get ${task_number}.notes)"
if [ -n "${ONENOTE_DEFAULT_CONTENT}" -a -z "${notes}" ]; then
notes="${ONENOTE_DEFAULT_CONTENT}"
fi
if [ $? -eq 0 ]; then
# The literal line feed is necessary for POSIX compatibility with sed.
echo "${notes}" | sed "s/${newline}/\\$linefeed/g" | ONENOTE_TASK=${task_number} ${pipe_editor} | ${0} ${task_number} ${consume_arg}
fi
fi
fi