aboutsummaryrefslogtreecommitdiff
path: root/lib/edit.sh
diff options
context:
space:
mode:
authorLibravatar Stepanov Aleksey <blueingreen@bluig.xyz>2025-05-11 14:12:21 +0500
committerLibravatar Stepanov Aleksey <blueingreen@bluig.xyz>2025-05-11 14:12:21 +0500
commitb26818dad13db472b20e299d96d0fb124417a5e6 (patch)
treecaf27ea27c321cbe4a8ce0be25c4cc37d3933dfd /lib/edit.sh
add taskwarrior-tui-scripts project
Diffstat (limited to 'lib/edit.sh')
-rwxr-xr-xlib/edit.sh107
1 files changed, 107 insertions, 0 deletions
diff --git a/lib/edit.sh b/lib/edit.sh
new file mode 100755
index 0000000..be271aa
--- /dev/null
+++ b/lib/edit.sh
@@ -0,0 +1,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
+}