简体   繁体   English

符号链接 ~.zshrc

[英]Symlink ~.zshrc

If my.zshrc file is ~/.dotfiles/zsh/.zshrc, how can I create a symlink so that the file appears as ~/.zshrc?如果 my.zshrc 文件是 ~/.dotfiles/zsh/.zshrc,我如何创建符号链接以使文件显示为 ~/.zshrc?

不需要 Alexej 答案中的cd步骤,因为您可以明确调用 ln -s目标目的地

ln -s ~/.dotfiles/zsh/.zshrc ~/.zshrc

跑步:

cd ~/ ; ln -s ~/.dotfiles/zsh/.zshrc

for me, when using relative path for symlink, it can show error: ~/.zshrc: No such file or directory error as @astephen2.对我来说,当使用符号链接的相对路径时,它会显示错误: ~/.zshrc: No such file or directory error as @astephen2。 You should change to absolute path then it working fine您应该更改为绝对路径然后它工作正常

You don't actually need a symlink.您实际上并不需要符号链接。 Add the following to ~/.zshenv :将以下内容添加到~/.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. zsh在任何其他文件之前获取~/.zshenv ,并将使用$ZDOTDIR的值作为本地配置文件的位置来代替您的主目录。

On MacOS, you can't use ~ in a symlink where the directory is quoted.在 MacOS 上,您不能在引用目录的符号链接中使用~ 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.我建议运行ln -s "$HOME/.dotfiles/zsh/.zshrc" "$HOME/.zshrc"或者,您可以忘记引号,并使用~代替$HOME ,但是如果有任何空格(或带空格的变量)你可能会遇到问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM