zsh-users
 help / color / mirror / code / Atom feed
* do you use separate .zshenv and .zshrc files?
@ 2012-04-28 19:07 TJ Luoma
  2012-04-28 20:54 ` Benjamin R. Haskell
  2012-04-28 23:03 ` Bart Schaefer
  0 siblings, 2 replies; 7+ messages in thread
From: TJ Luoma @ 2012-04-28 19:07 UTC (permalink / raw)
  To: zsh-users

I keep vacillating between wanting to separate my config files into two separate files or keep them in one.

If I understand ZSH correctly, I could use one file (.zshenv) and put the settings which *would* have been in .zshrc into a block like this:

if [[ -o login ]]
then
# do stuff which would have been in .zshrc here
fi

The reason for doing this is that I tend to forget which file has whatever thing it is that I want to tweak/edit/change/add, and so I end up having to open one, search for what I'm looking for, realize it's in the other file, and then open the other file.

ISTM that it would be easier to just keep everything in one file and separate the login stuff using the `if` statement above.

Are there any drawbacks to that method?




^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: do you use separate .zshenv and .zshrc files?
  2012-04-28 19:07 do you use separate .zshenv and .zshrc files? TJ Luoma
@ 2012-04-28 20:54 ` Benjamin R. Haskell
  2012-04-28 21:01   ` Benjamin R. Haskell
  2012-04-28 21:57   ` TJ Luoma
  2012-04-28 23:03 ` Bart Schaefer
  1 sibling, 2 replies; 7+ messages in thread
From: Benjamin R. Haskell @ 2012-04-28 20:54 UTC (permalink / raw)
  To: TJ Luoma; +Cc: zsh-users

On Sat, 28 Apr 2012, TJ Luoma wrote:

> I keep vacillating between wanting to separate my config files into 
> two separate files or keep them in one.

My config currently spans 19 files, so my bias should be apparent.  I 
keep everything in ~/.zsh/, except for machine-specific settings, which 
I put in ~/.zsh.local/.  And ~/.zshenv is a symlink to ~/.zsh/.zshenv, 
which sets ZDOTDIR to ~/.zsh.  My ~/.zsh/.zshrc sources the other files 
in ~/.zsh/, most of which have some guard at the top (e.g. 
~/.zsh/.zsh_screen returns if the `screen` command isn't installed).


> If I understand ZSH correctly, I could use one file (.zshenv) and put 
> the settings which *would* have been in .zshrc into a block like this:
>
> if [[ -o login ]]

You want 'interactive' here, not 'login':
if [[ -o interactive ]]


> then
> # do stuff which would have been in .zshrc here
> fi


[[ -o login ]] would catch things that would be done in .zprofile and 
.zlogin, not those that are done in .zshrc.


> The reason for doing this is that I tend to forget which file has 
> whatever thing it is that I want to tweak/edit/change/add, and so I 
> end up having to open one, search for what I'm looking for, realize 
> it's in the other file, and then open the other file.
>
> ISTM that it would be easier to just keep everything in one file and 
> separate the login stuff using the `if` statement above.

As pointed out above .zshenv vs .zshrc isn't a difference of "login" vs. 
not.  It's "interactive" vs. not.

Here's the order of the standard four files, and the condition under 
which they run:

.zshenv: (always)
.zprofile: [[ -o login ]]
.zshrc: [[ -o interactive ]]
.zlogin: [[ -o login ]]

To disable all of them, there is the 'NO_RCS' option.

Personally, I don't use .zprofile or .zlogin, because all of my 
customization outside of .zshenv is only applicable to interactive 
shells.


> Are there any drawbacks to that method?

None that I know of.  If that's how you prefer to organize it, it should 
work fine.

-- 
Best,
Ben


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: do you use separate .zshenv and .zshrc files?
  2012-04-28 20:54 ` Benjamin R. Haskell
@ 2012-04-28 21:01   ` Benjamin R. Haskell
  2012-04-28 21:57   ` TJ Luoma
  1 sibling, 0 replies; 7+ messages in thread
From: Benjamin R. Haskell @ 2012-04-28 21:01 UTC (permalink / raw)
  To: TJ Luoma; +Cc: zsh-users

On Sat, 28 Apr 2012, Benjamin R. Haskell wrote:

> Here's the order of the standard four files, and the condition under which 
> they run:
>
> .zshenv: (always)
> .zprofile: [[ -o login ]]
> .zshrc: [[ -o interactive ]]
> .zlogin: [[ -o login ]]
>
> To disable all of them, there is the 'NO_RCS' option.

For completeness:  Those are the standard four personal startup files. 
I tend to ignore systemwide files, because I put 'set -o no_global_rcs' 
in my .zshenv.  (I've too often found that the systemwide files just 
contain distribution-specific crap that conflicts with my own settings.)

For a more in-depth discussion see the 'STARTUP/SHUTDOWN FILES' section 
in `man 1 zsh`.

-- 
Best,
Ben


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: do you use separate .zshenv and .zshrc files?
  2012-04-28 20:54 ` Benjamin R. Haskell
  2012-04-28 21:01   ` Benjamin R. Haskell
@ 2012-04-28 21:57   ` TJ Luoma
  2012-04-28 22:25     ` Benjamin R. Haskell
  1 sibling, 1 reply; 7+ messages in thread
From: TJ Luoma @ 2012-04-28 21:57 UTC (permalink / raw)
  To: Benjamin R. Haskell; +Cc: zsh-users



On Saturday, April 28, 2012 at 4:54 PM, Benjamin R. Haskell wrote:

> My config currently spans 19 files, so my bias should be apparent. I
> keep everything in ~/.zsh/, except for machine-specific settings, which
> I put in ~/.zsh.local/. And ~/.zshenv is a symlink to ~/.zsh/.zshenv,
> which sets ZDOTDIR to ~/.zsh. My ~/.zsh/.zshrc sources the other files
> in ~/.zsh/, most of which have some guard at the top (e.g.
> ~/.zsh/.zsh_screen returns if the `screen` command isn't installed).

Ok, now I'm curious: 

1. What are the 19 files? Functions in one, aliases in another, variables in another? I can't even imagine that many different files, but maybe I'm missing something.

2. Are you primarily using one computer or several?  If several, how do you keep this in sync?

FWIW my ~/.zshenv and ~/.zshenv are links to ~/Dropbox/etc/Zsh/env.sh and ~/Dropbox/etc/Zsh/rc.sh but I have some shell accounts which I can't sync via Dropbox so I end up syncing them manually (scp) and it always seems like one file would be easier there too. OTOH I suppose rsync would be easy enough.

TjL




^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: do you use separate .zshenv and .zshrc files?
  2012-04-28 21:57   ` TJ Luoma
@ 2012-04-28 22:25     ` Benjamin R. Haskell
  0 siblings, 0 replies; 7+ messages in thread
From: Benjamin R. Haskell @ 2012-04-28 22:25 UTC (permalink / raw)
  To: TJ Luoma; +Cc: zsh-users

On Sat, 28 Apr 2012, TJ Luoma wrote:

>
>
> On Saturday, April 28, 2012 at 4:54 PM, Benjamin R. Haskell wrote:
>
>> My config currently spans 19 files, so my bias should be apparent. I
>> keep everything in ~/.zsh/, except for machine-specific settings, which
>> I put in ~/.zsh.local/. And ~/.zshenv is a symlink to ~/.zsh/.zshenv,
>> which sets ZDOTDIR to ~/.zsh. My ~/.zsh/.zshrc sources the other files
>> in ~/.zsh/, most of which have some guard at the top (e.g.
>> ~/.zsh/.zsh_screen returns if the `screen` command isn't installed).
>
> Ok, now I'm curious:
>
> 1. What are the 19 files? Functions in one, aliases in another, 
> variables in another? I can't even imagine that many different files, 
> but maybe I'm missing something.

Note that I didn't say my bias was "correct", only "apparent".  ;-)

It's mostly from inertia that I still keep my config in that many files, 
but here they are (I miscounted -- only 18):

.zsh_aliases - one-liners: aliases, hash -d, some tiny functions
.zsh_checkconfig - alerts me when certain commands/non-zsh configs are missing (e.g. .screenrc)
.zsh_colors - (obsolete) sets some vars to contain VT100 escape sequences
.zsh_completion - completion-system-specific configuration
.zsh_functions - functions of >1 line, simple perl scripts
.zsh_history_setup - history-related options
.zsh_im - sets up X11 Input Method (IM)
.zsh_locale - my locale settings (en_US.UTF-8 except LC_COLLATE=POSIX)
.zsh_make_backups - backs up my .historyfile and a few other files daily
.zsh_math - (rarely used) some small functions/vars relating to math
.zsh_nosefart - small functions for nosefart (an NES sound file player)
.zsh_prompt - sets up my prompt (lots of custom functions)
.zsh_screen - some functions and aliases for using screen/dtach
.zsh_ssh - set up my SSH agent
.zsh_ssh_logip - log my IP if logging in via SSH
.zsh_svn_backup - (obsolete - from when I was using SVN rather than git)
.zshenv - environment variables, paths, etc.
.zshrc - command_not_found_handler, env vars that only make sense 
interactively ($LESS, $PAGER, $EDITOR), general Zsh settings, loads the 
other files (including things in .zsh.local, if it exists)


> 2. Are you primarily using one computer or several?  If several, how 
> do you keep this in sync?

I generally have a work PC and a home PC.  I keep both of those configs 
in git, occasionally cherry-picking things from the work repo into my 
home repo.  For systems where I won't likely make many modifications, I 
generally just rsync to the remote system.  Then custom things go in 
.zsh.local (e.g. .zsh.local/.zsh_prompt always contains a custom prompt 
color).  For small synchronization tasks, I use a function that calls 
vimdiff on the local and remote files.


> FWIW my ~/.zshenv and ~/.zshenv are links to ~/Dropbox/etc/Zsh/env.sh 
> and ~/Dropbox/etc/Zsh/rc.sh but I have some shell accounts which I 
> can't sync via Dropbox so I end up syncing them manually (scp) and it 
> always seems like one file would be easier there too. OTOH I suppose 
> rsync would be easy enough.

Yeah.  At the rate I make modifications (infrequently, and usually in 
batches), I find it's easy enough to just:

rsync -av ~/.zsh remote-machine:

-- 
Best,
Ben


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: do you use separate .zshenv and .zshrc files?
  2012-04-28 19:07 do you use separate .zshenv and .zshrc files? TJ Luoma
  2012-04-28 20:54 ` Benjamin R. Haskell
@ 2012-04-28 23:03 ` Bart Schaefer
  2012-04-28 23:19   ` TJ Luoma
  1 sibling, 1 reply; 7+ messages in thread
From: Bart Schaefer @ 2012-04-28 23:03 UTC (permalink / raw)
  To: zsh-users

On Apr 28,  3:07pm, TJ Luoma wrote:
}
} ISTM that it would be easier to just keep everything in one file and
} separate the login stuff using the `if` statement above.
}
} Are there any drawbacks to that method?

In addition to the items other have mentioned ...

If you have a lot of configuration it may take somewhat longer to parse
and execute the one big file when all that's going to happen is that a
large part of it will be skipped.  Remember that an "if" is a compound
statement which has to all be read into memory to be sure it parses
correctly before any of it can be executed (or discarded, if the
condition is false).  So a giant "if [[ -o interactive ]]; ..." may
needlessly consume memory and time.

I have a multi-file configuration which consists of

$HOME/.zshenv which sets ZDOTDIR to point at

a directory checked out of a source code repository which contains the
actual initialization files.

Within that directory are subdirectories for each host or host type
for which there is a customized config.  I symlink one of those to
"local" and then in (for example) $ZDOTDIR/.zshrc I will have

	desire $ZDOTDIR/local/termsetup

where "desire" is a function defined early like

	desire() { [[ -O $1 ]] && source $1 }

so I don't have to care if a particular local configuration is missing.


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: do you use separate .zshenv and .zshrc files?
  2012-04-28 23:03 ` Bart Schaefer
@ 2012-04-28 23:19   ` TJ Luoma
  0 siblings, 0 replies; 7+ messages in thread
From: TJ Luoma @ 2012-04-28 23:19 UTC (permalink / raw)
  To: zsh-users



On Saturday, April 28, 2012 at 7:03 PM, Bart Schaefer wrote:

> If you have a lot of configuration it may take somewhat longer to parse
> and execute the one big file when all that's going to happen is that a
> large part of it will be skipped. Remember that an "if" is a compound
> statement which has to all be read into memory to be sure it parses
> correctly before any of it can be executed (or discarded, if the
> condition is false). So a giant "if [[ -o interactive ]]; ..." may
> needlessly consume memory and time.

Ah, well, one of the things I have noticed lately is that zsh seems to be taking a little longer to launch, so I wonder if that's one of the reasons. 

I'm going to try splitting it into separate files and see if I like that better.

TjL



^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2012-04-28 23:19 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-04-28 19:07 do you use separate .zshenv and .zshrc files? TJ Luoma
2012-04-28 20:54 ` Benjamin R. Haskell
2012-04-28 21:01   ` Benjamin R. Haskell
2012-04-28 21:57   ` TJ Luoma
2012-04-28 22:25     ` Benjamin R. Haskell
2012-04-28 23:03 ` Bart Schaefer
2012-04-28 23:19   ` TJ Luoma

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).