1
0
Fork 0
mirror of https://github.com/notwa/rc synced 2024-11-05 06:49:03 -08:00
rc/sh/recombine

36 lines
948 B
Text

#!/usr/bin/env false
# FAKE_COMPAT
cd ~/sh && unset IFS || exit
[ -z "${0##/*}" ] && sh=zsh || sh="${0#-}" # zsh replaces $0, so hardcode it
case "$sh" in
(ash) SH=ASH;;
(bash) SH=BASH;;
(dash) SH=DASH;;
(hush) SH=HUSH;;
(ksh) SH=KSH;;
(loksh) SH=OKSH;; # similar enough to oksh to use the same compatibility flag
(mksh) SH=MKSH;;
(oksh) SH=OKSH;;
(osh) SH=OSH;;
(posh) SH=POSH;;
(yash) SH=YASH;;
(zsh) SH=ZSH; set -o SH_WORD_SPLIT;;
(*)
printf >&2 %s\\n "unknown shell (\$0): $0"
exit 1
esac
printf %s\\n '#!/usr/bin/env false' '[ -n "$preload" ] || exit 1' ''
for f in "${HOME:?}/sh"/*; do
[ -n "${f##*.*}" ] && [ -f "$f" ] || continue
i=10 sh=
while IFS= read -r line; do
for word in $line; do
case "$word" in (YES_$SH) sh=1;; (NO_$SH) sh=0;; esac
done
[ "$((i-=1))" != 0 ] || break # act like head -n10
done < "$f"
[ "$sh" != 1 ] || set -- "$@" "$f"
done
[ $# = 0 ] || cat "$@"