16

I'm trying to move .zshrc to a folder where I keep this kind of files synced with Github.

But now whenever I start a zsh session it doesn't use that config file.

Assuming I changed the file to ~/.dotfiles how can I add ~/.dotfiles/.zshrc to the PATH(?!) to make zsh start with that config?

Doing source ~./dotfiles/.zshrc only works for that session. Doesn't work anymore if I close the terminal.

Braiam
  • 1
  • 11
  • 47
  • 78
Cândido Faísca
  • 307
  • 1
  • 3
  • 8

7 Answers7

20

You can symlink:

ln -s /path/to/original /path/to/symlink

For the zshrc you can do something like:

ln -s ~/.dotiles/.zshrc ~/.zshrc
nitishagar
  • 9,038
  • 3
  • 28
  • 40
19

One alternative to a symlink is to put this in ~/.zshenv:

ZDOTDIR=~/.dotfiles

If you want .zshenv in ~/.dotfiles as well, you can look into setting ZDOTDIR in one of the global configuration files (/etc/zshenv is a good choice).

chepner
  • 497,756
  • 71
  • 530
  • 681
8

Alternatively, you can do what I do and use GNU Stow. I've got my dotfiles in a repository, one subdirectory per category, like so:

dotfilerepo/zsh/.zshrc
dotfilerepo/zsh/.zlogin
dotfilerepo/git/.gitconfig
dotfilerepo/vim/.vimrc

then I can cd into repo and do stow zsh and it'll create a symlink from ~/.zshrc to repo/zsh/.zshrc, another from zsh/.zlogin to ~/.zlogin. stow vim to create symlinks from the vim subdirectory to ~, etc.

I've got a script, install-linkfarm, that does all the stow commands so when I move onto a new machine, I clone my repo, cd to it and run install-linkfarm and am good to go.

Joe Block
  • 1,872
  • 1
  • 12
  • 11
1

You can put this in ~/.zshrc, even as its entire contents:

if [ -r ~/.dotfiles/.zshrc ]; then
    source ~/.dotfiles/.zshrc
fi
Cliff P
  • 57
  • 1
  • 7
1

Please use the export command mentioned below to solve your problem.

export ZDOTDIR=$HOME/.dotfiles
stud3nt
  • 2,056
  • 1
  • 12
  • 21
bigxia
  • 19
  • 1
0

In Linux, you can check if your zsh is loading /etc/zsh/zshrc, and edit it.

If that's the case, redirect this to your custom script by adding:

sh $HOME/.dotfiles/zshrc
derloopkat
  • 6,232
  • 16
  • 38
  • 45
-1

Here is an interesting hack that doesn't require you to use sym-links. In your .xsession, (or .*wmrc) have the following:

xterm -e 'zsh -c ". ~/.dotfiles/.zshrc; zsh"'.

instead of just:

xterm
Make sure to put the -e at the end after all of your other xterm options.