#!/usr/bin/env dash # shellcheck source=/dev/null SHELL_LIBRARY_VERSION="1.4.2" . %SHELL_LIBRARY_PATH # these are used in version() AUTHORS="Soispha" YEARS="2023" NAME="neorg" help() { cat << EOF This is a quick wrapper to make starting neorg easier. Usage: $NAME [--help|--version] 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 The neorg workspace to open at startup, an empty value drops you at a prompt to enter the workspace yourself EOF } open_neorg_workspace() { nvim -c "NeorgStart" -s "$(ptmp ":Neorg workspace $1\n")" } 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 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 # 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";) else dbg "No context active"; open_neorg_workspace_prompt; fi } for arg in "$@"; do case "$arg" in "--help" | "-h") help; exit 0; ;; "--version" | "-v") version; exit 0; ;; esac done while [ "$#" -ne 0 ]; do case "$1" in "--task" | "-t") open_current_task_context; exit 0; ;; *) open_neorg_workspace "$1"; exit 0; ;; esac shift 1 done open_neorg_workspace_prompt; # vim: ft=sh