#!/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 }