forked from matthewmccullough/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy path_setupdotfiles.sh
executable file
·113 lines (98 loc) · 2.95 KB
/
_setupdotfiles.sh
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#!/bin/bash
DOTFILESDIR=~/dotfiles
DOTFILES=".bash_logout .bash_profile .bashrc .Brewfile .colordiffrc .colorgccrc .gitconfig .gitignore .hammerspoon .inputrc .iterm2_shell_integration.zsh .p10k.zsh .profile .pythonrc .shellactivities .shellaliases .shellpaths .shellvars .terraformrc .tmux.conf .vimrc .xxdiffrc .zlogout .zprofile .zshenv .zshrc"
DOTDIRS=".vim"
DROPFILES="persistent_history"
DROPDIRS="bin .pip"
SAVEDIR=~/.old/_setupdotfiles
function symlinkifne {
target=~/$1
echo "Working on: $target"
export dotless=`echo $1 | sed s/^\.//`
if [ ! -e $DOTFILESDIR/$dotless ]; then
# Check if platform-specific version exists.
osname=$(uname)
if [ "$osname" = "Darwin" ]; then
platform="macos"
elif [ "$osname" = "Linux" ]; then
platform="linux"
else
echo "ERROR: unsupported OS $osname!"
exit 1
fi
if [ -e $DOTFILESDIR/$dotless-$platform ]; then
export dotless="$dotless-$platform"
else
echo "ERROR: file $DOTFILESDIR/$dotless does not exist, and has no platform-specific variant!"
exit 1
fi
fi
if [ -e $target ]; then
if [ ! -L $target ]; then
# If it's not a symlink, tread carefully.
echo " WARNING: $target already exists!"
if [ "${MOVE:-false}" = "true" ]; then
echo " Moving $target to $SAVEDIR/"
mv $target $SAVEDIR/
dotless=$(echo $1 | sed s/.//)
echo " Symlinking $DOTFILESDIR/$dotless to $1"
ln -s $DOTFILESDIR/$dotless $target
else
echo " Skipping $1."
fi
else
# Safe to just delete if it is a symlink (or if it doesn't exist).
rm -f $target
echo " Symlinking $DOTFILESDIR/$dotless to $target"
ln -s $DOTFILESDIR/$dotless $target
fi
else
echo " Symlinking $DOTFILESDIR/$dotless to $target"
ln -s $DOTFILESDIR/$dotless $target
fi
}
echo "This script must be run from the dotfiles directory"
echo "Setting up..."
pushd ~
if [ "${MOVE:-false}" = "true" -a -d $SAVEDIR ]; then
echo "$SAVEDIR already exists! Please clean up and try again."
echo "This is used to save old versions of your configuration files."
exit 1
fi
mkdir -p $SAVEDIR
if [ ! -d dotfiles ]; then
echo "The dotfiles directory does not exist in your home directory!"
echo "You need to do:"
echo "# cd ~"
echo "# git clone --recurse-submodules https://github.com/jimlawton/dotfiles"
echo "# cd dotfiles"
echo "# ./_setupdotfiles.sh"
exit 1
fi
for dotfile in $DOTFILES; do
symlinkifne $dotfile
done
for dotdir in $DOTDIRS; do
symlinkifne $dotdir
done
# Any directories you want linked from Dropbox.
if [ -e ~/Dropbox/ ]; then
for dropdir in $DROPDIRS; do
if [ ! -e ~/$dropdir ]; then
ln -s ~/Dropbox/unixhome/$dropdir ~/
fi
done
fi
# Any files you want linked from Dropbox.
if [ -e ~/Dropbox/ ]; then
for dropfile in $DROPFILES; do
if [ ! -e ~/$dropfile ]; then
ln -s ~/Dropbox/$dropfile ~/.$dropfile
fi
done
fi
mkdir -p ~/.config
ln -sf ~/dotfiles/hyper-hacks/karabiner ~/.config/karabiner
mkdir -p ~/.terraform.d
popd
echo "Done!"