From 08837b9832efa2ede047164c4cb7aaee79774af9 Mon Sep 17 00:00:00 2001 From: Michiel Scholten Date: Wed, 15 Aug 2018 15:44:16 +0200 Subject: [PATCH] Moved the link creation and backup into a function --- install.sh | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/install.sh b/install.sh index aac40a4..bebde5a 100644 --- a/install.sh +++ b/install.sh @@ -41,22 +41,15 @@ install_fish() echo } -# Get the directory the dotfiles have been cloned into -DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -echo "Installing from $DIR" -DATETIME=$(date +%Y%m%d_%H%M) - -# Go home -cd || exit - -# Symlink all the things -for TARGET in .bash_aliases .bashrc bin .gitconfig .gitmodules .hgauthors.txt .hgignore .hgrc .ignore .screenrc .terminfo .tmux.conf .vim .vimrc install.sh -do +make_link() +{ + DIR="$1" + TARGET="$2" cd || exit echo $TARGET if [ "$(readlink $TARGET)" = "$DIR/$TARGET" ]; then echo " symlink exists and is fine, skipping" - continue + return elif [ -e $TARGET ] || [ -L $TARGET ] && [ "$(readlink $TARGET)" != "$DIR/$TARGET" ]; then echo " exists, moving out of the way" if [ ! -d "workspace/backup/dotfiles_$DATETIME" ]; then @@ -81,6 +74,21 @@ do # Create the symlink ln -s "$DIR/$TARGET" #echo "ln -s $DIR/$TARGET" + +} + +# Get the directory the dotfiles have been cloned into +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +echo "Installing from $DIR" +DATETIME=$(date +%Y%m%d_%H%M) + +# Go home +cd || exit + +# Symlink all the things +for TARGET in .bash_aliases .bashrc bin .gitconfig .gitmodules .hgauthors.txt .hgignore .hgrc .ignore .screenrc .terminfo .tmux.conf .vim .vimrc install.sh +do + make_link $DIR $TARGET done echo "INFO: Init submodules"