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

Re: Rewrite of zsh-newuser-install (Mikael's subthread)



Mikael Magnusson wrote on Wed, 07 Apr 2021 18:15 +00:00:
> On 4/7/21, Marlon <marlon.richert@xxxxxxxxx> wrote:
> >> On 5. Apr 2021, at 22.44, Mikael Magnusson <mikachu@xxxxxxxxx> wrote:
> >> On 4/5/21, Marlon Richert <marlon.richert@xxxxxxxxx> wrote:
> >>> # 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.

Yes and no.  On the one hand, "start in the cwd of the shell last
closed" would just get in my way: if I close an xterm on virtual desktop
2, switch to virtual desktop 3, and pop open a new xterm, I'd rather it
opened in ~ then in the cwd of the shell I just closed.

On the other hand, one of the things I miss since I migrated from
xfce4-terminal to «tabbed -c xterm -into» (from suckless-tools) is that the
former would default new tabs to the cwd of whatever command was running
in the tab in focus.  That guess wasn't always right, because it used
(IIRC) the cwd of the "top-most" (process tree -wise) shell in the tab
even if from that shell I ran zsh/vim/tmux and that process's cwd was
different, but in general, if I wanted the default of ~ it was easy
enough to just type «cd» and move on.

But even then, the default cwd wasn't some "global" thing; it was the
cwd of the tab in focus.  cwd's of other tabs, or of tabs in other
xfce4-terminal windows, wouldn't factor in.

So, if there was some way to say "Look up the process tree to the thing
I'm in" — be that a tmux session, a tabbed terminal emulator window,
a virtual desktop (in the `wmctrl -d` sense), etc. — and use that as the
default cwd of new processes, I might use that…

… but that's not going to be easy to get right, and in any case I amn't
going as far as to say it'd be good for the default zshrc.  It's stateful
magic.  If anything, it sounds like something that should be handled
outside zsh, by having whatever invokes zsh cd() before exec()ing.

Cheers,

Daniel




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