From 5299f0725f18ded7208b857b1f3292a719608ea2 Mon Sep 17 00:00:00 2001 From: Connor Olding Date: Sun, 21 Jul 2024 13:05:32 -0700 Subject: [PATCH] use `recombine` for all shells --- home/bashrc | 13 +------------ home/shrc | 8 ++++++++ home/zshrc | 21 --------------------- sh/recombine | 7 ++++--- 4 files changed, 13 insertions(+), 36 deletions(-) diff --git a/home/bashrc b/home/bashrc index 59c526a..e9a2586 100644 --- a/home/bashrc +++ b/home/bashrc @@ -36,20 +36,9 @@ _temporary_scope_() { PROMPT_COMMAND="[ \$? = 0 ] && PS1=\$'$ret_okay' || PS1=\$'$ret_fail'" }; _temporary_scope_; unset -f _temporary_scope_ -. ~/.shrc - #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. -if [ -s ~/sh/recombine ] && (. ~/sh/recombine) > ~/.sh-bash; then - preload=dummy - . ~/.sh-bash - unset preload -elif [ -f ~/.sh-bash ]; then - rm ~/.sh-bash -fi +. ~/.shrc alias reload='cd; exec bash' ### @- **TODO:** respect initctl like in `.zshrc`. [ ! -e ~/.lol ] || . ~/.lol diff --git a/home/shrc b/home/shrc index 2dd0d23..a8db436 100644 --- a/home/shrc +++ b/home/shrc @@ -4,6 +4,14 @@ unset FANCY; _=: && [ -z $_ ] && FANCY=1 || FANCY=0 # detect zsh and bash 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 have() { if [ -z "$ZSH_VERSION" ]; then which -- "$1"; else whence -p -- "$1"; fi; } 2>/dev/null diff --git a/home/zshrc b/home/zshrc index 24011d3..744d929 100644 --- a/home/zshrc +++ b/home/zshrc @@ -61,28 +61,7 @@ autoload edit-command-line autoload history-search-end 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. -preload=dummy -. ~/.sh -unset preload dirprev() { ### @- ### rotate and change to the previous directory in the directory stack diff --git a/sh/recombine b/sh/recombine index 007b703..fbeed15 100644 --- a/sh/recombine +++ b/sh/recombine @@ -2,7 +2,8 @@ # FAKE_COMPAT 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;; (bash) SH=BASH;; (dash) SH=DASH;; @@ -14,10 +15,10 @@ case "$0" in (osh) SH=OSH;; (posh) SH=POSH;; (yash) SH=YASH;; -(zsh) SH=ZSH;; +(zsh) SH=ZSH; set -o SH_WORD_SPLIT;; (*) printf >&2 %s\\n "unknown shell (\$0): $0" - return 1 + exit 1 esac printf %s\\n '#!/usr/bin/env false' '[ -n "$preload" ] || exit 1' ''