-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path_make_symlinks.sh
executable file
·90 lines (75 loc) · 2.15 KB
/
_make_symlinks.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
#!/bin/bash
set -e
# Install all the dotfiles in this directory (symlink them into place)
# When a file already exists, copy it to an "old_dotfiles" directory first
# When a symlink already exists, replace it
declare -a dotfile_whitelist=(
.vim\
.vimrc\
.zshrc\
)
backup_dir="${HOME}/dotfiles.bak"
function create_symlink {
echo "created symlink: $2 -> $1"
ln -s $1 $2
}
cd `dirname $0`
for f in ${dotfile_whitelist[@]}; do
# In the repo I don't include the leading dot so they're not all hidden
if [[ $f =~ ^\. ]]
then
repo_filename=${f:1}
else
repo_filename=${f}
fi
repo_file=$(pwd)/${repo_filename}
# if whitelisted file isn't actually in repo, skip
if [ ! -f ${repo_file} -a ! -d ${repo_file} ]
then
continue
fi
dotfile=${HOME}/.${repo_filename}
# if file or dir exists, back it up then create symlink
if [ -f ${dotfile} -o -d ${dotfile} ] && [ ! -h ${dotfile} ]
then
if [ ! -d ${backup_dir} ]
then
echo "WARN: made backup directory ${backup_dir}"
mkdir ${backup_dir}
fi
echo "WARN: moving existing ${dotfile} to ${backup_dir}" 1>&2
mv ${dotfile} ${backup_dir}
create_symlink "${repo_file}" "${dotfile}"
continue
fi
# if symlink exists and is different, warn then create new symlink
if [ -h "${dotfile}" ]
then
current_target=`ls -l ${dotfile} | awk '{print $11}'`
if [ "${current_target}" != "${repo_file}" ]
then
echo "WARN: removed symlink: ${dotfile} -> ${current_target}" 1>&2
rm "${dotfile}"
create_symlink "${repo_file}" "${dotfile}"
else
echo "file ${dotfile} already set correctly" 1>&2
fi
continue
fi
# doesn't exist yet, create symlink
if [ ! -a "${dotfile}" ]
then
create_symlink "${repo_file}" "${dotfile}"
continue
fi
done
if [ ! -d "$HOME/bin" ]; then
mkdir -p "$HOME/bin"
fi
create_symlink "$(pwd)/bin/ts" "$HOME/bin/ts"
create_symlink "$(pwd)/bin/pyperl" "$HOME/bin/pyperl"
create_symlink "$(pwd)/aliases.zsh" "$ZSH_CUSTOM/aliases.zsh"
# create_symlink "$(pwd)/bin/path_compressor.py" "$HOME/bin/path_compressor.py"
mkdir -p "$HOME/.vim_sessions"
mkdir -p "$HOME/.vim_undo"
touch "$HOME/.vimrc.local"