Open texastoland opened 5 months ago
if it helps anyone, $shell_name
(I use lowercase vars in scripts to avoid global env clashes) can be pulled from $SHELL
with:
echo -n "$SHELL" | sed 's>.*/>>'
I believe -n
(no newline) isn't portable, but I'm unsure if it's necessary.
My .zshenv
includes:
if type mise &> /dev/null; then
if [[ -t 0 ]]; then # terminal has stdin i.e. interactive
shell_name="$(echo "$SHELL" | sed -E 's>.*/>>')"
eval "$(mise activate "$shell_name")"
else
eval "$(mise activate --shims)"
fi
fi
Thanks for the tip :)
$shell_name
... can be pulled from$SHELL
Yeah there are a few ways. Some of them had unexpected behavior in subshells for example. I chose the following in my .zshrc
:
SHELL_NAME=${ZSH_VERSION:+zsh}${BASH_VERSION:+bash} # also sourced in .bashrc
A hypothetical --auto
flag might be able to do that too.
I found a dead simple pattern (confirmed in both zsh and bash):
Explained in my tweets:
Would you be interested in either PR:
--auto
flag that checks if stdin is readable internally (or)