zsh-users
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: zsh-users@zsh.org
Subject: Re: unshift
Date: Mon, 1 Apr 2024 12:41:40 -0700	[thread overview]
Message-ID: <CAH+w=7bm5E-PeS1N4X_fpmq6+YLwCJFbmP2z3a4OKeCd7in+Dg@mail.gmail.com> (raw)
In-Reply-To: <4de03717-ebcb-4b85-bc1b-14be0d2cc8c3@eastlink.ca>

On Mon, Apr 1, 2024 at 9:40 AM Ray Andrews <rayandrews@eastlink.ca> wrote:
>
> I've never used shift for anything other than the positionals which is all I'm considering, but if there was an unshift it would obviously have to be globally useful

"Undo the most recent shift" is not how "unshift" is defined in other
languages, e.g., perldoc: "shift" and "unshift" do the same thing to
the left end of an array that "pop" and "push" do to the right end.

If for some reason you don't want to declare a temporary for the old
value of $1, you can also do something like this:

set -- "${(@)argv[2,-1]}" "${argv[1]}"
...
set -- "${argv[-1]}" "${(@)argv[1,-2]}"

That is, rotate the positionals and then rotate them back again.  I
would actually usually do something like

set -- "${(@)argv[2,-1]}" -- "${argv[1]}"
while [[ $1 != -- ]]; do ...; shift; done

but what can be used as a such flag value is context-dependent.


  reply	other threads:[~2024-04-01 19:42 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-01 13:52 unshift Ray Andrews
2024-04-01 13:54 ` unshift Mark J. Reed
2024-04-01 14:00   ` unshift Mark J. Reed
2024-04-01 14:23   ` unshift Ray Andrews
2024-04-01 16:03   ` unshift Stephane Chazelas
2024-04-01 14:38 ` unshift Roman Perepelitsa
2024-04-01 16:11   ` unshift Ray Andrews
2024-04-01 16:20     ` unshift Roman Perepelitsa
2024-04-01 16:40       ` unshift Ray Andrews
2024-04-01 19:41         ` Bart Schaefer [this message]
2024-04-01 22:52           ` unshift Ray Andrews
2024-04-01 16:03 ` unshift Bart Schaefer
2024-04-01 16:30   ` unshift Ray Andrews
2024-04-02 12:41 ` unshift Dennis Eriksen
2024-04-02 14:01   ` unshift Ray Andrews
2024-04-02 19:59     ` unshift Roman Perepelitsa
2024-04-02 20:24       ` unshift Ray Andrews

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAH+w=7bm5E-PeS1N4X_fpmq6+YLwCJFbmP2z3a4OKeCd7in+Dg@mail.gmail.com' \
    --to=schaefer@brasslantern.com \
    --cc=zsh-users@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).