-
Notifications
You must be signed in to change notification settings - Fork 5
/
notes
executable file
·79 lines (66 loc) · 1.71 KB
/
notes
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
#!/usr/bin/env bash
set -euo pipefail
IFS=$'\n\t'
__usage="
Usage: notes [--help | -h | -?] <command> [<args>]
Subcommands:
new Create a new note with your EDITOR
list List all found notes
todos List todo items from all of your notes
find Find notes with matching title
search Search notes for text
Options:
-h, -?, --help Output usage for notes or a subcommand
"
if [[ $# -lt 1 ]]; then
echo "$__usage" >&2
exit 1
fi
PARAMS=()
SUBCOMMAND=0
while (( "$#" )); do
case "$1" in
-h|-'?'|--help)
echo "$__usage"
exit 0
;;
--*=|-*) # unsupported options
if [[ $SUBCOMMAND -eq 1 ]]; then
PARAMS+=( "$1" )
shift
else
echo "Error: Unsupported option \"$1\"" >&2
echo "$__usage" >&2
exit 1
fi
;;
new|news|list|todos|find|search) # preserve positional arguments
PARAMS+=( "$1" )
shift
SUBCOMMAND=1
;;
*) # reject unsupported subcommands
if [[ $SUBCOMMAND -eq 1 ]]; then
PARAMS+=( "$1" )
shift
else
echo "Error: Unsupported command \"$1\"" >&2
echo "$__usage" >&2
exit 1
fi
;;
esac
done
# set positional arguments in their proper place
set -- "${PARAMS[@]}"
binary="notes-$1"
set +e
binary_path=$(which "$binary")
set -e
if [ -z "$binary_path" ]; then
echo "Error: Binary \"$binary\" not found" >&2
echo "$__usage" >&2
exit 1
fi
shift
$binary_path "$@"