mirror of
https://github.com/envmodules/modules.git
synced 2026-06-14 00:42:43 +08:00
To improve shell detection code that until now was relying on a parent process name check, some shell variables will be used to determine the current shell name. $BASH and $ZSH_NAME variables will be looked at if defined to determine calling shell name. Doing so will avoid some external command call when running bash or zsh. Also if people source /etc/profile script in their own bash or zsh script it will correctly determine calling shell name, as parent process in this case is the script name. Cannot determine shell name on ksh with a variable due to the lack of a consistent detection mechanism across all ksh flavors [1]. Fixes #173 [1] https://books.google.fr/books?id=53zaxy423xcC&pg=PA161
16 lines
326 B
Bash
16 lines
326 B
Bash
# get current shell name by querying shell variables or looking at parent
|
|
# process name
|
|
if [ -n "${BASH:-}" ]; then
|
|
shell=${BASH##*/}
|
|
elif [ -n "${ZSH_NAME:-}" ]; then
|
|
shell=$ZSH_NAME
|
|
else
|
|
shell=$(@BASENAME@ $(@PS@ -p $$ -ocomm=))
|
|
fi
|
|
|
|
if [ -f @initdir@/$shell ]; then
|
|
. @initdir@/$shell
|
|
else
|
|
. @initdir@/sh
|
|
fi
|