Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: A way to untie -T vars?
- X-seq: zsh-users 28759
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: Roman Perepelitsa <roman.perepelitsa@xxxxxxxxx>
- Cc: Pier Paolo Grassi <pierpaolog@xxxxxxxxx>, Zsh Users <zsh-users@xxxxxxx>
- Subject: Re: A way to untie -T vars?
- Date: Mon, 23 Jan 2023 21:45:26 -0800
- Archived-at: <https://zsh.org/users/28759>
- In-reply-to: <CAH+w=7bzka=NBZ1SGRt7Fj65KuC3mmH99E8uyCn=Ff=uFaM58w@mail.gmail.com>
- List-id: <zsh-users.zsh.org>
- References: <CAKc7PVDEmKnY9TiYwaAgvzXEqNhLwZo46paUPjJOz9HsU3_djg@mail.gmail.com> <CAH+w=7YY5F_ZYJgivw9PSjt8PTQ9R+gHF3jnjbBw-LLkEnc2zg@mail.gmail.com> <CAH+w=7bL4txwLp4zFPeDvb6fbYfJV6-mT+S4oFnrJ7cXPZr_Xw@mail.gmail.com> <CAH+w=7a1RHjYSGnY2=dgZn9n1ZgC2PyJQ12imiDU4gLW4q4saA@mail.gmail.com> <CAN=4vMpo9i5qr-HmH2ymaxaJ6hQLg-gThZkSRJvafUEp1oN0ag@mail.gmail.com> <CAP+y1xAJq6TrkbTOSFNs=jbf7_=sTYnj3Y1=qHoF5W4S1r=Zkg@mail.gmail.com> <CAN=4vMq56vaLYud4uX86c_fJOtuAHALGXvDqEb7fEB1-=Ec5ug@mail.gmail.com> <CAH+w=7biHnWJV1=Cxd20xzikc9hk7037Rn4EwLenvyHsiQifmQ@mail.gmail.com> <CAN=4vMpQRirh_m_-G3RQH7fxsMbs=Yh7biuXUbypzMmKG=Q3sg@mail.gmail.com> <CAH+w=7bzka=NBZ1SGRt7Fj65KuC3mmH99E8uyCn=Ff=uFaM58w@mail.gmail.com>
On Mon, Jan 23, 2023 at 10:27 AM Bart Schaefer
<schaefer@xxxxxxxxxxxxxxxx> wrote:
>
> array local left justified 10 zero filled 10 uppercase tagged unique
> tied FOO foo
>
> (plus export, hide, and hideval, which typeset +m does not display)
Minor correction: typeset +m does output "exported" for scalars, but
not for arrays even when tied to an exported scalar.
> Pondering.
I've reached the conclusion that "local" makes no difference here. If
any calling scope has declared the parameter local, it will remain
local to that scope even if unset, and the dynamic scope behavior of
"typeset -g" from inside "untie" will apply to the variable in that
scope.
Also, per the other thread, there's no way to get the justification
width for -L/-R/-Z without using typeset +m so that's what I've done.
Since -L and -Z may be specified together, I've made two calls to
typeset +m, the gyrations to reduce it to a single call seemed even
more confusing than the hoops necessary to shuffle all the switches
through the positional parameters.
Attached this time because I'm sure gmail would maim it. This has
been tested with convoluted cases, but not with simple ones, so it may
still need refinement.
untie () {
emulate -L zsh -o extendedglob -o errreturn
while ((ARGC))
do
() {
case ${(tP)1} in
(*right_zeros*) set -- $1 -Z${${(M@)$(typeset +m $1):#[[:digit:]]#}[1]} ;;
esac
case ${(tP)1} in
(*left*) set -- "$@" -L${${(M@)$(typeset +m $1):#[[:digit:]]#}[1]} ;;
(*right_blanks*) set -- "$@" -R${${(M@)$(typeset +m $1):#[[:digit:]]#}[1]} ;;
esac
if [[ ${(tP)1} = *export* ]]
then
set -- $1 -x ${argv[2,$#]}
else
set -- $1 -g ${argv[2,$#]}
fi
set ${(s:-:tP)1} - $1 ${argv[2,$#]}
while [[ $1 != - ]]
do
case $1 in
(tag) set -- "$@" -t ;;
(unique) set -- "$@" -U ;;
(upper) set -- "$@" -u ;;
(lower) set -- "$@" -l ;;
(hide) set -- "$@" -h ;;
(hideval) set -- "$@" -H ;;
esac
shift
done
shift
case ${(tP)1} in
(array*tied*) set -- $1 $# "$@" $1 "${(@P)1}"
unset $1
typeset -a ${argv[4,$2+2]} $1
shift $2+2
set -A "$@" ;;
(scalar*tied*) set -- "$@" $1=${(P)1}
unset $1
shift
typeset "$@" ;;
(*tied*) print -u2 -r "Can't untie ${(qqq)1}: ${(tP)1}" ;;
(*) : "${1}: not a tied parameter" ;;
esac
} $1
shift
done
}
Messages sorted by:
Reverse Date,
Date,
Thread,
Author