dotfiles/createlinks.sh

60 lines
1.1 KiB
Bash

#!/bin/bash
if [ $# -ne 2 ]; then
echo "wrong argument count"
fi
# Set variables
homedir="$1"
dotfilesdir="$2"
# Change directory to home dir
cd "$homedir"
# Define a function that create a link unless it already exists
makelink() {
test $# -eq 2 || { echo "makelink: invalid function call"; exit 1; }
if [ ! -e "$1" ]; then
echo "can't create link '$2': target '$1' does not exist"
return
fi
if [ ! -e "$2" ]; then
# Create link
ln -sr "$1" "$2"
elif [ ! -L "$2" ]; then
# A file with the same name exists and it's not a link
# -> warn user!
echo "can't create link '$2': file already exists"
fi
}
makelink_simple() {
test $# -eq 1 || { echo "makelink_simple: invalid function call"; exit 1; }
makelink "$dotfilesdir/$1" "$1"
}
# -- CREATE THE LINKS HERE --
# ~/bin
makelink "$dotfiles/bin/" bin
# bash, profile, etc.
makelink_simple .profile
makelink_simple .bashrc
makelink_simple .bash_profile
makelink_simple .bash_logout
# vim
makelink_simple .vimrc
makelink_simple .gvimrc
# misc apps
makelink_simple .bcrc
makelink_simple .toprc
# TODO more links...