Symlink – How to Symlink Dotfiles to Documents/Dotfiles

symlink

I have a setup script which creates links between my dotfiles repo and the files at the root of my Home directory. Generally speaking, the process looks like this for each file:

ln -s ~/Documents/Dotfiles/.bash_profile ~/.bash_profile

Is this linked in the correct direction? E.g, I want to be able to keep my customizations in Documents and just point to them. Most of the documentation I've read seems to assume a traditional Unix or Linux environment, so I'm not sure this is correct.

The relevant part of my setup script is below

#!/bin/bash

set -e

function makeLinks() {
  ln -s ~/Documents/Dotfiles/.bash_aliases ~/.bash_aliases
  ln -s ~/Documents/Dotfiles/.bash_profile ~/.bash_profile
  ln -s ~/Documents/Dotfiles/.bash_prompt ~/.bash_prompt
  ln -s ~/Documents/Dotfiles/.gitconfig ~/.gitconfig
  ln -s ~/Documents/Dotfiles/.gitignore_global ~/.gitignore_global

  read -rp "This may overwrite existing files. Are you sure? (y/n) " -n 1;
  echo "";
  if [[ $REPLY =~ ^[Yy]$ ]]; then
    makeLinks
  fi;
}

Best Answer

man ln clearly says:

ln [-Ffhinsv] source_file [target_file]

So yeah, your command seems reasonable.

The script, however, is odd. makeLinks is never invoked and the prompt asking for confirmation would just cause recursion. You probably meant to place it outside the function definition.