1
0
Fork 0
mirror of https://github.com/notwa/rc synced 2024-11-05 06:39:02 -08:00

automatically detect which of the four main shells that sh is

This commit is contained in:
Connor Olding 2024-07-30 08:53:19 -07:00
parent 28b4942252
commit de4c5ec593

View file

@ -23,12 +23,22 @@ case "$sh" in
(osh) SH=OSH c=osh;; (osh) SH=OSH c=osh;;
(posh) SH=POSH c=posh;; (posh) SH=POSH c=posh;;
(yash) SH=YASH c=yash;; (yash) SH=YASH c=yash;;
(zsh) SH=ZSH c=zsh; set -o SH_WORD_SPLIT;; (zsh) SH=ZSH c=zsh;;
(sh)
f() { ! return 1; }
g() { return 256; }
if f; then # (ash, hush) || (zsh)
g && SH=ASH c=ash || SH=ZSH c=zsh
else # (bash, mksh, osh) || (dash, ksh, loksh, oksh, posh, yash)
g && SH=BASH c=bash || SH=DASH c=dash
fi;;
(*) (*)
printf >&2 %s\\n "unknown shell (\$0): $0" printf >&2 %s\\n "unknown shell (\$0): $0"
exit 1 exit 1
esac esac
[ "$SH" != zsh ] || set -o SH_WORD_SPLIT
printf %s\\n '#!/usr/bin/env false' '[ -n "$preload" ] || exit 1' '' printf %s\\n '#!/usr/bin/env false' '[ -n "$preload" ] || exit 1' ''
for f in "${HOME:?}/sh"/*; do for f in "${HOME:?}/sh"/*; do
[ -n "${f##*.*}" ] && [ -f "$f" ] || continue [ -n "${f##*.*}" ] && [ -f "$f" ] || continue