Symlink ~.zshrc
Asked Answered
zsh
K

5

18

If my .zshrc file is ~/.dotfiles/zsh/.zshrc, how can I create a symlink so that the file appears as ~/.zshrc?

Karena answered 30/7, 2013 at 0:14 Comment(0)
B
31

The cd step in Alexej's answer isn't needed as you can call ln -s target destination explicitly.

ln -s ~/.dotfiles/zsh/.zshrc ~/.zshrc
Borszcz answered 30/7, 2013 at 23:0 Comment(0)
P
3

run:

cd ~/ ; ln -s ~/.dotfiles/zsh/.zshrc
Plasmolysis answered 30/7, 2013 at 0:16 Comment(3)
I get a ~/.zshrc: No such file or directory error. Why is this?Karena
I dunno, but you could try going into your home directory--that is, cd ~--and try running this from there ln -s ~/.dotfiles/zsh/.zshrcPlasmolysis
I think, I know now. Mac OSX's ln doesn't have the -T option, my bad. I'll edit my answer.Plasmolysis
S
0

for me, when using relative path for symlink, it can show error: ~/.zshrc: No such file or directory error as @astephen2. You should change to absolute path then it working fine

Scalene answered 4/2, 2021 at 16:0 Comment(0)
P
0

On MacOS, you can't use ~ in a symlink where the directory is quoted. You need to use full paths. I'd recommend running ln -s "$HOME/.dotfiles/zsh/.zshrc" "$HOME/.zshrc" Alternatively, you can forget the quotes, and use ~ in place of $HOME, however if there are any spaces (or variables with spaces) you'll probably run into problems.

Phifer answered 4/1, 2023 at 20:28 Comment(4)
You can still use ~ in the arguments to ln -s, though; the shell expands them before ln is executed.Arundel
You're right, I had originally forgotten to mention that that only happens when using quotes, because the shell won't replace the ~Phifer
You can quote any portion of the path, if necessary, while leaving ~ unquoted: ~/"$SOMEDIR"/.zshrc expands correctly.Arundel
Oh... that completely escaped my mind.Phifer
A
0

You don't actually need a symlink. Add the following to ~/.zshenv:

ZDOTDIR=~/.dotfiles/zsh

zsh sources ~/.zshenv before any other files, and will use the value of $ZDOTDIR as the location for local configuration files in lieu of your home directory.

Arundel answered 4/1, 2023 at 20:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.