1
0
Fork 0
mirror of https://github.com/notwa/rc synced 2025-02-05 07:43:22 -08:00

use recombine for all shells

This commit is contained in:
Connor Olding 2024-07-21 13:05:32 -07:00
parent 474a42f658
commit 5299f0725f
4 changed files with 13 additions and 36 deletions

View file

@ -36,20 +36,9 @@ _temporary_scope_() {
PROMPT_COMMAND="[ \$? = 0 ] && PS1=\$'$ret_okay' || PS1=\$'$ret_fail'" PROMPT_COMMAND="[ \$? = 0 ] && PS1=\$'$ret_okay' || PS1=\$'$ret_fail'"
}; _temporary_scope_; unset -f _temporary_scope_ }; _temporary_scope_; unset -f _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. dummy() { :; } ### @- return 0, ignoring arguments.
. ~/.shrc
# combine everything matching "YES_BASH" in ~/sh/ into ~/.sh-bash.
# unlike zsh, we do not check the sha1sum of the output.
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`. alias reload='cd; exec bash' ### @- **TODO:** respect initctl like in `.zshrc`.
[ ! -e ~/.lol ] || . ~/.lol [ ! -e ~/.lol ] || . ~/.lol

View file

@ -4,6 +4,14 @@
unset FANCY; _=: && [ -z $_ ] && FANCY=1 || FANCY=0 # detect zsh and bash unset FANCY; _=: && [ -z $_ ] && FANCY=1 || FANCY=0 # detect zsh and bash
if [ "$FANCY" = 0 ]; then . ~/.prep; fi # handle stuff like /etc/profile and $PATH if [ "$FANCY" = 0 ]; then . ~/.prep; fi # handle stuff like /etc/profile and $PATH
# combine everything matching "YES_MYSHELL" in ~/sh/ into ~/.sh-myshell.
[ -z "${0##/*}" ] && sh=zsh || sh="$0" # zsh replaces $0, so hardcode it
if [ -s ~/sh/recombine ] && (. ~/sh/recombine) > ~/.sh-"$sh"; then
preload=:; . ~/.sh-"$sh"; unset preload
elif [ -f ~/.sh-"$sh" ]; then
rm ~/.sh-"$sh"
fi
# {{{1 utilities # {{{1 utilities
have() { if [ -z "$ZSH_VERSION" ]; then which -- "$1"; else whence -p -- "$1"; fi; } 2>/dev/null have() { if [ -z "$ZSH_VERSION" ]; then which -- "$1"; else whence -p -- "$1"; fi; } 2>/dev/null

View file

@ -61,28 +61,7 @@ autoload edit-command-line
autoload history-search-end autoload history-search-end
zmodload zsh/mathfunc zmodload zsh/mathfunc
# combine everything matching "YES_ZSH" in ~/sh/ into ~/.sh,
# but only recompile the output if the sha1sum has changed.
function
{: \
&& local a= b= \
&& { [ ! -s ~/.sh.sha1 ] || read -r b _ < ~/.sh.sha1 ;} \
&& (: \
&& cd ~/sh \
&& print -l '#!/usr/bin/env false' '[ -n "$preload" ] || exit 1' '' \
| cat - $(grep -lF YES_ZSH -- *~*.bak(.)) \
| tee ~/.sh \
;) \
| sha1sum - \
| tee ~/.sh.sha1 \
| read -r a _ \
&& { [ "$a" = "$b" ] && touch ~/.sh.zwc || zrecompile -p ~/.sh ;} \
;}
dummy() : ### @- return 0, ignoring arguments. dummy() : ### @- return 0, ignoring arguments.
preload=dummy
. ~/.sh
unset preload
dirprev() { ### @- dirprev() { ### @-
### rotate and change to the previous directory in the directory stack ### rotate and change to the previous directory in the directory stack

View file

@ -2,7 +2,8 @@
# FAKE_COMPAT # FAKE_COMPAT
cd ~/sh && unset IFS || exit cd ~/sh && unset IFS || exit
case "$0" in [ -z "${0##/*}" ] && sh=zsh || sh="$0" # zsh replaces $0, so hardcode it
case "$sh" in
(ash) SH=ASH;; (ash) SH=ASH;;
(bash) SH=BASH;; (bash) SH=BASH;;
(dash) SH=DASH;; (dash) SH=DASH;;
@ -14,10 +15,10 @@ case "$0" in
(osh) SH=OSH;; (osh) SH=OSH;;
(posh) SH=POSH;; (posh) SH=POSH;;
(yash) SH=YASH;; (yash) SH=YASH;;
(zsh) SH=ZSH;; (zsh) SH=ZSH; set -o SH_WORD_SPLIT;;
(*) (*)
printf >&2 %s\\n "unknown shell (\$0): $0" printf >&2 %s\\n "unknown shell (\$0): $0"
return 1 exit 1
esac esac
printf %s\\n '#!/usr/bin/env false' '[ -n "$preload" ] || exit 1' '' printf %s\\n '#!/usr/bin/env false' '[ -n "$preload" ] || exit 1' ''