-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtw2md.sh
More file actions
44 lines (37 loc) · 1.41 KB
/
tw2md.sh
File metadata and controls
44 lines (37 loc) · 1.41 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
# Set IFS to handle spaces in task descriptions and tags
IFS=$(printf '\n\t')
# Check if argument is provided, otherwise use default "next"
if [ $# -eq 0 ]; then
# beware here export next is separated with a new line on purpose
export_arg='limit:3
export
next'
else
export_arg="$*"
fi
# Export all next tasks as JSON and store in variable
tasks=$(task $export_arg | jq -c '.')
# Print table headers
echo "| Project | Description | Due Date | Tags |"
echo "| ------- | ------------------------------------------------------- | ---------- | -------- |"
# Loop through all tasks and print them in a Markdown table
for task in $(echo "$tasks" | jq -c '.[]'); do
description=$(echo "$task" | jq -r '.description')
project=$(echo "$task" | jq -r '.project')
due=$(echo "$task" | jq -r '.due')
tags=$(echo "$task" | jq -r '.tags')
if [[ "$tags" == "null" ]]; then
tags="None"
else
tags=$(echo "$task" | jq -r '.tags | map("#" + gsub("\"";"")) | join(", ")')
fi
# Convert due date to human-readable format
if [[ -n "$due" && "$due" != "null" ]]; then
timestamp=$(date -j -f "%Y%m%dT%H%M%SZ" "$due" '+%Y-%m-%d')
due="$timestamp"
else
due="No date"
fi
# Print task details as a table row
printf "| %-8s | - [ ] %-50s | %-10s | %-8s |\n" "$project" "$description" "$due" "$tags"
done