Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: A way to untie -T vars?
- X-seq: zsh-users 28700
- From: Roman Perepelitsa <roman.perepelitsa@xxxxxxxxx>
- To: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- Cc: Zsh Users <zsh-users@xxxxxxx>
- Subject: Re: A way to untie -T vars?
- Date: Sat, 21 Jan 2023 20:15:07 +0100
- Archived-at: <https://zsh.org/users/28700>
- In-reply-to: <CAH+w=7a1RHjYSGnY2=dgZn9n1ZgC2PyJQ12imiDU4gLW4q4saA@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>
On Sat, Jan 21, 2023 at 7:53 PM Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
>
> Speaking of unorthodoxy ...
>
> untie () {
> emulate -L zsh
> case ${(tP)1} in
> (scalar-tied)
> local scalar=${(P)1}
> unset $1
> typeset -g $1=$scalar
> ;;
> (array-tied)
> local array=( ${(P)1} )
> unset $1
> # Need eval here for array assignment, as
> # reserved word doesn't work with $1=(...)
> eval "typeset -ga $1=( \$array )"
> ;;
> (*) ;;
> esac
> }
Bravo.
`untie scalar` and `untie array` won't work due to name clashes but
this seems easily fixable.
Roman.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author