Commit b334775

mo khan <mo@mokhan.ca>
2021-02-06 00:34:45
refactor: execute task immediately
1 parent afd5807
Changed files (1)
jive.sh
@@ -35,13 +35,6 @@ __jive_auto_reload() {
   fi
 }
 
-jive() {
-  __jive_auto_reload
-  __jive_open_pipe
-  __jive_exec "$@"
-  __jive_read_and_close_pipe
-}
-
 __jive_exec() {
   /usr/bin/env -S ruby -I "${__jive_lib_dir}" "${__jive_exe_dir}/jive" "$@"
 }
@@ -55,31 +48,30 @@ __jive_open_pipe() {
   \rm -f "${tmpfile}" # Unlink the tempfile. (we've already opened it).
 }
 
-__jive_read_and_close_pipe() {
-  local tasks
-  tasks=()
+__jive_execute_task() {
+  local task=$1
+
+  case "${task}" in
+    cd:*)
+      # shellcheck disable=SC2164
+      cd "${task//cd:/}"
+      ;;
+    setenv:*)
+      export "${task//setenv:/}"
+      ;;
+    *)
+      echo "Woof! ${task}"
+      ;;
+  esac
+}
 
+__jive_flush_tasks() {
   local task
   while \read -r task; do
-    tasks+=("${task}")
+    __jive_execute_task "${task}"
   done <&8
 
   __jive_close_pipe
-
-  for task in "${tasks[@]}"; do
-    case "${task}" in
-      cd:*)
-        # shellcheck disable=SC2164
-        cd "${task//cd:/}"
-        ;;
-      setenv:*)
-        export "${task//setenv:/}"
-        ;;
-      *)
-        echo "wtf is ${task} ?"
-        ;;
-    esac
-  done
 }
 
 __jive_close_pipe() {
@@ -87,3 +79,9 @@ __jive_close_pipe() {
   exec 9<&- # close FD 9.
 }
 
+jive() {
+  __jive_auto_reload
+  __jive_open_pipe
+  __jive_exec "$@"
+  __jive_flush_tasks
+}