Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: A way to untie -T vars?
- X-seq: zsh-users 28806
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: Roman Perepelitsa <roman.perepelitsa@xxxxxxxxx>
- Cc: Zsh Users <zsh-users@xxxxxxx>
- Subject: Re: A way to untie -T vars?
- Date: Wed, 25 Jan 2023 18:34:15 -0800
- Archived-at: <https://zsh.org/users/28806>
- In-reply-to: <CAH+w=7Y1CP1tN29LHFC6QxcdDngZVLKEPdr6c3+h8UAXBy2q-Q@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> <CAH+w=7YSr1RjDi3zXAhBg6unDj0gcjG+DKM5BjKVgoVhoP+Rog@mail.gmail.com> <CAN=4vMr19u2KCjKn_=nSaxZ1XOBTASwu5EPdy1fve4FX9XhVRQ@mail.gmail.com> <CAH+w=7bOHTSAat9+eypbb3kVyZofYG+8_NHtXdzBreT2tutpzA@mail.gmail.com> <1801643545.282032.1674578750345@mail.virginmedia.com> <CAH+w=7YYJJxDyFZ20ZJ6FwtFzrsCyHb8tNkMNxBQqWSHRNBfpw@mail.gmail.com> <CAN=4vMor55C9c4vw3vaKzfyx8KuWxMoproVzZ01o2HXGiJzr3g@mail.gmail.com> <CAH+w=7Yt6tj4BjaAmrPGt56AmVm7QdgFL-AMPA8rzpwyQz0hdw@mail.gmail.com> <CAN=4vMrPU+bCb3V84HqUgEeXw82UeMpWCA0Xaw1-z8hG-aksDA@mail.gmail.com> <CAH+w=7axOuFLv-88P7cFD_qVro36FHgmc0ax==Ttxb7wAaNOrA@mail.gmail.com> <CAH+w=7Y1CP1tN29LHFC6QxcdDngZVLKEPdr6c3+h8UAXBy2q-Q@mail.gmail.com>
On Wed, Jan 25, 2023 at 3:48 PM Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
>
> The value being assigned to the variable is coming from $1=${(P)1} and
> ${(P)1} includes the specified justification, so the value assigned is
> always already the correct width.
Which means ${(P)#1} is the justification, no need to fork typeset for
that, and ...
> Is there any other way to reference
> the "real, unfilled" value of a parameter that has justification
> specified?
The only reliable way I can find is to first remove the justification:
% typeset -L5 FOO=123456789
% printf "<%s>\n" $FOO
<12345>
% typeset +L FOO
% printf "<%s>\n" $FOO
<123456789>
This can be done without otherwise changing the type or tied-ness of the scalar.
One more pass at it attached.
untie () {
emulate -L zsh -o extendedglob -o errreturn
while ((ARGC))
do
() {
case -${(tP)1}- in
(*-(readonly|special)-*) print -u2 -r "Can't untie ${(qqq)1}: ${(tP)1}"
return 0 ;;
(*-tied-*) set -- ${(s:-:tP)1} - $1 -g ;;
(*) : "${1}: not a tied parameter"
return 0 ;;
esac
while [[ $1 != - ]]
do
case $1 in
(export) set -- "$@" -x ;;
(tag) set -- "$@" -t ;;
(unique) set -- "$@" -U ;;
(upper) set -- "$@" -u ;;
(lower) set -- "$@" -l ;;
(hide) set -- "$@" -h ;;
(hideval) set -- "$@" -H ;;
(left) set -- "$@" -L${(P)#${@[$@[(i)-]+1]}} ;;
(right_blanks) set -- "$@" -R${(P)#${@[$@[(i)-]+1]}} ;;
(right_zeros) set -- "$@" -Z${(P)#${@[$@[(i)-]+1]}} ;;
esac
shift
done
shift
case -${(tP)1}- in
(*-array-*) set -- $# "$@" $1 "${(@P)1}"
unset $2
typeset -a ${argv[3,$1+1]} $2
shift $1+1
set -A "$@" ;;
(*-scalar-*) typeset -g +L +R +Z $1
set -- "$@" $1=${(P)1}
unset $1
shift
typeset "$@" ;;
(*) print -u2 -r -- "${1}: impossible: ${(tP)1}"
return 1 ;;
esac
} $1
shift
done
}
Messages sorted by:
Reverse Date,
Date,
Thread,
Author