about summary refs log tree commit diff stats
path: root/pkgs/by-name/ne/neorg/functions/add.sh
blob: 5a830a103442283c73df5286e01bc4df65e19f24 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#!/usr/bin/env dash

add0open_taskwarrior_project_file() {
    task_project_file="%TASK_PROJECT_FILE"

    cd "$(dirname $task_project_file)" || die "BUG: task_project_file ('$task_project_file') can't be accessed"

    git_dir="$(search_flake_base_dir)"
    [ "$git_dir" ] || die "(BUG): No git directory?"
    cd "$git_dir" || die "Unreachable, this MUST exists"

    nvim "$task_project_file"
    git add "$task_project_file"

    base_task_project_file_path="$(awk "{ gsub(\"$git_dir/\", \"\", \$0); print }" "$(ptmp "$task_project_file")")"
    git add $task_project_file

    # Check that only the project file has been added (and that our file is actually
    # modified)
    if git status --porcelain=v2 | awk -v path="$base_task_project_file_path" 'BEGIN { hit = 0 } { if ($2 ~ /A./ || $2 ~ /M./) { if ($NF ~ path) { hit = 1 } else { hit = 0; exit 1 } } } END { if (hit == 1) { exit 0 } else { exit 1 } }'; then
        git commit --verbose --message="chore($(dirname "$base_task_project_file_path")): Update"
    fi
}