diff options
author | Soispha <soispha@vhack.eu> | 2023-10-20 21:48:43 +0200 |
---|---|---|
committer | Soispha <soispha@vhack.eu> | 2023-10-20 21:48:43 +0200 |
commit | ba9fa34a7ee5a4707562245545e809d74e85fe05 (patch) | |
tree | e28bb89dd36dcd2c2ef5a795e658a1b600da0f77 /hm/soispha/pkgs/scripts/wrappers/neorg | |
parent | refactor(hm/conf/taskwarrior/projects): Store the parsed projects in a attr (diff) | |
download | nixos-config-ba9fa34a7ee5a4707562245545e809d74e85fe05.tar.gz nixos-config-ba9fa34a7ee5a4707562245545e809d74e85fe05.zip |
feat(hm/pkgs/scr/neorg): Add support for Firefox context specific profiles
Diffstat (limited to '')
-rwxr-xr-x | hm/soispha/pkgs/scripts/wrappers/neorg | 140 |
1 files changed, 110 insertions, 30 deletions
diff --git a/hm/soispha/pkgs/scripts/wrappers/neorg b/hm/soispha/pkgs/scripts/wrappers/neorg index c7e08c15..f26faac4 100755 --- a/hm/soispha/pkgs/scripts/wrappers/neorg +++ b/hm/soispha/pkgs/scripts/wrappers/neorg @@ -9,34 +9,49 @@ YEARS="2023" NAME="neorg" +set -ef + help() { cat << EOF This is a quick wrapper to make starting neorg easier. Usage: - $NAME [--help|--version] [<neorg workspace>] + $NAME [OPTIONS] [COMMAND] -Options: +OPTIONS: --help | -h Display this help and exit. --version | -v Display version and copyright information and exit. - --task ID | -t ID - Open the neorg project associated with the current context and - the uuid of the task with id ID. +COMMANDS: + task [ID] + Open the neorg context associated with the current context and + the uuid of the task with id ID. Without ID, it'll open the + current context's norg file. If no context is set, drops you to the selection prompt - <neorg workspace> - The neorg workspace to open at startup, an empty value drops + + workspace [WS] + The neorg workspace (WS) to open at startup, an empty value drops you at a prompt to enter the workspace yourself. - If unset (and no other options apply), opens the current task - context. + + project [P] + Opens the webbrowser with either the context (P) or + the current active context as argument if no context is supplied + + list + Lists all available contexts + + add + Allows you to quickly add projects + EOF } -get_current_context() { +# Utils {{{ +UTILS_get_current_context() { current_context="$(task _get rc.context)"; printf "%s\n" "$current_context"; } -get_current_context_path() { +UTILS_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 @@ -45,24 +60,28 @@ get_current_context_path() { fi printf "%s\n" "$context_path" } -get_neorg_project_dir() { +UTILS_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() { +# Workspace {{{ +WORKSPACE_open_neorg_workspace() { nvim -c "NeorgStart" -s "$(ptmp ":Neorg workspace $1\n")" } -open_neorg_workspace_prompt() { +WORKSPACE_open_neorg_workspace_prompt() { nvim -c "NeorgStart" -s "$(ptmp ":Neorg workspace ")" } -open_current_task_context() { - current_context="$(get_current_context)" +# }}} +# Context {{{ +CONTEXT_open_current_task_context() { + current_context="$(UTILS_get_current_context)" if [ "$current_context" ]; then - context_path="$(get_current_context_path "$current_context")"; + context_path="$(UTILS_get_current_context_path "$current_context")"; - extended_neorg_project_dir="$(get_neorg_project_dir)"; + extended_neorg_project_dir="$(UTILS_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"; @@ -71,15 +90,15 @@ open_current_task_context() { git commit --message="chore($(dirname "$context_path")): Update" --no-gpg-sign else warn "No context active"; - open_neorg_workspace_prompt; + WORKSPACE_open_neorg_workspace_prompt; fi } -open_current_task_context_at_task_id() { +CONTEXT_open_current_task_context_at_task_id() { task_id="$1"; - current_context="$(get_current_context)" + current_context="$(UTILS_get_current_context)" if [ "$current_context" ]; then - context_path="$(get_current_context_path "$current_context")"; - extended_neorg_project_dir="$(get_neorg_project_dir)"; + context_path="$(UTILS_get_current_context_path "$current_context")"; + extended_neorg_project_dir="$(UTILS_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"; @@ -94,9 +113,45 @@ open_current_task_context_at_task_id() { git commit --message="chore($(dirname "$context_path")): Update" --no-gpg-sign else warn "No context active"; - open_neorg_workspace_prompt; + WORKSPACE_open_neorg_workspace_prompt; fi } +# }}} +# Project {{{ +PROJECT_open_current_context_in_browser() { + current_context="$(UTILS_get_current_context)"; + [ "$current_context" ] || WORKSPACE_open_neorg_workspace_prompt; + PROJECT_open_context_in_browser "$current_context"; +} +PROJECT_open_context_in_browser() { + context="$1"; + [ "$context" ] || die "BUG: No context supplied to PROJECT_open_context_in_browser" + + firefox -P "$context" +} +# }}} +# List {{{ +LIST_list_all_contexts_newline() { + print "%ALL_PROJECTS_NEWLINE" +} +LIST_list_all_contexts_comma() { + print "%ALL_PROJECTS_COMMA" +} +# }}} +# Add {{{ +ADD_open_taskwarrior_project_file() { + task_project_file="%TASK_PROJECT_FILE"; + cd "$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/\", \"\") }" "$(ptmp "$task_project_file")")" + git commit --verbose --message="chore($(dirname "$base_task_project_file_path")): Update" +} +# }}} for arg in "$@"; do case "$arg" in @@ -113,20 +168,45 @@ done while [ "$#" -ne 0 ]; do case "$1" in - "--task" | "-t") + "t"*) # task 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"; + [ "$task_id" ] || CONTEXT_open_current_task_context; + CONTEXT_open_current_task_context_at_task_id "$task_id"; + exit 0; + ;; + "w"*) # workspace + shift 1; + workspace_to_open="$1"; + [ "$workspace_to_open" ] || WORKSPACE_open_neorg_workspace_prompt; + WORKSPACE_open_neorg_workspace "$workspace_to_open"; + exit 0; + ;; + "p"*) # project + shift 1; + context_to_open="$1"; + [ "$context_to_open" ] || PROJECT_open_current_context_in_browser; + if ! grep -q "$context_to_open" "$(ptmp "%ALL_PROJECTS_NEWLINE")"; then + die "Your context ('$context_to_open') is not in the list of available contexts: + %ALL_PROJECTS_COMMA"; + fi + PROJECT_open_context_in_browser "$context_to_open"; exit 0; ;; + "l"*) # list + LIST_list_all_contexts_newline; + exit 0 + ;; + "a"*) # add-project + ADD_open_taskwarrior_project_file; + exit 0 + ;; *) - open_neorg_workspace "$1"; + die "Command '$1' does not exist! Please look at:\n $NAME --help"; exit 0; ;; esac done -open_current_task_context; - +CONTEXT_open_current_task_context; # vim: ft=sh |