diff options
author | Soispha <soispha@vhack.eu> | 2023-10-19 10:10:52 +0200 |
---|---|---|
committer | Soispha <soispha@vhack.eu> | 2023-10-19 10:10:52 +0200 |
commit | e2d84ece390a531940b9b6484711d9899a8d074a (patch) | |
tree | 161e4cc310b719688f98646c53e2dfb66484932a | |
parent | feat(hm/conf/taskwarrior): Automatically save the task data in a git repo (diff) | |
download | nixos-config-e2d84ece390a531940b9b6484711d9899a8d074a.tar.gz nixos-config-e2d84ece390a531940b9b6484711d9899a8d074a.zip |
feat(hm/pkgs/scr/neorg): Support task specific heads in norg files
Diffstat (limited to '')
-rwxr-xr-x | hm/soispha/pkgs/scripts/wrappers/neorg | 80 |
1 files changed, 63 insertions, 17 deletions
diff --git a/hm/soispha/pkgs/scripts/wrappers/neorg b/hm/soispha/pkgs/scripts/wrappers/neorg index 2bdb82cf..ce45cc44 100755 --- a/hm/soispha/pkgs/scripts/wrappers/neorg +++ b/hm/soispha/pkgs/scripts/wrappers/neorg @@ -14,21 +14,42 @@ cat << EOF This is a quick wrapper to make starting neorg easier. Usage: - $NAME [--help|--version] <neorg workspace> + $NAME [--help|--version] [<neorg workspace>] Options: --help | -h Display this help and exit. --version | -v Display version and copyright information and exit. - --task | -t - Open the neorg project associated with the current context. - If no context is set, drop to the selection prompt + --task ID | -t ID + Open the neorg project associated with the current context and + the uuid of the task with id ID. + If no context is set, drops you to the selection prompt <neorg workspace> The neorg workspace to open at startup, an empty value drops - you at a prompt to enter the workspace yourself + you at a prompt to enter the workspace yourself. + If unset (and no other options apply), opens the current task + context. EOF } +get_current_context() { + current_context="$(task _get rc.context)"; + printf "%s\n" "$current_context"; +} +get_current_context_path() { + current_context="$1"; + context_path="$(task _get rc.context."$current_context".rc.neorg_path 2>/dev/null)"; + if ! [ "$context_path" ]; then + context_path="$(grep "context.$current_context.rc.neorg_path" "%HOME_TASKRC" | awk 'BEGIN {FS="="} {print $2}')"; + [ "$context_path" ] || die "All contexts should have a 'neorg_path' set!" + fi + printf "%s\n" "$context_path" +} +get_neorg_project_dir() { + # Perform shell expansion of Tilde + neorg_project_dir="$(sed "s|~|$HOME|" "$(ptmp "%DEFAULT_NEORG_PROJECT_DIR")")"; + printf "%s\n" "$neorg_project_dir" +} open_neorg_workspace() { nvim -c "NeorgStart" -s "$(ptmp ":Neorg workspace $1\n")" @@ -37,19 +58,42 @@ open_neorg_workspace_prompt() { nvim -c "NeorgStart" -s "$(ptmp ":Neorg workspace ")" } open_current_task_context() { - current_context="$(task _get rc.context)"; + current_context="$(get_current_context)" if [ "$current_context" ]; then - context_path="$(task _get rc.context."$current_context".rc.neorg_path 2>/dev/null)"; - if ! [ "$context_path" ]; then - context_path="$(grep "context.$current_context.rc.neorg_path" "%HOME_TASKRC" | awk 'BEGIN {FS="="} {print $2}')"; - [ "$context_path" ] || die "All contexts should have a 'neorg_path' set!" + context_path="$(get_current_context_path "$current_context")"; + + extended_neorg_project_dir="$(get_neorg_project_dir)"; + cd "$extended_neorg_project_dir" || die "(BUG?): Can not access the project dir: $extended_neorg_project_dir"; + + nvim "$extended_neorg_project_dir/$context_path"; + + git add .; + git commit --message="chore($(dirname "$context_path")): Update" --no-gpg-sign + else + warn "No context active"; + open_neorg_workspace_prompt; + fi +} +open_current_task_context_at_task_id() { + task_id="$1"; + current_context="$(get_current_context)" + if [ "$current_context" ]; then + context_path="$(get_current_context_path "$current_context")"; + extended_neorg_project_dir="$(get_neorg_project_dir)"; + task_uuid="$(task "$task_id" uuids)" + + cd "$extended_neorg_project_dir" || die "(BUG?): Can not access the project dir: $extended_neorg_project_dir"; + + if ! grep -q "% $task_uuid" "$extended_neorg_project_dir/$context_path"; then + echo "* TITLE (% $task_uuid)" >> "$extended_neorg_project_dir/$context_path" fi - # Perform shell expansion of Tilde - extended_neorg_project_dir="$(sed "s|~|$HOME|" "$(ptmp "%DEFAULT_NEORG_PROJECT_DIR")")"; - (cd "$extended_neorg_project_dir" && nvim +edit "$extended_neorg_project_dir/$context_path";) + nvim "$extended_neorg_project_dir/$context_path" --cmd "/% $task_uuid"; + + git add .; + git commit --message="chore($(dirname "$context_path")): Update" --no-gpg-sign else - dbg "No context active"; + warn "No context active"; open_neorg_workspace_prompt; fi } @@ -70,7 +114,10 @@ done while [ "$#" -ne 0 ]; do case "$1" in "--task" | "-t") - open_current_task_context; + shift 1; + task_id="$1"; + [ "$task_id" ] || die "You must have a task_id set! See --help for more" + open_current_task_context_at_task_id "$task_id"; exit 0; ;; *) @@ -78,9 +125,8 @@ while [ "$#" -ne 0 ]; do exit 0; ;; esac - shift 1 done -open_neorg_workspace_prompt; +open_current_task_context; # vim: ft=sh |