fixes(0.1.1)

- 0-indexing in zsh (see std::sensible)
- hope declare -g doesnt propagate to env, same scope as functions
- fix fallback interpreter exit behavior
This commit is contained in:
2026-06-02 10:18:59 +02:00
parent 983e2f34f7
commit b0d7b4d3bf
+32 -3
View File
@@ -2,9 +2,9 @@ std::bootstrap() {
[ -n "${STD_VERSION:-}" ] && [ -n "${STD_VERSION:-}" ] &&
std::panic "\`std\` ($STD_VERSION) already loaded, can\'t load version $1" std::panic "\`std\` ($STD_VERSION) already loaded, can\'t load version $1"
export STD_VERSION=$1 declare -g STD_VERSION=$1
} }
std::bootstrap 0.1.0 std::bootstrap 0.1.1
INTERPRETER=$(ps -p $$ | awk '$1 != "PID" {print $(NF)}') INTERPRETER=$(ps -p $$ | awk '$1 != "PID" {print $(NF)}')
: "${INTERPRETER:=bash}" : "${INTERPRETER:=bash}"
@@ -24,6 +24,34 @@ std::interpreter::is-ksh() {
[[ "$(std::interpreter::name)" == ksh ]] [[ "$(std::interpreter::name)" == ksh ]]
} }
##
# Adds sensible behavior for some stuff, not called by default because it messes with terms.
#
# Consider enabling it locally with `eval "$(std::sensible)"`
#
# You can pass `global` as the first argument to set settings globally.
##
std::sensible() {
local interpreter
interpreter=$(std::interpreter::name)
case $interpreter in
bash)
;;
zsh)
# stuff like 0-indexing
if [[ "${1:-}" == "global" ]]; then
echo emulate sh
else
echo emulate -L sh
fi
;;
*)
echo "Not sure how to get sourced path for $interpreter" >&2
exit 1
;;
esac
}
std::mod::get-self-path() { std::mod::get-self-path() {
local interpreter local interpreter
interpreter=$(std::interpreter::name) interpreter=$(std::interpreter::name)
@@ -39,7 +67,8 @@ std::mod::get-self-path() {
eval 'realpath -e "$(dirname "${.sh.file}")"' eval 'realpath -e "$(dirname "${.sh.file}")"'
;; ;;
*) *)
echo "Not sure how to get sourced path for $interpreter" echo "Not sure how to get sourced path for $interpreter" >&2
exit 1
;; ;;
esac esac
} }