Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: A way to untie -T vars?



On Sun, Jan 22, 2023 at 1:58 AM Roman Perepelitsa
<roman.perepelitsa@xxxxxxxxx> wrote:
>
> If you wanted to turn this into a library function, you would need to
> handle more types.

So ... (gmail is probably going to line-wrap this)

untie () {
  emulate -L zsh
  while ((ARGC))
  do
    () {
      case ${(tP)1} in
        (array-tied) set -- $1 "${(@P)1}"
          unset $1
          set -A "$@" ;;
        (scalar-tied-export) set -- $1 x ;&
        (scalar-tied) set -- $1 ${(P)1} $2
          unset $1
          typeset -g$3 $1=$2 ;;
        (*tied*) print -u2 -r "Can't untie ${(qqq)1}: ${(tP)1}" ;;
        (*) : "${(qqq)1}: not a tied parameter" ;;
      esac
    } $1
    shift
  done
}

The (*) label is for benefit of xtrace, but it could instead print
that message.  I couldn't find any other parameter types that needed
handling?

That's "functions -x2" output, by the way, take it up with PWS if you
don't like the placement of the case labels/delimiters.




Messages sorted by: Reverse Date, Date, Thread, Author