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

Re: Please implement auto-handling of ${HOME}/.zsh/


On Wed, Mar 20, 2013 at 07:16:39PM +0000, Larry Schrof wrote:
> I have been dying for this for many years.  I have a ton of zsh configs,
> so I like to organize them in ~/.zsh/,

Same here.

> but here's the problem.

I actually don't see it as problem, though. Works fine here with a
minimal implementation. Nevertheless I'd be happy to see this being
part of zsh officially to reduce dot file clutter in my ~/ and to make
the zsh config more VCS-suitable.

> First, I have to create a symlink ~/.zshenv and point it to ~/.zsh/.zshenv

Same here, except that I use ~/.zsh/zshenv and hence have a symlink
.zsh/.zshrc → .zsh/zshrc.

> Then, as the first thing to do in ~/.zsh/.zshenv, I have to do:
>    export ZDOTDIR=${HOME}/.zsh


> This is janky and is messier than it needs to be.

IMHO that's a very small "workaround". Could be way messier.

> It would be awesome if something like the following happened. Forgive me
> if the implementation is flawed; just note the spirit of my suggestion.
> - Before zsh begins to process the first user-based config file
>   (I believe ~/.zshenv), look for the existence of ~/.zsh/ (a directory).
> - If this directory does not exist, proceed normally. (Start reading
> ~/.zshenv)
> - If this directory DOES exist:
> ---> Automatically set ZDOTDIR to ${HOME}/.zsh/
> ---> Ignore any ~/.zsh* files (If the user is using ~/.zsh/ it's their job

Why not concatenating them? That's what I'd have expected in a first
run. Then, after some thinking, I see that your suggestion potentially
makes sense, too.

Anyway, +1 for the basic idea.

On Wed, Mar 20, 2013 at 10:41:52PM -0700, Bart Schaefer wrote:
> } First, I have to create a symlink ~/.zshenv and point it to ~/.zsh/.zshenv
> } Then, as the first thing to do in ~/.zsh/.zshenv, I have to do:
> }    export ZDOTDIR=${HOME}/.zsh
> Why not create a ~/.zshenv that does
>     export ZDOTDIR=${HOME}/.zsh
>     source $ZDOTDIR/.zshenv
> and forget about the symlinks?

Because you than have to create that file and store its content
elsewhere. But you need to have that file around anyway for that, so
symlinking seems the easier variant, at least if you have ~/.zsh/
under version control.

> Like TJ, I have a common set of config files stored on the web.  (Not
> in Dropbox, in a source repository from which I check out to ~/.zsh,
> but it's the same idea.)  One of the files in that repository is a
> script called ".installer" which writes something much like the above
> into ~/.zshenv (with a warning if that would clobber an existing file,
> etc.).  I haven't yet needed to, but I've considered having .installer
> also write bash init files that exec zsh if zsh is not in /etc/shells.

I use .$DOTDIR/bin/setup-symlinks.sh for that purpose in a bunch of
gitified dotdirs (including my .xsession), but that's more or less the
same (with the exception that I prefer symlinks, of course).

> So on any new host, I just check out the .zsh directory, run .installer,
> resolve a conflict if it reports one, and I'm done.

git clone … + .$DOTDIR/bin/setup-symlinks.sh

(Plan is to use mr in the future to clone all relevant dot dirs at
once the way RichiH does..)

On Wed, Mar 20, 2013 at 04:55:09PM -0400, Paul Hoffman wrote:
> Interesting, but some people (well, *I*) have already organized their 
> ~/.zsh/* differently and this change would break things.

Well, yeah, me, too, because I use ~/.zsh/zshenv and ~/.zsh/zshrc
because I dislike dot files inside dot dirs. But then again, I'd still
happy if that would become an official zsh feature and I'd change my
setup for that.

> I hope it isn't -- IMNSHO janky is better than something that might 
> break things and that would complicate the already complicated startup 
> process (and add to its long and complicated documentation).

I think it's worth it. And automatically setting $ZDOTDIR isn't very
complicated, neither to implement nor to document. The only more
complicated thing would be that, if $ZDOTDIR is set, it would look for
$ZDOTDIR/zshenv and $ZDOTDIR/zshrc, too (or only, see below).

On Wed, Mar 20, 2013 at 08:54:22PM +0100, Moritz Bunkus wrote:
> I'd love to have this, but two things that could be made even better
> in my opinion:
> 1. Check $XDG_CONFIG_HOME/zsh as well as ~/.zsh. The former is from
> the XDG Base Directory Specification[1] which I'd love to see zsh
> follow. $XDG_CONFIG_HOME defaults to ~/.config if unset.

Good idea! +1

> 2. If one of those directories exists then look for $that_dir/zshenv
> and not $that_dir/.zshenv. Hiding the files only makes sense for
> $HOME, not for a sub-directory. Same should be true for
> $that_dir/zshrc and the other files.

Yeah, that's my preference, too.

> So my proposal would be:
> - Look for an existing directory $XDG_CONFIG_HOME/zsh (if
> $XDG_CONFIG_HOME is unset assume default $HOME/.config) or $HOME/.zsh
> - If that directory exists set ZDOTDIR to it and read configuration
> files from that directory. The files are not prefixed with .
> - If that directory does not exist then proceed as before: read
> configuration files from $HOME, the files are prefixed with .

+1 for having it work that way.

		Kind regards, Axel
/~\  Plain Text Ribbon Campaign                   | Axel Beckert
\ /  Say No to HTML in E-Mail and News            | abe@xxxxxxxxxxxxxxx  (Mail)
 X   See http://www.asciiribbon.org/              | abe@xxxxxxxxx (Mail+Jabber)
/ \  I love long mails: http://email.is-not-s.ms/ | http://noone.org/abe/ (Web)

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