forked from lethor/essentials
-
Notifications
You must be signed in to change notification settings - Fork 1
/
create-symlinks
executable file
·53 lines (44 loc) · 1.2 KB
/
create-symlinks
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/env bash
symlink()
{
if [ -z "$1" ] || [ -z "$2" ]; then
echo "usage: symlink <source> <target>" >&2
return 1
fi
if [ ! -e "$1" ]; then
echo "Source does not exist: $1" >&2
return 2
fi
if [ -L "$2" ]; then
echo "Link exists: $2" 2>&1
return
fi
if [ -e "$2" ]; then
echo "Backing up existing $2" 2>&1
mv "$2" "$2~$(date +%FT%T%z)"
fi
echo "Linking $2..."
ln -s "$1" "$2"
}
source=$(cd "$(dirname "$0")" && pwd) # This script's parent directory.
target="$HOME"
case $(uname -s) in
"Darwin" )
os="macos" ;;
"Linux" )
if [ -e /etc/debian_version ]; then
os="debian"
else
os="unix"
fi ;;
* )
os="unix" ;;
esac
symlink "$os" this
symlink "$source/this/bin" "$target/bin"
symlink "$source/this/dotfiles/bash_aliases" "$target/.bash_aliases"
symlink "$source/this/dotfiles/bash_profile" "$target/.bash_profile"
symlink "$source/this/dotfiles/bashrc" "$target/.bashrc"
symlink "$source/this/dotfiles/zshrc" "$target/.zshrc"
symlink "$source/this/dotfiles/vimrc" "$target/.vimrc"
symlink "$source/this/dotfiles/profile" "$target/.profile"