Added dotfiles management script
This commit is contained in:
parent
62cf7af099
commit
acecc996e4
2 changed files with 114 additions and 0 deletions
46
createlinks.sh
Normal file
46
createlinks.sh
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
#!/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
|
||||
|
||||
# dotfiles
|
||||
makelink_simple .bashrc
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue