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

Re: unshift





On 2024-04-01 07:38, Roman Perepelitsa wrote:
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:
Very interesting!  Could it be official?  Maybe not worth it's weight but ...
=================================

   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