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

add recombine and rewrite the way .bashrc loads its functions

This commit is contained in:
Connor Olding 2024-07-21 12:22:05 -07:00
parent 0e4bc62986
commit a643458c9f
2 changed files with 44 additions and 12 deletions

View file

@ -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

35
sh/recombine Normal file
View file

@ -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 "$@"