Skip to content

Instantly share code, notes, and snippets.

@ormaaj
Created December 6, 2025 05:43
Show Gist options
  • Select an option

  • Save ormaaj/f3b18803ee7307215395e2cecc3194d4 to your computer and use it in GitHub Desktop.

Select an option

Save ormaaj/f3b18803ee7307215395e2cecc3194d4 to your computer and use it in GitHub Desktop.
nameref auto-mapper
#!/usr/bin/env bash
shopt -s lastpipe extglob expand_aliases
function unset2 {
unset -v "$@"
}
function getparams {
typeset -a v=v[l]=1+l,v
l=_[_=\${#v[@]}%\$#,0] let v
eval typeset -n -- \
"${v[@]/*/_${sh_level}_&=\$&}" \
"${v[@]/*/r&=_${sh_level}_&}" ||
return
typeset -n r
for r in "${v[@]/#/r}"; do
r+=( "moo ${!r}"{,,,} )
done
}
function m {
local -; set +m
typeset -Gx BASH_COMPAT=51
typeset -A map+=(
[sh_fun]=FUNCNAME
[sh_pid]=BASHPID
[sh_match]=BASH_REMATCH
[sh_level]=_[_=\${#sh_fun[@]},0]
)
set -- "${map[@]@k}"
while
eval typeset -n -- "${1}=\${2}"
command shift -- "$((3${3+-1}))"
do :
done
typeset -p -- "${!map[@]}"
unset2 -v map
set -x
typeset -a v=({a..c})
typeset -a -- "${v[@]}"
getparams "${v[@]}"
typeset -p -- "${v[@]}"
}
m "$@"
# vim: set ft=bash fenc=utf-8 ff=unix ts=4 noet :
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment