#!/usr/bin/env bash function emit-stack-trace { local -i x local -i stack_frames="${#FUNCNAME[@]}" { echo "ERROR in ${FUNCNAME[1]}() at ${BASH_SOURCE[1]}:${BASH_LINENO[0]}" for (( x=2; x < stack_frames; x++ )) do echo "called by ${FUNCNAME[x]}() at ${BASH_SOURCE[x]}:${BASH_LINENO[x - 1]}" done } >&2 } # end emit-stack-trace() function strict-errors { set -o errexit set -o errtrace trap emit-stack-trace ERR } # end strict-errors() function loose-errors { set +o errexit set +o errtrace trap - ERR } # end loose-errors() strict-errors # "dirname $0" does not work if we were invoked via a symlink, so we've got to # go through this fun. See http://mywiki.wooledge.org/BashFAQ/028 if readlink -e /dev/null &>/dev/null then # GNU readlink(1) self="$(readlink -e "${BASH_SOURCE[0]}")" else # BSD readlink(1) loose-errors self="${BASH_SOURCE[0]}" if [[ ! $self =~ ^/ ]] then if [[ $self =~ / ]] then self="$PWD/$self" else echo 'Could not determine base directory for Fig.' >&2 exit 1 fi fi self_link="$(! readlink -n "$self")" while [[ -n $self_link ]] do if [[ ! $self_link =~ ^/ ]] then self_link="$(dirname "$self")/$self_link" fi self="$self_link" self_link="$(! readlink -n "$self")" done strict-errors fi fig_dir=$(dirname "$self") # No longer strict on errors; let Ruby code determine how this script exits. loose-errors # Identical to regular fig, but doesn't use exception handling so you can see # stack traces. exec ruby \ --external-encoding UTF-8 \ --internal-encoding UTF-8 \ -r "$fig_dir/../lib/fig/command/initialization.rb" \ -e 'exit Fig::Command.new.run_fig ARGV' \ -- "$@"