From cc09b607330385d6d81b9c47cf64a2442432e93f Mon Sep 17 00:00:00 2001 From: Soispha Date: Tue, 20 Feb 2024 16:35:15 +0100 Subject: refactor(treewide): Add a `.sh` extension to shell scripts --- .../pkgs/scripts/specific/neorg/sh/functions/add | 23 ------------ .../scripts/specific/neorg/sh/functions/add.sh | 23 ++++++++++++ .../scripts/specific/neorg/sh/functions/context | 43 ---------------------- .../scripts/specific/neorg/sh/functions/context.sh | 43 ++++++++++++++++++++++ .../pkgs/scripts/specific/neorg/sh/functions/dmenu | 12 ------ .../scripts/specific/neorg/sh/functions/dmenu.sh | 12 ++++++ .../scripts/specific/neorg/sh/functions/f_start | 7 ---- .../scripts/specific/neorg/sh/functions/f_start.sh | 7 ++++ .../scripts/specific/neorg/sh/functions/f_stop | 7 ---- .../scripts/specific/neorg/sh/functions/f_stop.sh | 7 ++++ .../pkgs/scripts/specific/neorg/sh/functions/list | 8 ---- .../scripts/specific/neorg/sh/functions/list.sh | 8 ++++ .../scripts/specific/neorg/sh/functions/project | 42 --------------------- .../scripts/specific/neorg/sh/functions/project.sh | 42 +++++++++++++++++++++ .../pkgs/scripts/specific/neorg/sh/functions/utils | 40 -------------------- .../scripts/specific/neorg/sh/functions/utils.sh | 40 ++++++++++++++++++++ .../scripts/specific/neorg/sh/functions/workspace | 9 ----- .../specific/neorg/sh/functions/workspace.sh | 9 +++++ 18 files changed, 191 insertions(+), 191 deletions(-) delete mode 100755 hm/soispha/pkgs/scripts/specific/neorg/sh/functions/add create mode 100755 hm/soispha/pkgs/scripts/specific/neorg/sh/functions/add.sh delete mode 100755 hm/soispha/pkgs/scripts/specific/neorg/sh/functions/context create mode 100755 hm/soispha/pkgs/scripts/specific/neorg/sh/functions/context.sh delete mode 100755 hm/soispha/pkgs/scripts/specific/neorg/sh/functions/dmenu create mode 100755 hm/soispha/pkgs/scripts/specific/neorg/sh/functions/dmenu.sh delete mode 100755 hm/soispha/pkgs/scripts/specific/neorg/sh/functions/f_start create mode 100755 hm/soispha/pkgs/scripts/specific/neorg/sh/functions/f_start.sh delete mode 100755 hm/soispha/pkgs/scripts/specific/neorg/sh/functions/f_stop create mode 100755 hm/soispha/pkgs/scripts/specific/neorg/sh/functions/f_stop.sh delete mode 100755 hm/soispha/pkgs/scripts/specific/neorg/sh/functions/list create mode 100755 hm/soispha/pkgs/scripts/specific/neorg/sh/functions/list.sh delete mode 100755 hm/soispha/pkgs/scripts/specific/neorg/sh/functions/project create mode 100755 hm/soispha/pkgs/scripts/specific/neorg/sh/functions/project.sh delete mode 100755 hm/soispha/pkgs/scripts/specific/neorg/sh/functions/utils create mode 100755 hm/soispha/pkgs/scripts/specific/neorg/sh/functions/utils.sh delete mode 100755 hm/soispha/pkgs/scripts/specific/neorg/sh/functions/workspace create mode 100755 hm/soispha/pkgs/scripts/specific/neorg/sh/functions/workspace.sh (limited to 'hm/soispha/pkgs/scripts/specific/neorg/sh/functions') diff --git a/hm/soispha/pkgs/scripts/specific/neorg/sh/functions/add b/hm/soispha/pkgs/scripts/specific/neorg/sh/functions/add deleted file mode 100755 index bd700775..00000000 --- a/hm/soispha/pkgs/scripts/specific/neorg/sh/functions/add +++ /dev/null @@ -1,23 +0,0 @@ -#!/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 -} diff --git a/hm/soispha/pkgs/scripts/specific/neorg/sh/functions/add.sh b/hm/soispha/pkgs/scripts/specific/neorg/sh/functions/add.sh new file mode 100755 index 00000000..bd700775 --- /dev/null +++ b/hm/soispha/pkgs/scripts/specific/neorg/sh/functions/add.sh @@ -0,0 +1,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 +} diff --git a/hm/soispha/pkgs/scripts/specific/neorg/sh/functions/context b/hm/soispha/pkgs/scripts/specific/neorg/sh/functions/context deleted file mode 100755 index b9ae4463..00000000 --- a/hm/soispha/pkgs/scripts/specific/neorg/sh/functions/context +++ /dev/null @@ -1,43 +0,0 @@ -#!/usr/bin/env dash - -context0open_current_task_context() { - current_context="$(utils0get_current_context)" - - if [ "$current_context" ]; then - context_path="$(utils0get_current_context_path "$current_context")"; - - extended_neorg_project_dir="$(utils0get_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"; - fi -} - -context0open_current_task_context_at_task_id() { - task_id="$1"; - current_context="$(utils0get_current_context)" - - if [ "$current_context" ]; then - context_path="$(utils0get_current_context_path "$current_context")"; - extended_neorg_project_dir="$(utils0get_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 - - nvim "$extended_neorg_project_dir/$context_path" -c "/% $task_uuid"; - - git add .; - git commit --message="chore($(dirname "$context_path")): Update" --no-gpg-sign - else - warn "No context active"; - fi -} diff --git a/hm/soispha/pkgs/scripts/specific/neorg/sh/functions/context.sh b/hm/soispha/pkgs/scripts/specific/neorg/sh/functions/context.sh new file mode 100755 index 00000000..b9ae4463 --- /dev/null +++ b/hm/soispha/pkgs/scripts/specific/neorg/sh/functions/context.sh @@ -0,0 +1,43 @@ +#!/usr/bin/env dash + +context0open_current_task_context() { + current_context="$(utils0get_current_context)" + + if [ "$current_context" ]; then + context_path="$(utils0get_current_context_path "$current_context")"; + + extended_neorg_project_dir="$(utils0get_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"; + fi +} + +context0open_current_task_context_at_task_id() { + task_id="$1"; + current_context="$(utils0get_current_context)" + + if [ "$current_context" ]; then + context_path="$(utils0get_current_context_path "$current_context")"; + extended_neorg_project_dir="$(utils0get_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 + + nvim "$extended_neorg_project_dir/$context_path" -c "/% $task_uuid"; + + git add .; + git commit --message="chore($(dirname "$context_path")): Update" --no-gpg-sign + else + warn "No context active"; + fi +} diff --git a/hm/soispha/pkgs/scripts/specific/neorg/sh/functions/dmenu b/hm/soispha/pkgs/scripts/specific/neorg/sh/functions/dmenu deleted file mode 100755 index 36133004..00000000 --- a/hm/soispha/pkgs/scripts/specific/neorg/sh/functions/dmenu +++ /dev/null @@ -1,12 +0,0 @@ -#!/usr/bin/env dash - -dmenu0open_context_in_browser() { - project="$(echo "%ALL_PROJECTS_PIPE" | rofi -sep "|" -dmenu)"; - - if [ "$project" ]; then - project0open_project_in_browser "$project"; - else - notify-send "(neorg/dmenu) No project selected"; - exit 1 - fi -} diff --git a/hm/soispha/pkgs/scripts/specific/neorg/sh/functions/dmenu.sh b/hm/soispha/pkgs/scripts/specific/neorg/sh/functions/dmenu.sh new file mode 100755 index 00000000..36133004 --- /dev/null +++ b/hm/soispha/pkgs/scripts/specific/neorg/sh/functions/dmenu.sh @@ -0,0 +1,12 @@ +#!/usr/bin/env dash + +dmenu0open_context_in_browser() { + project="$(echo "%ALL_PROJECTS_PIPE" | rofi -sep "|" -dmenu)"; + + if [ "$project" ]; then + project0open_project_in_browser "$project"; + else + notify-send "(neorg/dmenu) No project selected"; + exit 1 + fi +} diff --git a/hm/soispha/pkgs/scripts/specific/neorg/sh/functions/f_start b/hm/soispha/pkgs/scripts/specific/neorg/sh/functions/f_start deleted file mode 100755 index c75986a7..00000000 --- a/hm/soispha/pkgs/scripts/specific/neorg/sh/functions/f_start +++ /dev/null @@ -1,7 +0,0 @@ -#!/usr/bin/env dash - -fstart0start_new_task() { - task_id="$1"; - fstop0stop_current_task; - task start "$task_id" -} diff --git a/hm/soispha/pkgs/scripts/specific/neorg/sh/functions/f_start.sh b/hm/soispha/pkgs/scripts/specific/neorg/sh/functions/f_start.sh new file mode 100755 index 00000000..c75986a7 --- /dev/null +++ b/hm/soispha/pkgs/scripts/specific/neorg/sh/functions/f_start.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env dash + +fstart0start_new_task() { + task_id="$1"; + fstop0stop_current_task; + task start "$task_id" +} diff --git a/hm/soispha/pkgs/scripts/specific/neorg/sh/functions/f_stop b/hm/soispha/pkgs/scripts/specific/neorg/sh/functions/f_stop deleted file mode 100755 index d60cb46f..00000000 --- a/hm/soispha/pkgs/scripts/specific/neorg/sh/functions/f_stop +++ /dev/null @@ -1,7 +0,0 @@ -#!/usr/bin/env dash - -fstop0stop_current_task() { - # we ensured that only one task may be active - active="$(task +ACTIVE _ids)"; - [ "$active" ] && task stop "$active"; -} diff --git a/hm/soispha/pkgs/scripts/specific/neorg/sh/functions/f_stop.sh b/hm/soispha/pkgs/scripts/specific/neorg/sh/functions/f_stop.sh new file mode 100755 index 00000000..d60cb46f --- /dev/null +++ b/hm/soispha/pkgs/scripts/specific/neorg/sh/functions/f_stop.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env dash + +fstop0stop_current_task() { + # we ensured that only one task may be active + active="$(task +ACTIVE _ids)"; + [ "$active" ] && task stop "$active"; +} diff --git a/hm/soispha/pkgs/scripts/specific/neorg/sh/functions/list b/hm/soispha/pkgs/scripts/specific/neorg/sh/functions/list deleted file mode 100755 index 10659457..00000000 --- a/hm/soispha/pkgs/scripts/specific/neorg/sh/functions/list +++ /dev/null @@ -1,8 +0,0 @@ -#!/usr/bin/env dash - -list0list_all_contexts_newline() { - print "%ALL_PROJECTS_NEWLINE" -} -list0list_all_contexts_comma() { - print "%ALL_PROJECTS_COMMA" -} diff --git a/hm/soispha/pkgs/scripts/specific/neorg/sh/functions/list.sh b/hm/soispha/pkgs/scripts/specific/neorg/sh/functions/list.sh new file mode 100755 index 00000000..10659457 --- /dev/null +++ b/hm/soispha/pkgs/scripts/specific/neorg/sh/functions/list.sh @@ -0,0 +1,8 @@ +#!/usr/bin/env dash + +list0list_all_contexts_newline() { + print "%ALL_PROJECTS_NEWLINE" +} +list0list_all_contexts_comma() { + print "%ALL_PROJECTS_COMMA" +} diff --git a/hm/soispha/pkgs/scripts/specific/neorg/sh/functions/project b/hm/soispha/pkgs/scripts/specific/neorg/sh/functions/project deleted file mode 100755 index 8def0930..00000000 --- a/hm/soispha/pkgs/scripts/specific/neorg/sh/functions/project +++ /dev/null @@ -1,42 +0,0 @@ -#!/usr/bin/env dash - -project0open_current_context_in_browser() { - current_context="$(utils0get_current_context)"; - [ "$current_context" ] || die "No current context to use"; - project0open_context_in_browser "$(utils0context2project "$current_context")"; -} - -project0open_project_in_browser() { - project="$1"; - [ "$project" ] || die "BUG: No context supplied to project0open_context_in_browser" - - old_context="$(utils0get_current_context)"; - # We have ensured that only one task may be active - old_started_task="$(task +ACTIVE _ids)"; - - tracking="$(mktmp)"; - task "project:$project" _ids | xargs --no-run-if-empty task _zshids > "$tracking"; - task context "$(utils0project2context "$project")" - - while read -r description; do - desc="$(echo "$description" | awk -F: '{print $2}' )"; - if [ "$desc" = "tracking" ]; then - task_id="$(echo "$description" | awk -F: '{print $1}' )"; - notify-send "(Neorg)" "Starting task $project -> $desc"; - task start "$task_id" - break - fi - done < "$tracking" - - - firefox -P "$project" - - task stop "$task_id" - [ "$old_started_task" ] && task start "$old_started_task" - - if [ "$old_context" ]; then - task context "$old_context" - else - task context none - fi -} diff --git a/hm/soispha/pkgs/scripts/specific/neorg/sh/functions/project.sh b/hm/soispha/pkgs/scripts/specific/neorg/sh/functions/project.sh new file mode 100755 index 00000000..8def0930 --- /dev/null +++ b/hm/soispha/pkgs/scripts/specific/neorg/sh/functions/project.sh @@ -0,0 +1,42 @@ +#!/usr/bin/env dash + +project0open_current_context_in_browser() { + current_context="$(utils0get_current_context)"; + [ "$current_context" ] || die "No current context to use"; + project0open_context_in_browser "$(utils0context2project "$current_context")"; +} + +project0open_project_in_browser() { + project="$1"; + [ "$project" ] || die "BUG: No context supplied to project0open_context_in_browser" + + old_context="$(utils0get_current_context)"; + # We have ensured that only one task may be active + old_started_task="$(task +ACTIVE _ids)"; + + tracking="$(mktmp)"; + task "project:$project" _ids | xargs --no-run-if-empty task _zshids > "$tracking"; + task context "$(utils0project2context "$project")" + + while read -r description; do + desc="$(echo "$description" | awk -F: '{print $2}' )"; + if [ "$desc" = "tracking" ]; then + task_id="$(echo "$description" | awk -F: '{print $1}' )"; + notify-send "(Neorg)" "Starting task $project -> $desc"; + task start "$task_id" + break + fi + done < "$tracking" + + + firefox -P "$project" + + task stop "$task_id" + [ "$old_started_task" ] && task start "$old_started_task" + + if [ "$old_context" ]; then + task context "$old_context" + else + task context none + fi +} diff --git a/hm/soispha/pkgs/scripts/specific/neorg/sh/functions/utils b/hm/soispha/pkgs/scripts/specific/neorg/sh/functions/utils deleted file mode 100755 index 91da811a..00000000 --- a/hm/soispha/pkgs/scripts/specific/neorg/sh/functions/utils +++ /dev/null @@ -1,40 +0,0 @@ -#!/usr/bin/env dash - -# Runs it's first argument and then the second, regardless if the first failed or -# succeeded -utils0chain() { - eval "$1"; eval "$2" -} - -utils0get_current_context() { - current_context="$(task _get rc.context)"; - printf "%s\n" "$current_context"; -} - -utils0get_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" -} - -utils0get_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" -} - - -utils0project2context() { - project="$1"; - context="$(sed 's|\.|_|g' "$(ptmp "$project")")"; - printf "%s\n" "$context"; -} -utils0context2project() { - context="$1"; - project="$(sed 's|_|\.|g' "$(ptmp "$context")")"; - printf "%s\n" "$project"; -} diff --git a/hm/soispha/pkgs/scripts/specific/neorg/sh/functions/utils.sh b/hm/soispha/pkgs/scripts/specific/neorg/sh/functions/utils.sh new file mode 100755 index 00000000..91da811a --- /dev/null +++ b/hm/soispha/pkgs/scripts/specific/neorg/sh/functions/utils.sh @@ -0,0 +1,40 @@ +#!/usr/bin/env dash + +# Runs it's first argument and then the second, regardless if the first failed or +# succeeded +utils0chain() { + eval "$1"; eval "$2" +} + +utils0get_current_context() { + current_context="$(task _get rc.context)"; + printf "%s\n" "$current_context"; +} + +utils0get_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" +} + +utils0get_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" +} + + +utils0project2context() { + project="$1"; + context="$(sed 's|\.|_|g' "$(ptmp "$project")")"; + printf "%s\n" "$context"; +} +utils0context2project() { + context="$1"; + project="$(sed 's|_|\.|g' "$(ptmp "$context")")"; + printf "%s\n" "$project"; +} diff --git a/hm/soispha/pkgs/scripts/specific/neorg/sh/functions/workspace b/hm/soispha/pkgs/scripts/specific/neorg/sh/functions/workspace deleted file mode 100755 index d5eb2fca..00000000 --- a/hm/soispha/pkgs/scripts/specific/neorg/sh/functions/workspace +++ /dev/null @@ -1,9 +0,0 @@ -#!/usr/bin/env dash - -workspace0open_neorg_workspace() { - workspace="$1" - nvim -c "NeorgStart" -s "$(ptmp ":Neorg workspace $workspace\n")" -} -workspace0open_neorg_workspace_prompt() { - nvim -c "NeorgStart" -s "$(ptmp ":Neorg workspace ")" -} diff --git a/hm/soispha/pkgs/scripts/specific/neorg/sh/functions/workspace.sh b/hm/soispha/pkgs/scripts/specific/neorg/sh/functions/workspace.sh new file mode 100755 index 00000000..d5eb2fca --- /dev/null +++ b/hm/soispha/pkgs/scripts/specific/neorg/sh/functions/workspace.sh @@ -0,0 +1,9 @@ +#!/usr/bin/env dash + +workspace0open_neorg_workspace() { + workspace="$1" + nvim -c "NeorgStart" -s "$(ptmp ":Neorg workspace $workspace\n")" +} +workspace0open_neorg_workspace_prompt() { + nvim -c "NeorgStart" -s "$(ptmp ":Neorg workspace ")" +} -- cgit 1.4.1