blob: be271aa2f9d1153300b627454a99819273bd7480 (
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
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
|
#!/usr/bin/env bash
#****F* lib/global.sh
# NAME
#
# global.sh - общие функции для всех скриптов.
#
# USES
#
# - environment.sh
#******
function getIdsTask() {
local nameProject
nameProject=$(getNameProject "$1")
readarray -t idsTaskProject < <(task project:"$nameProject" +current _ids)
printf '%s\n' "${idsTaskProject[@]}"
}
function getFileHash() {
sha256sum "$1" | awk '{print $1}'
}
function checkFilesHash() {
local originalHash
local currentHash
originalHash=$(getFileHash "/tmp/tskw.edit.bak")
currentHash=$(getFileHash "/tmp/tskw.edit")
if [[ "$originalHash" != "$currentHash" ]]; then
readarray -t taskStages < <(grep -v "^#" </tmp/tskw.edit)
else
notify "msg-gray" "Этапы проекта не были изменены. Выход..."
exit 0
fi
}
function backupStages() {
cp /tmp/tskw.edit /tmp/tskw.edit.bak
}
function editStages() {
nvim /tmp/tskw.edit &
wait
}
function editStageProject() {
local idsTaskProject
idsTaskProject=$(getIdsTask "$1")
if [[ -f /tmp/tskw.edit ]]; then
: >/tmp/tskw.edit
fi
if [[ "${#tasksProject[@]}" -eq 0 ]]; then
echo "# Проект без этапов. Эта строка будет проигнорирована." >>/tmp/tskw.edit
backupStages
editStages
checkFilesHash
return 0
fi
for taskID in "${tasksProject[@]}"; do
local uuid
uuid=$(task _get "$taskID".uuid)
task _get "$uuid".description >>/tmp/tskw.edit
done
backupStages
editStages
checkFilesHash
}
function deleteProject() {
local idsTaskProject
local nameProject
idsTaskProject=$(getIdsTask "$1")
nameProject=$(getNameProject "$1")
if [[ "${#idsTaskProject[@]}" -eq 0 ]]; then
return
else
task rc.bulk=0 rc.confirmation=off project:"$nameProject" -COMPLETED -DELETED +current delete
fi
}
function recreateProject() {
for taskIndex in "${!taskStages[@]}"; do
if [[ "$taskIndex" -eq 0 ]]; then
task add "${taskStages[$taskIndex]}" project:"$nameProject" order:$(("$taskIndex" + 2 - 1)) +current
else
task add "${taskStages[$taskIndex]}" project:"$nameProject" depends:"$uuidNewTask" order:$(("$taskIndex" + 2 - 1)) +current
fi
local uuidNewTask
uuidNewTask=$(getLatestTaskUuid)
done
}
|