.lib/sh/stubexec.sh

Fri, 26 Nov 2021 00:12:00 -0600

author
Meredith Howard <mhoward@roomag.org>
date
Fri, 26 Nov 2021 00:12:00 -0600
changeset 959
4a5aaef00594
parent 958
b883fb5c4792
child 960
4921edc4b518
permissions
-rw-r--r--

try a personal config

realpath() {
  local dir="$(dirname -- "$1")"
  local file="$(basename -- "$1")"
  (cd "$dir" 2>/dev/null && printf '%s/%s\n' "$(pwd -P)" "$file")
}

shim_filter() {
  local binpath=''
  while read binpath; do
    case "$binpath" in
      */.plenv/shims/*)
        plenv which $1 >/dev/null 2>&1 || continue
        ;;
      */.asdf/shims/*)
        asdf which $1 >/dev/null 2>&1 || continue
        ;;
    esac
    echo "$binpath"
  done
}

realbin() {
  which -a $(basename $1) |
    grep -v "$(realpath $1)" |
    shim_filter |
    head -n 1
}

stubexec() {
  local real_bin="$(realbin "$0")"
  if [ -x "$real_bin" ]; then
    exec "$real_bin" $*
  fi
  install_it
  stubexec $*
}

mercurial