3 # Link each FILE in patched-src to ~/FILE
5 # By default, link.sh only replaces missing files and simlinks. You
6 # can optionally overwrite any local files by passing the --force
9 if [ -z "${DOTFILES_DIR}" ]; then
10 echo 'DOTFILES_DIR is not set. Bailing out.'
14 DOTFILES_SRC="${DOTFILES_DIR}/patched-src"
15 FORCE='no' # If 'file', overwrite existing files.
16 # If 'yes', overwrite existing files and dirs.
17 DRY_RUN='no' # If 'yes', disable any actions that change the filesystem
20 while [ -n "${1}" ]; do
35 # Create the symbolic link, overriding the target if it exists.
40 # file - The file we're processing '.foo'
44 if [ -e ~/"${FILE}" ] || [ -h ~/"${FILE}" ]; then
45 if [ "${DRY_RUN}" = 'yes' ]; then
46 echo "move ~/${FILE} to ~/${FILE}.bak"
49 mv -v ~/"${FILE}" ~/"${FILE}.bak" || exit 1
52 if [ "${DRY_RUN}" = 'yes' ]; then
53 echo "link ~/${FILE} to ${DOTFILES_DIR}/${FILE}"
56 ln -sv "${DOTFILES_DIR}/patched-src/${FILE}" ~/"${FILE}" || exit 1
60 cd "${DOTFILES_DIR}/patched-src" || exit 1
63 if [ "${FILE}" = '.' ]; then
66 FILE="${FILE:2}" # strip the leading './'
67 if [ "${DOTFILES_SRC}/${FILE}" -ef ~/"${FILE}" ]; then
68 continue # already simlinked
70 if [ -d "${DOTFILES_SRC}/${FILE}" ] && [ -d ~/"${FILE}" ] && \
71 [ "${FORCE}" != 'yes' ]; then
72 echo "use --force to override the existing directory: ~/${FILE}"
73 continue # allow unlinked directories
75 if [ -e ~/"${FILE}" ] && [ "${FORCE}" = 'no' ]; then
76 echo "use --force to override the existing target: ~/${FILE}"
77 continue # target already exists