Skip to content

Commit bb1204e

Browse files
committed
improved detector for CD & SCRIPT
1 parent f1cbe36 commit bb1204e

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

bash.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -306,10 +306,10 @@ else
306306
alias is_ttya=false
307307
fi
308308
cmd_exists() { command -v $1 >/dev/null; } # it detects any builtin or external commands, aliases, and any functions
309-
fn_exists() { LC_ALL=C type $1 2>/dev/null | grep -qE '(shell function)|(a function)'; }
310-
fn_builtin_exists() { LC_ALL=C type $1 2>/dev/null | grep -q 'shell builtin'; }
309+
fn_exists() { LC_ALL=C type $1 2>/dev/null | grep -qE '( shell function)|( a function)'; }
310+
fn_builtin_exists() { LC_ALL=C type $1 2>/dev/null | grep -q ' shell builtin'; }
311311
if is_zsh_strict; then
312-
fn_aliased_exists() { LC_ALL=C type $1 2>/dev/null | grep -qE '(alias for)|(aliased to)'; }
312+
fn_aliased_exists() { LC_ALL=C type $1 2>/dev/null | grep -qE '(alias for )|(aliased to )'; }
313313
else
314314
fn_aliased_exists() { LC_ALL=C alias $1 1>/dev/null 2>&1; }
315315
fi
@@ -1368,11 +1368,11 @@ alias list-all-env-variables=list_all_env_variables list-all-variables=list_all_
13681368
# trans_readlink() { DIR="${1%/*}" && (cd $DIR && pwd -P); }
13691369
# is_darwin && realpathx() { [[ $1 == /* ]] && echo "$1" || { DIR="${1%/*}" && DIR=$(cd $DIR && pwd -P) && echo "$DIR/$(basename $1)"; }; } || realpathx() { readlink -f $*; }
13701370
in_sourcing && {
1371-
SCRIPT=$(realpathx $(is_zsh_strict && echo "$0" || echo "$BASH_SOURCE")) && CD=$(dirname "$SCRIPT") && debug "$(safety ">> IN SOURCING (DEBUG=$DEBUG), \$0=$0, \$_=$_")"
1371+
SCRIPT=$(realpathx $(is_zsh_strict && echo "$0" || { [ "$BASH_SOURCE" != "" ] && echo "$BASH_SOURCE" || echo "$0"; })) && CD=$(dirname "$SCRIPT") && debug "$(safety ">> IN SOURCING (DEBUG=$DEBUG), \$0=$0, \$_=$_")"
13721372
} || {
13731373
path_in_orb_host "$0" && SCRIPT="$0" || SCRIPT=$(realpathx "$0")
13741374
CD=$(dirname "$SCRIPT") && debug "$(safety ">> '$SCRIPT' in '$CD', \$0='$0','$1'.")"
1375-
}
1375+
} || CD="$(cd $(dirname "$0") && pwd)"
13761376
if_vagrant && [ "$SCRIPT" == "/tmp/vagrant-shell" ] && { [ -d "$CD/ops.d" ] || CD=/vagrant/bin; }
13771377
path_in_orb_host "$0" && : || { [ -L "$SCRIPT" ] && debug "$(safety "linked script found")" && SCRIPT="$(realpathx "$SCRIPT")" && CD="$(dirname "$SCRIPT")"; }
13781378
# The better consice way to get baseDir, ie. $CD, is:

0 commit comments

Comments
 (0)