diff --git a/home/bashrc b/home/bashrc index 62591d6..59c526a 100644 --- a/home/bashrc +++ b/home/bashrc @@ -38,21 +38,18 @@ _temporary_scope_() { . ~/.shrc -ADDPATH "$HOME/sh" # this doesn't work for all scripts at the moment +#ADDPATH "$HOME/sh" # this doesn't work for all scripts at the moment +dummy() { :; } ### @- return 0, ignoring arguments. # combine everything matching "YES_BASH" in ~/sh/ into ~/.sh-bash. # unlike zsh, we do not check the sha1sum of the output. - (: \ - && cd ~/sh \ - && printf '%s\n' '#!/usr/bin/env false' '[ -n "$preload" ] || exit 1' '' \ - | cat - > ~/.sh-bash \ - $(grep -lF YES_BASH -- $(find ~/sh/ -maxdepth 1 -type f '!' -name '*.bak')) \ - ;) - -dummy() { :; } ### @- return 0, ignoring arguments. -preload=dummy -. ~/.sh-bash -unset preload +if [ -s ~/sh/recombine ] && (. ~/sh/recombine) > ~/.sh-bash; then + preload=dummy + . ~/.sh-bash + unset preload +elif [ -f ~/.sh-bash ]; then + rm ~/.sh-bash +fi alias reload='cd; exec bash' ### @- **TODO:** respect initctl like in `.zshrc`. [ ! -e ~/.lol ] || . ~/.lol diff --git a/sh/recombine b/sh/recombine new file mode 100644 index 0000000..007b703 --- /dev/null +++ b/sh/recombine @@ -0,0 +1,35 @@ +#!/usr/bin/env false +# FAKE_COMPAT + +cd ~/sh && unset IFS || exit +case "$0" in +(ash) SH=ASH;; +(bash) SH=BASH;; +(dash) SH=DASH;; +(hush) SH=HUSH;; +(ksh) SH=KSH;; +(loksh) SH=LOKSH;; +(mksh) SH=MKSH;; +(oksh) SH=OKSH;; +(osh) SH=OSH;; +(posh) SH=POSH;; +(yash) SH=YASH;; +(zsh) SH=ZSH;; +(*) + printf >&2 %s\\n "unknown shell (\$0): $0" + return 1 +esac + +printf %s\\n '#!/usr/bin/env false' '[ -n "$preload" ] || exit 1' '' +for f in ~/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 "$@"