From 22159f160cc9b775dcb9b95e80f71e6b5a925650 Mon Sep 17 00:00:00 2001 From: WilliamMTK Date: Fri, 4 Jul 2025 15:09:28 -0400 Subject: i_love_zsh: make setup script universal for other shells (#122) * i_love_zsh: make setup script universal for other shells * Update setup_environment Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update setup_environment Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- setup_environment | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/setup_environment b/setup_environment index 5974ad0..f48422d 100644 --- a/setup_environment +++ b/setup_environment @@ -1,9 +1,25 @@ # see README before running this -ps -p $$ | awk '/bash/ || / sh/ || /zsh/ {exit 1;}' && echo "WARNING ** source setup_environment must be run in a bash, zsh or sh shell; see README" - +# Helper functions +# Usage: location=$(get_script_location) +get_script_location() { + if test -n "$BASH" ; then SCRIPT_LOC=$BASH_SOURCE + elif test -n "$ZSH_NAME" ; then SCRIPT_LOC=${(%):-%x} + else + echo "WARNING this script only tested with bash and zsh, use with caution with your shell at $SHELL" + if test -n "$TMOUT"; then SCRIPT_LOC=${.sh.file} + elif test ${0##*/} = dash; then x=$(lsof -p $$ -Fn0 | tail -1); SCRIPT_LOC=${x#n} + elif test -n "$FISH_VERSION" ; then SCRIPT_LOC=(status current-filename) + else echo "ERROR unknown shell, cannot determine script location" && return 1 + fi + fi + echo "$SCRIPT_LOC" +} + +# Get the location of this script when sourcing +SCRIPT_LOC=$(get_script_location) || (echo "ERROR getting script location" && return 1) export GPGPUSIM_SETUP_ENVIRONMENT_WAS_RUN= -export GPGPUSIM_ROOT="$( cd "$( dirname "$BASH_SOURCE" )" && pwd )" +export GPGPUSIM_ROOT="$( cd "$( dirname "$SCRIPT_LOC" )" && pwd )" GPGPUSIM_VERSION_STRING=`cat $GPGPUSIM_ROOT/version | awk '/Version/ {print $8}'` #Detect Git branch and commit # -- cgit v1.3