Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Recommended method for reloading `.zshrc`? (`source` VS `exec`?)

Most people seem to recommend using source for reloading .zshrc. Why?

First I tried out source ~/.zshrc. But it resulted in a compinit error (at reload, not for new shell instances at first .zshrc load).

My reload alias is now:

alias zsh-reload="exec zsh"

instead of:

source ~/.zshrc

The reason for this is that my previous reload method (source) triggered a compinit error;

zsh compinit: insecure directories, run compaudit for list.
Ignore insecure directories and continue [y] or abort compinit [n]?

So I'm now doing exec because I believie it ensures the previous environment doesn't pollute the new one.

  • What are the downsides of using the exec method?
  • Is there an explicit reason for that you're doing exec or source?
  • Could exec in theory cause unexpected problems compared to the source method?
like image 675
Michael Bergquist Suarez Avatar asked May 23 '19 23:05

Michael Bergquist Suarez


People also ask

What is Zshrc file used for?

zshrc file so that, assuming you are using ZSH as your shell, it will get executed when you log in. The fact that the line actually in your . zshrc file contains this would appear to be an error. In this case it will write the output from the export command to the .

How do I automatically generate Zshrc?

Preferences -> Profiles -> Select Default Profile(default profile will be starred) -> General -> Command -> Select Login Shell -> Send text at start: Enter the value source ~/. zshrc .

How do I save a .zshrc file?

zshrc is the ZSH configuration file itself. Now to save the file in nano , hit ctrl + X .

How do I restart my Ohmyzsh?

Restart the zsh process by running: exec zsh .


1 Answers

With exec, all (unexported) variables in your shell are lost, which is probably not what you want. Instead, it might be better to fix the compinit problem, by using compinit -i. See the zsh man page for compinit, paragraph Use of compinit:

to make compinit silently ignore all insecure files and directories use the option -i

like image 164
user1934428 Avatar answered Oct 11 '22 17:10

user1934428