-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtask-add.sh
More file actions
37 lines (30 loc) · 1018 Bytes
/
task-add.sh
File metadata and controls
37 lines (30 loc) · 1018 Bytes
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
#!/usr/bin/env bash
# Add the current dir as an annotation to a new task
# Exit immediately if a command exits with a non-zero status.
set -e
# Prints an error message to stderr and exits.
#
# @param $1 - The error message to print.
function error_exit() {
echo "ERROR: $1" >&2
exit 1
}
function main() {
# Verify that the 'task' command is available.
if ! command -v task &>/dev/null; then
error_exit "The 'task' command could not be found. Please ensure Taskwarrior is installed and in your PATH."
fi
# Verify that a task description has been provided.
if [[ $# -eq 0 ]]; then
error_exit "You must provide a description for the task.
Usage: task-add <your task description>"
fi
# Add the task and capture the output to get the ID.
task add +dir "$@"
local new_id
new_id=$(task +LATEST ids)
# Add the current directory path ($PWD) as an annotation to the new task.
task "$new_id" annotate "$PWD"
echo "Successfully annotated task $new_id with directory: $PWD"
}
main "$@"