From b26818dad13db472b20e299d96d0fb124417a5e6 Mon Sep 17 00:00:00 2001 From: Stepanov Aleksey Date: Sun, 11 May 2025 14:12:21 +0500 Subject: add taskwarrior-tui-scripts project --- lib/edit.sh | 107 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100755 lib/edit.sh (limited to 'lib/edit.sh') 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 + 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 +} -- cgit