diff --git a/home/bashrc b/home/bashrc index cba4164..acae28b 100644 --- a/home/bashrc +++ b/home/bashrc @@ -37,13 +37,14 @@ ADDPATH "$HOME/sh" ( cd ~/sh \ - && printf "%s\n" '#!/usr/bin/env false' '[ "${SOURCING:-0}" -gt 0 ] || exit 1' '' \ + && printf "%s\n" '#!/usr/bin/env false' '[ -n "$preload" ] || exit 1' '' \ | cat - $(grep -lF 'YES_BASH' $(find ~/sh -maxdepth 1 -type f)) \ > ~/.sh-bash ) -: $((SOURCING+=1)) +dummy() { :; } ### @- return 0, ignoring arguments. +preload=dummy . ~/.sh-bash -: $((SOURCING-=1)) +unset preload alias reload='cd; exec bash' ### @- **TODO:** respect initctl like in `.zshrc`. diff --git a/home/zshrc b/home/zshrc index 6a471ee..e2de3c9 100644 --- a/home/zshrc +++ b/home/zshrc @@ -51,7 +51,7 @@ function { [ -s ~/.sh.sha1 ] && read -r b _ < ~/.sh.sha1 ( cd ~/sh \ - && print -l '#!/usr/bin/env false' '[ "${SOURCING:-0}" -gt 0 ] || exit 1' '' \ + && print -l '#!/usr/bin/env false' '[ -n "$preload" ] || exit 1' '' \ | cat - $(grep -lF 'YES_ZSH' *(.)) \ | tee ~/.sh \ ) | sha1sum - \ @@ -61,9 +61,10 @@ function { [ "$a" = "$b" ] && touch ~/.sh.zwc || zrecompile -p ~/.sh } -: $((SOURCING+=1)) +dummy() { :; } ### @- return 0, ignoring arguments. +preload=dummy . ~/.sh -: $((SOURCING-=1)) +unset preload local fuzzy=`has fzy || print` diff --git a/sh/argc b/sh/argc index 0b445c8..ae21c27 100644 --- a/sh/argc +++ b/sh/argc @@ -59,4 +59,4 @@ argc() { ### @- validate the number of arguments in a function. return 0 } -[ "${SOURCING:-0}" -gt 0 ] || argc "$@" +[ -n "${preload+-}" ] || argc "$@" diff --git a/sh/arith b/sh/arith index 0813ee4..1026d0a 100755 --- a/sh/arith +++ b/sh/arith @@ -20,4 +20,4 @@ arith() { ### @- printf "%s\n" "$(($@))" } -[ "${SOURCING:-0}" -gt 0 ] || arith "$@" +[ -n "${preload+-}" ] || arith "$@" diff --git a/sh/aur b/sh/aur index 6073bb3..32b51f1 100755 --- a/sh/aur +++ b/sh/aur @@ -136,4 +136,4 @@ aur() { ### @- [ "$fail" -eq 0 ] && return 0 || return 1 } -[ "${SOURCING:-0}" -gt 0 ] || aur "$@" +[ -n "${preload+-}" ] || aur "$@" diff --git a/sh/autosync b/sh/autosync index 9b49a0a..9196a0c 100755 --- a/sh/autosync +++ b/sh/autosync @@ -17,4 +17,4 @@ autosync() { ### @- done } -[ "${SOURCING:-0}" -gt 0 ] || autosync "$@" +[ -n "${preload+-}" ] || autosync "$@" diff --git a/sh/bak b/sh/bak index 2d807a4..9f6e9d1 100644 --- a/sh/bak +++ b/sh/bak @@ -30,4 +30,4 @@ bak() { ### @- return $ret } -[ "${SOURCING:-0}" -gt 0 ] || bak "$@" +[ -n "${preload+-}" ] || bak "$@" diff --git a/sh/baknow b/sh/baknow index a75b275..b474805 100644 --- a/sh/baknow +++ b/sh/baknow @@ -19,4 +19,4 @@ baknow() { ### @- cp -ip "${1:?missing file argument}" "$1.$(now "$1").bak" } -[ "${SOURCING:-0}" -gt 0 ] || baknow "$@" +[ -n "${preload+-}" ] || baknow "$@" diff --git a/sh/baks b/sh/baks index 0879d40..380703a 100644 --- a/sh/baks +++ b/sh/baks @@ -4,10 +4,6 @@ # YES_BASH # YES_DASH -#: $((SOURCING+=1)) -#. ~/sh/note # FIXME: don't do this? -#: $((SOURCING-=1)) - baks() { ### @- ### backup files by copying each and appending *the current* date-time, ### irrespective of when the files were modified or created. @@ -36,4 +32,6 @@ baks() { ### @- return $ret } -[ "${SOURCING:-0}" -gt 0 ] || baks "$@" +preload() { local preload='set -- $@'; while [ $# -gt 0 ]; do . ~/sh/$1 || exit 2; shift; done; } +eval ${preload:-preload} note +[ -n "${preload+-}" ] || baks "$@" diff --git a/sh/bin b/sh/bin index 7fe3a69..d7c448d 100644 --- a/sh/bin +++ b/sh/bin @@ -20,4 +20,4 @@ bin() { ### @- printf "%08X\n" "$a" } -[ "${SOURCING:-0}" -gt 0 ] || bin "$@" +[ -n "${preload+-}" ] || bin "$@" diff --git a/sh/cdbusiest b/sh/cdbusiest index 14180b4..2a8aeb2 100755 --- a/sh/cdbusiest +++ b/sh/cdbusiest @@ -17,4 +17,4 @@ cdbusiest() { ### @- cd $d } -[ "${SOURCING:-0}" -gt 0 ] || cdbusiest "$@" +[ -n "${preload+-}" ] || cdbusiest "$@" diff --git a/sh/colors b/sh/colors index af169d7..09196ad 100755 --- a/sh/colors +++ b/sh/colors @@ -13,4 +13,4 @@ colors() { ### @- printf "\e[%dm$(printf " \e[%dm mV \e[40m" {4,10}{0..7})\e[0m\n" {3,9}{0..7} } -[ "${SOURCING:-0}" -gt 0 ] || colors "$@" +[ -n "${preload+-}" ] || colors "$@" diff --git a/sh/compandy b/sh/compandy index c362783..75e98a3 100755 --- a/sh/compandy +++ b/sh/compandy @@ -22,4 +22,4 @@ compandy() { ### @- $atk $atk $rel $rel $thresh $thresh $end $knee $gain $start $delay } -[ "${SOURCING:-0}" -gt 0 ] || compandy "$@" +[ -n "${preload+-}" ] || compandy "$@" diff --git a/sh/compile b/sh/compile index 3e10b44..7fd289c 100755 --- a/sh/compile +++ b/sh/compile @@ -359,4 +359,4 @@ compile() { ### @- $compiler $std ${final_flags[@]} $file ${libraries[@]} ${warnings[@]} $outflag $out } -[ "${SOURCING:-0}" -gt 0 ] || compile "$@" +[ -n "${preload+-}" ] || compile "$@" diff --git a/sh/confirm b/sh/confirm index 1726202..2a0916e 100755 --- a/sh/confirm +++ b/sh/confirm @@ -45,4 +45,4 @@ else } fi -[ "${SOURCING:-0}" -gt 0 ] || confirm "$@" +[ -n "${preload+-}" ] || confirm "$@" diff --git a/sh/countdiff b/sh/countdiff index 8295661..405463d 100644 --- a/sh/countdiff +++ b/sh/countdiff @@ -19,4 +19,4 @@ countdiff() { ### @- | awk '/changed/{print $4+$6;a=1}END{if(!a)print 0}' } -[ "${SOURCING:-0}" -gt 0 ] || countdiff "$@" +[ -n "${preload+-}" ] || countdiff "$@" diff --git a/sh/cutv b/sh/cutv index 229ecc5..eb39c2a 100644 --- a/sh/cutv +++ b/sh/cutv @@ -27,4 +27,4 @@ cutv() { ### @- # -maxrate 9600k -bufsize 12000k -vcodec libx264 -preset medium -crf 22 -vf scale=1280:720 } -[ "${SOURCING:-0}" -gt 0 ] || cutv "$@" +[ -n "${preload+-}" ] || cutv "$@" diff --git a/sh/days b/sh/days index e11e3dd..478ed44 100755 --- a/sh/days +++ b/sh/days @@ -14,4 +14,4 @@ days() { ### @- echo $(( ($(date +%s) - $(date -d "$1" +%s)) / 60 / 60 / 24 )) } -[ "${SOURCING:-0}" -gt 0 ] || days "$@" +[ -n "${preload+-}" ] || days "$@" diff --git a/sh/dbusiest b/sh/dbusiest index d6b5b15..ff1bdb1 100755 --- a/sh/dbusiest +++ b/sh/dbusiest @@ -24,4 +24,4 @@ dbusiest() { ### @- [ -z $d ] && return 1 } -[ "${SOURCING:-0}" -gt 0 ] || dbusiest +[ -n "${preload+-}" ] || dbusiest "$@" diff --git a/sh/dfu b/sh/dfu index 7ebbc2c..2f29c84 100755 --- a/sh/dfu +++ b/sh/dfu @@ -19,4 +19,4 @@ dfu() { ### @- NR>1{printf"%-20s %7.2f %7.2f %7.2f %7.2f\n",$6,$3/2^20,($3+$4)/2^20,($4)/2^20,($2-$4-$3)/2^20}' } -[ "${SOURCING:-0}" -gt 0 ] || dfu +[ -n "${preload+-}" ] || dfu "$@" diff --git a/sh/disf b/sh/disf index 40a52bb..66991d1 100755 --- a/sh/disf +++ b/sh/disf @@ -6,7 +6,7 @@ # TODO: actually test that this works with dash. -function disf() { ### @- +disf() { ### @- ### disassemble a single function from an unstripped executable, unreliably. [ $# -le 2 ] || { printf "%s\n" "$0: too many arguments" >&2; return 1; } local exe="${1:?first argument should be an unstripped executable}" @@ -15,4 +15,4 @@ function disf() { ### @- objdump -d -C --no-show-raw-insn "$exe" | sed '/<'"$symbol"'>:/,/^$/!d;//d' } -[ "${SOURCING:-0}" -gt 0 ] || disf "$@" +[ -n "${preload+-}" ] || disf "$@" diff --git a/sh/document b/sh/document index 7db03e8..b2d258b 100644 --- a/sh/document +++ b/sh/document @@ -164,4 +164,4 @@ document() { ### @- esac } -[ "${SOURCING:-0}" -gt 0 ] || document "$@" +[ -n "${preload+-}" ] || document "$@" diff --git a/sh/e b/sh/e index 994a9bc..b72d093 100755 --- a/sh/e +++ b/sh/e @@ -61,4 +61,4 @@ e() { ### @- fi } -[ "${SOURCING:-0}" -gt 0 ] || e "$@" +[ -n "${preload+-}" ] || e "$@" diff --git a/sh/ea b/sh/ea index 8079700..7cd154f 100644 --- a/sh/ea +++ b/sh/ea @@ -46,4 +46,4 @@ ea() { ### @- **TODO:** document. esac } -[ "${SOURCING:-0}" -gt 0 ] || ea "$@" +[ -n "${preload+-}" ] || ea "$@" diff --git a/sh/echo2 b/sh/echo2 index ec841f1..d23ab20 100644 --- a/sh/echo2 +++ b/sh/echo2 @@ -17,4 +17,4 @@ echo2() { ### @- printf "%s\n" "$*" >&2 } -[ "${SOURCING:-0}" -gt 0 ] || echo2 "$@" +[ -n "${preload+-}" ] || echo2 "$@" diff --git a/sh/explore b/sh/explore index 0652b53..e0c9c1c 100644 --- a/sh/explore +++ b/sh/explore @@ -9,4 +9,4 @@ explore() { ### @- open a single directory in `explorer.exe`, defaulting to `$PW explorer "$(cygpath -w "${1:-.}")" } -[ "${SOURCING:-0}" -gt 0 ] || explore "$@" +[ -n "${preload+-}" ] || explore "$@" diff --git a/sh/ff b/sh/ff index 818ed81..a641a15 100644 --- a/sh/ff +++ b/sh/ff @@ -10,4 +10,4 @@ ff() { ### @- find "${1:-.}" -type f | fzy } -[ "${SOURCING:-0}" -gt 0 ] || ff "$@" +[ -n "${preload+-}" ] || ff "$@" diff --git a/sh/ghmd b/sh/ghmd index 5d8586e..dcfbec2 100644 --- a/sh/ghmd +++ b/sh/ghmd @@ -28,4 +28,4 @@ ghmd() { ### @- return $ret } -[ "${SOURCING:-0}" -gt 0 ] || ghmd "$@" +[ -n "${preload+-}" ] || ghmd "$@" diff --git a/sh/has b/sh/has index 47fc687..c5df964 100644 --- a/sh/has +++ b/sh/has @@ -16,4 +16,4 @@ has() { ### @- fi } -[ "${SOURCING:-0}" -gt 0 ] || has "$@" +[ -n "${preload+-}" ] || has "$@" diff --git a/sh/hex b/sh/hex index 5dfebce..c719890 100755 --- a/sh/hex +++ b/sh/hex @@ -21,4 +21,4 @@ hex() { ### @- printf "%08X\n" "$(($@))" } -[ "${SOURCING:-0}" -gt 0 ] || hex "$@" +[ -n "${preload+-}" ] || hex "$@" diff --git a/sh/ify b/sh/ify index 29b3166..3da52c9 100644 --- a/sh/ify +++ b/sh/ify @@ -19,4 +19,4 @@ ify() { ### @- "$@" | "$ex" } -[ "${SOURCING:-0}" -gt 0 ] || ify "$@" +[ -n "${preload+-}" ] || ify "$@" diff --git a/sh/is_empty b/sh/is_empty index 3a9faa3..fe2097f 100755 --- a/sh/is_empty +++ b/sh/is_empty @@ -13,4 +13,4 @@ is_empty() { ### @- return 0 } -[ "${SOURCING:-0}" -gt 0 ] || is_empty "$@" +[ -n "${preload+-}" ] || is_empty "$@" diff --git a/sh/isup b/sh/isup index 61585c9..88daace 100755 --- a/sh/isup +++ b/sh/isup @@ -16,4 +16,4 @@ isup() { ### @- [ -z "${c#2[0-9][0-9]}" ] } -[ "${SOURCING:-0}" -gt 0 ] || isup "$@" +[ -n "${preload+-}" ] || isup "$@" diff --git a/sh/maybesudo b/sh/maybesudo index 2392427..a30d22e 100644 --- a/sh/maybesudo +++ b/sh/maybesudo @@ -136,4 +136,4 @@ maybesudo_() { ### @- # don't put any code here or you'll clobber $?. } -[ "${SOURCING:-0}" -gt 0 ] || maybesudo_ "$@" +[ -n "${preload+-}" ] || maybesudo_ "$@" diff --git a/sh/minutemaid b/sh/minutemaid index c555f51..880f3ce 100755 --- a/sh/minutemaid +++ b/sh/minutemaid @@ -40,4 +40,4 @@ minutemaid() { ### @- fi } -[ "${SOURCING:-0}" -gt 0 ] || minutemaid "$@" +[ -n "${preload+-}" ] || minutemaid "$@" diff --git a/sh/monitor b/sh/monitor index 7a1a922..dc09be8 100755 --- a/sh/monitor +++ b/sh/monitor @@ -47,4 +47,4 @@ monitor() { ### @- done } -[ "${SOURCING:-0}" -gt 0 ] || monitor "$@" +[ -n "${preload+-}" ] || monitor "$@" diff --git a/sh/noccom b/sh/noccom index 3abcb5c..fe9e8e0 100644 --- a/sh/noccom +++ b/sh/noccom @@ -53,4 +53,4 @@ EOF perl ~/opt/local/bin/noccom "$@" } -[ "${SOURCING:-0}" -gt 0 ] || noccom "$@" +[ -n "${preload+-}" ] || noccom "$@" diff --git a/sh/note b/sh/note index 5acaa94..c9134a8 100644 --- a/sh/note +++ b/sh/note @@ -12,4 +12,4 @@ note() { ### @- printf "\033[1m%s\033[0m\n" "$*" >&2 } -[ "${SOURCING:-0}" -gt 0 ] || note "$@" +[ -n "${preload+-}" ] || note "$@" diff --git a/sh/now b/sh/now index 1dadac3..9cc0cc2 100755 --- a/sh/now +++ b/sh/now @@ -53,4 +53,4 @@ now() { ### @- echo "${F}_${ms}" } -[ "${SOURCING:-0}" -gt 0 ] || now "$@" +[ -n "${preload+-}" ] || now "$@" diff --git a/sh/pacbm b/sh/pacbm index cc63522..a3620d1 100755 --- a/sh/pacbm +++ b/sh/pacbm @@ -18,4 +18,4 @@ pacbm() { ### @- ' | sort -n } -[ "${SOURCING:-0}" -gt 0 ] || pacbm "$@" +[ -n "${preload+-}" ] || pacbm "$@" diff --git a/sh/pause b/sh/pause index 38568c8..aa1bcf2 100755 --- a/sh/pause +++ b/sh/pause @@ -17,4 +17,4 @@ pause() { ### @- ' } -[ "${SOURCING:-0}" -gt 0 ] || pause "$@" +[ -n "${preload+-}" ] || pause "$@" diff --git a/sh/pegg b/sh/pegg index abcb9ff..07cd7f3 100644 --- a/sh/pegg +++ b/sh/pegg @@ -19,4 +19,4 @@ pegg() { ### @- pippy "https://github.com/$1/$2/tarball/${3:-master}#egg=$2" } -[ "${SOURCING:-0}" -gt 0 ] || pegg "$@" +[ -n "${preload+-}" ] || pegg "$@" diff --git a/sh/pippy b/sh/pippy index f6fb910..9ffc713 100644 --- a/sh/pippy +++ b/sh/pippy @@ -12,4 +12,4 @@ pippy() { ### @- "$sudo" py -m pip install --upgrade --upgrade-strategy only-if-needed "$@" } -[ "${SOURCING:-0}" -gt 0 ] || pippy "$@" +[ -n "${preload+-}" ] || pippy "$@" diff --git a/sh/pre b/sh/pre index 706ee64..a5f849e 100755 --- a/sh/pre +++ b/sh/pre @@ -26,4 +26,4 @@ pre() { ### @- fi } -[ "${SOURCING:-0}" -gt 0 ] || pre "$@" +[ -n "${preload+-}" ] || pre "$@" diff --git a/sh/preload b/sh/preload new file mode 100644 index 0000000..8f7e02a --- /dev/null +++ b/sh/preload @@ -0,0 +1,32 @@ +#!/usr/bin/env false +# NO_ZSH +# NO_BASH +# NO_DASH +# NO_ASH +# NOTE: this is actually compatible with all of the above shells; +# i just really don't want it being sourced by accident. +# this file really only exists for documentation purposes. + +preload() { ### @- handle dependencies within the [`~/sh/`](/sh) directory. + ### this function contains more comments than code, so you should read it. + # all sourced files from within the preload function will instead + # append to the list of files to preload (i.e. dependencies). + # dash and ash have no arrays besides $@, so we must use it. + local preload='set -- $@' + # we want to iterate over $@ like a queue; pushing and popping. + # `for` would create a local copy and leave $@ unmodified, so it's no good. + while [ $# -gt 0 ]; do + # NOTE: there's no quotes here since the surrounding method uses eval, + # so paths-with-spaces is already doomed from the start. + # however, $HOME can still safely contain spaces. + # NOTE: it's important to use an absolute path here. + . ~/sh/$1 # yes, you can source files from within functions, + # and they even respect your locals. + [ $? -eq 0 ] \ + || exit 2 # this `exit 2` is just for zsh and bash; + # dash and ash do it automatically. + # zsh actually uses some other return value, + # but we use 2 anyway since everything else uses 2. + shift # pop the queue + done +} diff --git a/sh/psbm b/sh/psbm index a970138..9e92ed1 100755 --- a/sh/psbm +++ b/sh/psbm @@ -18,4 +18,4 @@ psbm() { ### @- ' | sort -n } -[ "${SOURCING:-0}" -gt 0 ] || psbm "$@" +[ -n "${preload+-}" ] || psbm "$@" diff --git a/sh/randir b/sh/randir index ed7e111..9fa2550 100755 --- a/sh/randir +++ b/sh/randir @@ -13,4 +13,4 @@ randir() { ### @- find -maxdepth 1 -type d \( -path '/root' -prune -o -print \) | tail -n+2 | shuf | head -n1 } -[ "${SOURCING:-0}" -gt 0 ] || randir "$@" +[ -n "${preload+-}" ] || randir "$@" diff --git a/sh/refresh b/sh/refresh index 36641cf..8074b2c 100644 --- a/sh/refresh +++ b/sh/refresh @@ -7,4 +7,4 @@ refresh() { ### @- invoke `hash -r`. hash -r } -[ "${SOURCING:-0}" -gt 0 ] || refresh "$@" +[ -n "${preload+-}" ] || refresh "$@" diff --git a/sh/rot13 b/sh/rot13 index 35f6aea..a45487d 100644 --- a/sh/rot13 +++ b/sh/rot13 @@ -16,4 +16,4 @@ rot13() { ### @- tr -- A-Za-z0-9 N-ZA-Mn-za-m5-90-4 } -[ "${SOURCING:-0}" -gt 0 ] || rot13 "$@" +[ -n "${preload+-}" ] || rot13 "$@" diff --git a/sh/rs b/sh/rs index 87dabac..e3bf323 100644 --- a/sh/rs +++ b/sh/rs @@ -72,4 +72,4 @@ rs() { ### @- $o_overwrite "$extless.enc.$ext" } -[ "${SOURCING:-0}" -gt 0 ] || rs "$@" +[ -n "${preload+-}" ] || rs "$@" diff --git a/sh/sc b/sh/sc index 3f1a408..c4a248c 100755 --- a/sh/sc +++ b/sh/sc @@ -1,9 +1,5 @@ #!/usr/bin/env bash -: $((SOURCING+=1)) -. ~/sh/ea # FIXME: don't do this? somehow? -: $((SOURCING-=1)) - sc_shorten() { REPLY="${1:2:2}${1:5:2}${1:8:2}${1:11:12}" } @@ -66,4 +62,6 @@ sc() { ### @- return 0 } -[ "${SOURCING:-0}" -gt 0 ] || sc "$@" +preload() { local preload='set -- $@'; while [ $# -gt 0 ]; do . ~/sh/$1 || exit 2; shift; done; } +eval ${preload:-preload} ea +[ -n "${preload+-}" ] || sc "$@" diff --git a/sh/scramble b/sh/scramble index 837d75b..d0f4edb 100755 --- a/sh/scramble +++ b/sh/scramble @@ -18,4 +18,4 @@ scramble() { ### @- -e 's/@//g' } -[ "${SOURCING:-0}" -gt 0 ] || scramble "$@" +[ -n "${preload+-}" ] || scramble "$@" diff --git a/sh/screeny b/sh/screeny index ecb330e..01aa929 100755 --- a/sh/screeny +++ b/sh/screeny @@ -17,4 +17,4 @@ screeny() { ### @- return 0 } -[ "${SOURCING:-0}" -gt 0 ] || screeny "$@" +[ -n "${preload+-}" ] || screeny "$@" diff --git a/sh/scropt b/sh/scropt index 2a7cf64..e759de9 100755 --- a/sh/scropt +++ b/sh/scropt @@ -1,10 +1,6 @@ #!/usr/bin/env bash # YES_ZSH -#: $((SOURCING+=1)) -#. ~/sh/now # FIXME: don't do this? -#: $((SOURCING-=1)) - scropt() { ### @- ### run `scrot` through `optipng` and save the result to `~/play/$(now).png`. ### @@ -18,4 +14,6 @@ scropt() { ### @- [ $? -eq 0 ] && echo "$fn" || return $? } -[ "${SOURCING:-0}" -gt 0 ] || scropt "$@" +preload() { local preload='set -- $@'; while [ $# -gt 0 ]; do . ~/sh/$1 || exit 2; shift; done; } +eval ${preload:-preload} now +[ -n "${preload+-}" ] || scropt "$@" diff --git a/sh/similar b/sh/similar index f1e0297..cba1231 100755 --- a/sh/similar +++ b/sh/similar @@ -20,4 +20,4 @@ similar() { ### @- }' } -[ "${SOURCING:-0}" -gt 0 ] || similar "$@" +[ -n "${preload+-}" ] || similar "$@" diff --git a/sh/slit b/sh/slit index e320980..eef39be 100755 --- a/sh/slit +++ b/sh/slit @@ -12,4 +12,4 @@ slit() { ### @- #awk "{ print ${(j:,:):-\$${^@}} }" } -[ "${SOURCING:-0}" -gt 0 ] || slit "$@" +[ -n "${preload+-}" ] || slit "$@" diff --git a/sh/slitt b/sh/slitt index 7f860ee..ef6cafd 100644 --- a/sh/slitt +++ b/sh/slitt @@ -15,4 +15,4 @@ slitt() { ### @- #awk "BEGIN { FS=\"\\t\"; OFS=\"\\t\" } { print ${(j:,:):-\$${^@}} }" } -[ "${SOURCING:-0}" -gt 0 ] || slitt "$@" +[ -n "${preload+-}" ] || slitt "$@" diff --git a/sh/sram b/sh/sram index a9c98e9..fa0e1f2 100755 --- a/sh/sram +++ b/sh/sram @@ -49,4 +49,4 @@ sram() { ### @- revend "$out" } -[ "${SOURCING:-0}" -gt 0 ] || sram "$@" +[ -n "${preload+-}" ] || sram "$@" diff --git a/sh/stfu b/sh/stfu index 70dbb39..03f1f58 100644 --- a/sh/stfu +++ b/sh/stfu @@ -1,9 +1,6 @@ #!/usr/bin/env sh # YES_ZSH -#. ~/sh/echo2 # FIXME -#. ~/sh/note # FIXME - stfu() { ### @- ### invoke a command, silencing stdout and stderr *unless* the command fails. ### @@ -44,8 +41,8 @@ stfu() { ### @- ### WARNING: The system cannot find the file specified. ### asses ### ``` - [ $# -gt 0 ] || { printf "%s\n" "$0: too few arguments" >&2; return 1; } + local temp="${TMP:-/tmp}/stfu" local time="$(date -u '+%s')" @@ -77,4 +74,6 @@ stfu() { ### @- return $ret } -[ "${SOURCING:-0}" -gt 0 ] || stfu "$@" +preload() { local preload='set -- $@'; while [ $# -gt 0 ]; do . ~/sh/$1 || exit 2; shift; done; } +eval ${preload:-preload} echo2 note +[ -n "${preload+-}" ] || stfu "$@" diff --git a/sh/sum b/sh/sum index c8e50d0..8240c1e 100644 --- a/sh/sum +++ b/sh/sum @@ -20,4 +20,4 @@ sum() { ### @- echo "$sum" } -[ "${SOURCING:-0}" -gt 0 ] || sum "$@" +[ -n "${preload+-}" ] || sum "$@" diff --git a/sh/sv b/sh/sv index 87fa260..34ed200 100755 --- a/sh/sv +++ b/sh/sv @@ -36,4 +36,4 @@ sv() { ### @- ' } -[ "${SOURCING:-0}" -gt 0 ] || sv "$@" +[ -n "${preload+-}" ] || sv "$@" diff --git a/sh/tpad b/sh/tpad index 2aee5ca..c07a518 100755 --- a/sh/tpad +++ b/sh/tpad @@ -11,4 +11,4 @@ tpad() { ### @- done } -[ "${SOURCING:-0}" -gt 0 ] || tpad "$@" +[ -n "${preload+-}" ] || tpad "$@" diff --git a/sh/trash b/sh/trash index 898cadc..c0418e0 100644 --- a/sh/trash +++ b/sh/trash @@ -14,4 +14,4 @@ trash() { ### @- dd status=none if=/dev/random bs=1 count="${1:?missing count argument}" } -[ "${SOURCING:-0}" -gt 0 ] || trash "$@" +[ -n "${preload+-}" ] || trash "$@" diff --git a/sh/trunc b/sh/trunc index bdff60d..3a32ec1 100755 --- a/sh/trunc +++ b/sh/trunc @@ -18,4 +18,4 @@ trunc() { ### @- awk -vL=${1:-$COLUMNS} '{e=length>L?"…":"";print substr($0,0,L-(e?1:0)) e}' } -[ "${SOURCING:-0}" -gt 0 ] || trunc "$@" +[ -n "${preload+-}" ] || trunc "$@" diff --git a/sh/unscreen b/sh/unscreen index 2116ca5..c2d428a 100755 --- a/sh/unscreen +++ b/sh/unscreen @@ -14,4 +14,4 @@ unscreen() { ### @- return 0 } -[ "${SOURCING:-0}" -gt 0 ] || unscreen "$@" +[ -n "${preload+-}" ] || unscreen "$@" diff --git a/sh/wat b/sh/wat index da4bd15..42a90ff 100644 --- a/sh/wat +++ b/sh/wat @@ -37,4 +37,4 @@ wat() { ### @- ) } -[ "${SOURCING:-0}" -gt 0 ] || wat "$@" +[ -n "${preload+-}" ] || wat "$@" diff --git a/sh/wipe b/sh/wipe index edc0052..6a2a017 100644 --- a/sh/wipe +++ b/sh/wipe @@ -21,4 +21,4 @@ wipe() { ### @- echo $'\033[0m\n' | tr -d '$' } -[ "${SOURCING:-0}" -gt 0 ] || wipe "$@" +[ -n "${preload+-}" ] || wipe "$@" diff --git a/sh/xxp b/sh/xxp index 6da8d90..76b73ca 100644 --- a/sh/xxp +++ b/sh/xxp @@ -20,4 +20,4 @@ xxp() { ### @- hexdump -e '15 1 "%02X " 1 1 " %02X\n"' -- "$@" } -[ "${SOURCING:-0}" -gt 0 ] || xxp "$@" +[ -n "${preload+-}" ] || xxp "$@"