From 5ab2749c72ad71cada05982e4ca84150eed03b87 Mon Sep 17 00:00:00 2001 From: You Jiacheng <1503679330@qq.com> Date: Wed, 22 Nov 2023 02:25:55 +0800 Subject: [PATCH] Update install.sh --- install.sh | 38 +++++++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/install.sh b/install.sh index ec4bf59..9b59ea7 100644 --- a/install.sh +++ b/install.sh @@ -2,19 +2,31 @@ set -eu -# Detect the shell from which the script was called -parent=$(ps -o comm $PPID |tail -1) -parent=${parent#-} # remove the leading dash that login shells have -case "$parent" in - # shells supported by `micromamba shell init` - bash|fish|xonsh|zsh) - shell=$parent - ;; - *) - # use the login shell (basename of $SHELL) as a fallback - shell=${SHELL##*/} - ;; -esac +if [ -n "$INIT_WHICH_SHELL" ]; then + shell=$INIT_WHICH_SHELL +else + # Detect the shell from which the script was called + parent=$(ps -o comm $PPID 2>/dev/null |tail -1) + parent=${parent#-} # remove the leading dash that login shells have + # Check if the parent shell is supported + case "$parent" in + bash|fish|xonsh|zsh) + shell=$parent + ;; + *) + # If parent shell is not supported (or there is no parent), check the current shell + parent=$(ps -o comm $$ |tail -1) + case "$current" in + bash|fish|xonsh|zsh) + shell=$current + ;; + *) + # If neither parent nor current shell is supported, use the login shell + shell=${SHELL##*/} + ;; + esac + esac +fi # Parsing arguments if [ -t 0 ] ; then