Sha256: cc417c00e20f0d04f6f1631e1b20e1e807deeac08606ba628740a6b32353378a

Contents?: true

Size: 1.92 KB

Versions: 12

Compression:

Stored size: 1.92 KB

Contents

#!/bin/sh
# shellcheck disable=1001,1012,2039,1090
# 1001,1012 stop complaints about '\awk' syntax to bypass aliases.
# 2039 stops complaints about array references not being POSIX.
# 1090 stops complaints about sourcing non-constant paths.

__shell="$(\ps -p $$ | \awk 'NR > 1 { sub(/^-/, "", $4); print $4 }')"
__shellname="$(basename "${__shell}")"

case "${__shellname}" in
  bash)
    __jive_root_dir="$(builtin cd "$(\dirname "${BASH_SOURCE[0]}")" && \pwd)"
    ;;
  zsh)
    __jive_root_dir="$(\dirname "$0:A")"
    ;;
  *)
    >&2 \echo "jive is not compatible with your shell (${__shell})"
    \return 1
    ;;
esac

__jive_exe_dir="${__jive_root_dir}/exe"
__jive_lib_dir="${__jive_root_dir}/lib"
__jive_script="${__jive_root_dir}/jive.sh"

__mtime_of_jive_script="$(\date -r "${__jive_script}" +%s)"
__jive_auto_reload() {
  local current_mtime
  current_mtime="$(\date -r "${__jive_script}" +%s)"

  if [[ "${current_mtime}" != "${__mtime_of_jive_script}" ]]; then
    echo "Reloading... ${__jive_script}"
    . "${__jive_script}"
  fi
}

__jive_exec() {
  /usr/bin/env -S ruby -I "${__jive_lib_dir}" "${__jive_exe_dir}/jive" "$@"
}

__jive_open_pipe() {
  local tmpfile
  tmpfile="$(\mktemp -u)"

  exec 42>"${tmpfile}" # Open the tempfile for writing on FD 42.
  exec 8<"${tmpfile}" # Open the tempfile for reading on FD 8.
  \rm -f "${tmpfile}" # Unlink the tempfile. (we've already opened it).
}

__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
    __jive_execute_task "${task}"
  done <&8

  __jive_close_pipe
}

__jive_close_pipe() {
  exec 8<&- # close FD 8.
  exec 42<&- # close FD 42.
}

jive() {
  __jive_auto_reload
  __jive_open_pipe
  __jive_exec "$@"
  __jive_flush_tasks
}

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
jive-0.5.0 jive.sh
jive-0.4.4 jive.sh
jive-0.4.3 jive.sh
jive-0.4.2 jive.sh
jive-0.4.1 jive.sh
jive-0.4.0 jive.sh
jive-0.3.3 jive.sh
jive-0.3.2 jive.sh
jive-0.3.1 jive.sh
jive-0.3.0 jive.sh
jive-0.2.3 jive.sh
jive-0.2.2 jive.sh