about summary refs log tree commit diff stats
path: root/hm/soispha/pkgs/scripts/wrappers/neorg
diff options
context:
space:
mode:
Diffstat (limited to '')
-rwxr-xr-xhm/soispha/pkgs/scripts/wrappers/neorg58
1 files changed, 36 insertions, 22 deletions
diff --git a/hm/soispha/pkgs/scripts/wrappers/neorg b/hm/soispha/pkgs/scripts/wrappers/neorg
index ecd830e8..4d35ea32 100755
--- a/hm/soispha/pkgs/scripts/wrappers/neorg
+++ b/hm/soispha/pkgs/scripts/wrappers/neorg
@@ -6,7 +6,6 @@ SHELL_LIBRARY_VERSION="1.4.2" . %SHELL_LIBRARY_PATH
 # these are used in version()
 AUTHORS="Soispha"
 YEARS="2023"
-VERSION="1.0.0"
 
 NAME="neorg"
 
@@ -18,51 +17,66 @@ Usage:
     $NAME [--help|--version] <neorg workspace>
 
 Options:
-    --help   | -h
+    --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
     <neorg workspace>
                             The neorg workspace to open at startup, an empty value drops
                             you at a prompt to enter the workspace yourself
 EOF
 }
 
-run_with_workspace() {
+open_neorg_workspace() {
     nvim -c "NeorgStart" -s "$(ptmp ":Neorg workspace $1\n")"
 }
-run_without_workspace() {
+open_neorg_workspace_prompt() {
     nvim -c "NeorgStart" -s "$(ptmp ":Neorg workspace ")"
 }
+open_current_task_context() {
+    current_context="$(task _get rc.context)";
+    if [ "$current_context" ]; then
+        context_path="$(task _get rc.context."$current_context".rc.neorg_path)";
+        [ "$context_path" ] || die "All contexts should have a 'neorg_path' set!"
 
-neorg_workspace="";
-run=true;
+        # Perform shell expansion of Tilde
+        nvim "$(sed "s|~|$HOME|" "$(ptmp "%DEFAULT_NEORG_PROJECT_DIR/$context_path")")";
+    else
+        dbg "No context active";
+        open_neorg_workspace_prompt;
+    fi
+}
 
-while [ "$#" -ne 0 ]; do
-    case "$1" in
+for arg in "$@"; do
+    case "$arg" in
         "--help" | "-h")
-            if [ "$run" = true ]; then
-                help
-            fi
-            run=false;
+            help;
+            exit 0;
             ;;
         "--version" | "-v")
-            if [ "$run" = true ]; then
-                version
-            fi
-            run=false;
+            version;
+            exit 0;
+            ;;
+    esac
+done
+
+while [ "$#" -ne 0 ]; do
+    case "$1" in
+        "--task" | "-t")
+            open_current_task_context;
+            exit 0;
             ;;
         *)
-            neorg_workspace="$1";
+            open_neorg_workspace "$1";
+            exit 0;
             ;;
     esac
     shift 1
 done
 
-if [ "$neorg_workspace" ] && [ "$run" = true ];then
-    run_with_workspace "$neorg_workspace";
-elif [ "$run" = true ]; then
-    run_without_workspace
-fi
+open_neorg_workspace_prompt;
 
 # vim: ft=sh