3

Problem

I'm trying to move my config files from a .dotfiles folder, and link those files to the corresponding config path.

Example

In this example I'm trying

$ ln -s ~/.dotfiles/nvim/init.vim ~/.config/nvim/init.vim

And the program (nvim in this case), the config file doesn't take effect.

But when I copy the file instead of linking

$ cp ~/.dotfiles/nvim/init.vim ~/.config/nvim/init.vim

It does take effect.

Other example

When I do the same thing but with my .zshrc file

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

It takes effect...

Question

How could I link my .dotfiles config files to the according path for config?


Thanks

Kusalananda
  • 320,670
  • 36
  • 633
  • 936
  • 1
    What does "it doesn't work" mean _exactly_? – Kusalananda Nov 17 '19 at 13:10
  • The program I'm trying to config doesn't consider the file. So when I open `nvim`, I don't get the config I've added if I used a symlink, but when I copy the config file, it does. – Norman Perrin Nov 17 '19 at 13:12
  • I really can't recreate this. Neovim is quite happy to read a symbolic link as its init file. – Kusalananda Nov 17 '19 at 14:38
  • 1
    Did you, by mistake, _quote_ the link target (`~/.dotfiles/nvim/init.vim`) when you created the link? This would make `~` not expand, and the link would not be able to be followed. – Kusalananda Nov 17 '19 at 14:55

3 Answers3

0

Probably you want to put .dotfiles to git repo and instead of files you end up with symlinks inside git.

There are multiple ways to handle this:

  1. You probably might want to move actual files to .dotfiles and create a symlink to those in original place. Should work in most cases, but you might run into issues if there are some strange checks implemented in software which uses this configuration files (but shouldn't really happen). I'd try this one.

  2. Use hardlinks instead of softlinks. ln ~/.dotfiles/nvim/init.vim ~/.config/nvim/init.vim instead of ln -s. However that might be a bit harder to track and manage. Note that hardlinks do not work for directories.

  3. You might wanna try to play with bind mounts, however it works for directories only and isn't that obvious. Plus requires system changes to make this option survive reboot.

rush
  • 27,055
  • 7
  • 87
  • 112
  • I edited the first part of the question that was wrong. I ment to say **from** my `.dotfiles` folder. So I think I would be doing the first option you shared. – Norman Perrin Nov 17 '19 at 13:08
0

Solved by itself...

I specified the absolute path from ~. Like:

$ ln -s ~/.dotfiles/nvim/init.vim ~/.config/nvim/init.vim

I think I was creating the symlink with a relative path before


Thanks everyone who answered

0

Instead of ln -s ~/.dotfiles/nvim/init.vim ~/.config/nvim/init.vim

you can also do:

cd ~/.config/nvim

and then

ln -s ../../.dotfiles/nvim/init.vim (relative)

or

ln -s ~/.dotfiles/nvim/init.vim (expanded to absolute)

Like this you have more control. Both rel. and abs. should work. Difference is when you copy or move.