From 9aa80c1e47fe3d5523212511c0c46d57ab3044a0 Mon Sep 17 00:00:00 2001 From: "J. Paul Reed" Date: Sat, 11 Jul 2015 19:54:33 -0700 Subject: [PATCH] Write a function to properly handle the common case of symlinking in a sourcefile from a host source. I originally moved these files around, but I think symlinking them in is better: they tell the user that the copies they're using were created by curl-bashenv. --- curl-bashenv | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/curl-bashenv b/curl-bashenv index be31141..db4536c 100755 --- a/curl-bashenv +++ b/curl-bashenv @@ -90,6 +90,13 @@ function symlink_gitrepo_file() { $LN -s "$source_file" "$dest_file" } +function symlink_sourcehost_file() { + test -z "$1" && assert "symlink_sourcehost_file: first arg empty" + source_file="${SETUP_DIR}/$1" + dest_file="$HOME/$1" + test -e "$dest_file" && $MV "$dest_file" "${BACKUP_DIR}" + $LN -s "$source_file" "$dest_file" +} function setup_sourcehost_ssh() { local sshBackupDir="${BACKUP_DIR}/.ssh" @@ -204,9 +211,7 @@ function setup_sourcehost_shdotfiles() { $SCP $SOURCE:~/{$dotfile_list} ${SETUP_DIR}/ for f in $prefixed_dotfiles; do - for f in $dotfile_list; do - test -e $HOME/$f && $MV $HOME/$f ${BACKUP_DIR} - $MV ${SETUP_DIR}/$f $HOME + symlink_sourcehost_file $f done return 0 @@ -214,8 +219,7 @@ function setup_sourcehost_shdotfiles() { function setup_sourcehost_gitconfig() { $SCP ${SOURCE}:~/.gitconfig ${SETUP_DIR}/ - test -f $HOME/.gitconfig && $MV $HOME/.gitconfig ${BACKUP_DIR} - $MV ${SETUP_DIR}/.gitconfig $HOME + symlink_sourcehost_file .gitconfig } function setup_gitrepo_gitconfig() {