aboutsummaryrefslogtreecommitdiff
path: root/lib/project.sh
blob: 03e322f0a911f1b080788ef7e4fc11086da216bf (plain)
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
#!/usr/bin/env bash

#****F* lib/project.sh
# NAME
#
# project.sh - bash-скрипт для создания проекта в taskwarrior-tui.
#******

function getProjName() {
	task _get "$1".description
}

function getExitCriteria() {
	task _get "$1".annotations.1.description
}

function taskCheck() {
	local task

	task="$1"
	annotationCount=$(getAnnotationCount "$task")

	case "$annotationCount" in
	0)
		notify "msg-error" "Нет критерия завершения, выход..."

		return 1
		;;
	1)
		notify "msg-error" "Нет первого шага у проекта, выход..."

		return 1
		;;
	*)
		checkExistingProject "$task"
		hasProject "$task"

		return 0
		;;
	esac
}

function taskProj() {
	local task
	local projName
	local exitCriteria
	local idTask
	local tags

	task="$1"
	tags=$(getTags "$1")
	projName=$(getProjName "$1")
	exitCriteria=$(getExitCriteria "$1")

	readarray -t annotations < <(task "$1" export | jq -r '.[] | .annotations[1:] | .[].description')

	if [[ "$tags" =~ "someday" ]]; then
		task "$task" modify priority: -someday
	fi

	task "$task" modify project:"$projName" description:"$exitCriteria"

	denotateAllAnnotations "$task"

	for taskIndex in "${!annotations[@]}"; do
		if [[ "$taskIndex" -eq 0 ]]; then
			task add "${annotations[$taskIndex]}" project:"$projName" order:"$((taskIndex + 2))"

			idTask=$(getLatestTaskId)

			continue
		fi

		task add "${annotations[$taskIndex]}" project:"$projName" order:"$((taskIndex + 2))" depends:"$idTask"

		idTask=$(getLatestTaskId)
	done
}