Created
December 6, 2025 05:43
-
-
Save ormaaj/f3b18803ee7307215395e2cecc3194d4 to your computer and use it in GitHub Desktop.
nameref auto-mapper
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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