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

Re: unshift



On Mon, Apr 1, 2024 at 3:52 PM Ray Andrews <rayandrews@xxxxxxxxxxx> wrote:
>
> Can we unshift the positional params?

That's an interesting challenge. A start:

  alias shift='emulate zsh -o typeset_silent -c "local -a _shift_a _shift_n"
               _shift_a+=("$@")
               _shift_n+=(-$#)
               shift'

  alias unshift='set -- "${(@)_shift_a[_shift_n[-1],-1]}"
                 _shift_a[_shift_n[-1],-1]=()
                 _shift_n[-1]=()'

unshift undoes the last call to `shift [ -p ] [ n ]`. I think (not
entirely sure) that it works with all options. Unfortunately, it does
not work for `shift [ -p ] [ n ] name ...`.

Roman.




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