zsh-workers
 help / color / mirror / code / Atom feed
From: Arseny Maslennikov <arseny@altlinux.org>
To: Zsh hackers list <zsh-workers@zsh.org>
Subject: Re: Rewrite of zsh-newuser-install (Mikael's subthread)
Date: Wed, 7 Apr 2021 23:08:31 +0300	[thread overview]
Message-ID: <YG4RP8hDZCVUiQdU@cello> (raw)
In-Reply-To: <CAHYJk3RUX6MyFB7o2WFE=P0-=QQ=gv49Z3VTyu+9Zm9fzmoB4A@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 4191 bytes --]

On Wed, Apr 07, 2021 at 08:15:18PM +0200, Mikael Magnusson wrote:
> On 4/7/21, Marlon <marlon.richert@gmail.com> wrote:
> >
> >> On 5. Apr 2021, at 22.44, Mikael Magnusson <mikachu@gmail.com> wrote:
> >>
> >> On 4/5/21, Marlon Richert <marlon.richert@gmail.com> wrote:
> >>> #
> >>> # Type `zrestart` to safely apply changes after editing this file.
> >>> #
> >>> zrestart() {
> >>>  local zshrc=${ZDOTDIR:-$HOME}/.zshrc
> >>>  print -P "Validating %U$zshrc%u..."
> >>>  zsh -nf $zshrc ||
> >>>    return
> >>>
> >>>  print -P 'Restarting Zsh...'
> >>>  zsh -l &&
> >>>    exit
> >>> }

There are two problems with `zsh -l && exit':
1) every zrestart invocation as written consumes PID space (so not
really a restart);
2) if the last job of the last zsh in a zrestart chain has a non-zero
exit status (e. g. WIFSIGNALED or falsey), and that zsh is ordered to
exit, it will return that exit status, breaking the zrestart chain. The
user would likely interpret this as "wow, my ^D doesn't work!".

I don't know how to write zrestart in plain zsh robustly enough to be
worthy of inclusion in the default .zshrc. Personally I just do
    alias zz='exec zsh'
or
    alias ZZ='exec zsh'
and that's it, but that's too minimalistic for a newbie tool.

> >>
> >> This could be an autoloadable function, not pasted verbatim in .zshrc.
> >> Also disagree with -l here. You can use $options[login] or $- to see
> >> if you're in a login shell already and start same. Things like this we
> >> can't fix after users already copy this config. It should try to
> >> mostly be configuration, not helper functions that can have permanent
> >> flaws once installed.
> >
> > Sure, I can move it to an autoloadable function. That’s fine by me. I did
> > not come up with the -l, though. Earlier in the thread, Oliver & Bart didn’t
> > like using `exec zsh` and offered this instead. See
> > [48031](https://www.zsh.org/mla/workers/2021/msg00244.html). I’d be happy to
> > change it, but I don’t know how they feel about it.
> 
> You could also just have a comment saying something to the effect of
> "changes to this file will only take effect in new shells, you can
> either open a new terminal or type "zsh" in an existing terminal". I
> guess I don't care too much either way after all.
<...>
> >>> # Auto-save last 20 dirs to file whenever we change dirs.
> >>> # See
> >>> http://zsh.sourceforge.net/Doc/Release/User-Contributions.html#Recent-Directories
> >>> autoload -Uz add-zsh-hook chpwd_recent_dirs
> >>> add-zsh-hook chpwd chpwd_recent_dirs
> >>> zstyle ':chpwd:*' recent-dirs-file ${ZDOTDIR:-$HOME}/.chpwd-recent-dirs
> >>>
> >>> # On startup, initialize dir stack from file.
> >>> autoload -Uz chpwd_recent_filehandler
> >>> chpwd_recent_filehandler
> >>> cd $reply[1]
> >>> dirs $reply[@] >/dev/null
> >>
> >> Does this start zsh in some other directory than it inherited from the
> >> terminal? If so, nak from me on that, way too surprising.
> >
> > It makes the shell pick up in the same dir as where you left off last time.
> > I would hardly call that surprising. In fact, I would pretty much call that
> > _expected_ for most applications nowadays.
> 
> I think most people on the list will strongly disagree with you here.

Oh yes. When I was giving my (mostly positive or indifferent) feedback
to Marlon privately on his request, I just ignored this part about
dirstack at all, since I neither use it nor care about it.

Making the shell chdir to a different directory every time is incredibly
unintuitive to most Unix shell users.
The runtime state restore functionality expected from applications does not
apply here at all, because the shell is not an application, but a power
tool.
To expand on this: while a running application is usually a
singleton in a given system, it's not uncommon for people to run about
10-15 fully independent shells for different tasks simultaneously.
Consider the user logs out from such a session and then logs back in —
the next shell they start will chdir to a directory last changed to by
those 15 shells, and that directory is hard to keep track of.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

  parent reply	other threads:[~2021-04-07 20:08 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-05 19:44 Mikael Magnusson
2021-04-05 21:01 ` Mikael Magnusson
2021-04-05 21:44 ` Bart Schaefer
2021-04-07 13:44   ` Marlon
2021-04-07 16:24     ` Daniel Shahaf
2021-04-10 11:23       ` Marlon
2021-04-10 20:46         ` dana
2021-04-10 21:41           ` Bart Schaefer
2021-04-10 22:03             ` Roman Perepelitsa
2021-04-11 11:38               ` Marlon Richert
2021-04-13 14:49               ` Daniel Shahaf
2021-04-13 14:55           ` Daniel Shahaf
2021-04-07 14:28 ` Marlon
2021-04-07 15:14   ` Daniel Shahaf
2021-04-07 16:36   ` Bart Schaefer
2021-04-07 18:15   ` Mikael Magnusson
2021-04-07 18:50     ` Daniel Shahaf
2021-04-07 20:08     ` Arseny Maslennikov [this message]
2021-04-09 20:07     ` Marlon
2021-04-09 22:04       ` Oliver Kiddle
2021-04-09 23:04         ` Daniel Shahaf
2021-04-09 23:55           ` Bart Schaefer
2021-04-13 15:00             ` Daniel Shahaf
2021-04-09 23:08         ` Bart Schaefer
2021-04-10  7:44           ` Roman Perepelitsa
2021-04-09 23:23       ` Mikael Magnusson
2021-04-10  7:45         ` Marlon Richert
2021-04-09 15:29   ` Marlon

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=YG4RP8hDZCVUiQdU@cello \
    --to=arseny@altlinux.org \
    --cc=zsh-workers@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).