mirror of
https://github.com/notwa/rc
synced 2024-11-05 06:39:02 -08:00
Connor Olding
85869d590d
this is a crappy fix to remain until i decide on how best to handle the basic configuration of each shell
56 lines
1.5 KiB
Text
56 lines
1.5 KiB
Text
#!/usr/bin/env false
|
|
# FAKE_COMPAT
|
|
|
|
cd ~/sh && unset IFS || exit
|
|
|
|
case "$0" in
|
|
(-*) zero="${0#-}";;
|
|
(/*) zero="${0##*/}";;
|
|
(*) zero="$0"
|
|
esac
|
|
|
|
[ "$zero" != recombine ] || zero=zsh # only zsh does this (AFAIK)
|
|
|
|
case "$zero" in
|
|
(ash) SH=ASH sh=ash;;
|
|
(bash) SH=BASH sh=bash;;
|
|
(dash) SH=DASH sh=dash;;
|
|
(hush) SH=HUSH sh=hush;;
|
|
(ksh) SH=KSH sh=ksh;;
|
|
(loksh) SH=OKSH sh=oksh;; # similar enough to oksh to use the same compatibility flag
|
|
(mksh) SH=MKSH sh=mksh;;
|
|
(oksh) SH=OKSH sh=oksh;;
|
|
(osh) SH=OSH sh=osh;;
|
|
(posh) SH=POSH sh=posh;;
|
|
(yash) SH=YASH sh=yash;;
|
|
(zsh) SH=ZSH sh=zsh;;
|
|
(sh)
|
|
f() { ! return 1; }
|
|
g() { return 256; }
|
|
if f; then # (ash, hush) || (zsh)
|
|
g && SH=ASH sh=ash || SH=ZSH sh=zsh
|
|
else # (bash, mksh, osh) || (dash, ksh, loksh, oksh, posh, yash)
|
|
g && SH=BASH sh=bash || SH=DASH sh=dash
|
|
fi;;
|
|
(*)
|
|
printf >&2 %s\\n "unknown shell (\$0): $0"
|
|
exit 1
|
|
esac
|
|
|
|
[ "$SH" != ZSH ] || set -o SH_WORD_SPLIT
|
|
|
|
printf %s\\n '#!/usr/bin/env false' '[ -n "$preload" ] || exit 1' ''
|
|
for f in "${HOME:?}/sh"/*; do
|
|
[ -n "${f##*.*}" ] && [ -f "$f" ] || continue
|
|
i=10 ok=
|
|
while IFS= read -r line; do
|
|
check=0
|
|
for word in $line; do
|
|
case "$word" in (YES_$SH) ok=1;; (NO_$SH) ok=0;; (compat:) check=1;; esac
|
|
[ "$check" != 1 ] || case "$word" in (+$sh) ok=1;; (-$sh) ok=0;; esac
|
|
done
|
|
[ "$((i-=1))" != 0 ] || break # act like head -n10
|
|
done < "$f"
|
|
[ "$ok" != 1 ] || set -- "$@" "$f"
|
|
done
|
|
[ $# = 0 ] || cat "$@"
|