-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup-symlinks.sh
executable file
·57 lines (46 loc) · 1.48 KB
/
setup-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
#!/bin/bash
##############################################################################
# ./setup-symlinks.sh
# This script creates symlinks in the home directory to dotfiles in ~/dotfiles
##############################################################################
### Variables ###
dotfiles_dir=./dotfiles # dotfiles directory
old_dotfiles_dir=~/dotfiles_old # old dotfiles backup directory
# List of files/folders to symlink in home directory
dotfiles=(
'zshrc'
'zsh_profile'
'inputrc'
'vimrc'
'zsh_aliases'
'zsh_exports'
)
# Create dotfiles_old in home directory
echo "# Creating $old_dotfiles_dir for backup of any existing dotfiles in ~"
mkdir -p $old_dotfiles_dir
echo "...done"
for dotfile in ${dotfiles[@]}; do
source_dotfile=$dotfiles_dir/$dotfile
target_dotfile=~/.$dotfile
# If dotfile exists from ~ to dotfiles_old
if [ -e "$target_dotfile" ]; then
if [ "$(readlink "$target_dotfile")" != "$source_dotfile" ]; then
echo "# Moving existing $target_dotfile to $old_dotfiles_dir"
mv $target_dotfile $old_dotfiles_dir/
echo "...done"
fi
fi
# Create symlink for dotfile in home directory
echo "# Creating symlink for $dotfile in home directory"
ln -fs $source_dotfile $target_dotfile
echo "...done"
done
# Unset variables
unset dotfiles_dir
unset old_dotfiles_dir
unset dotfiles
unset dotfile
unset source_dotfile
unset target_dotfile
# Source updated ~/.zshrc dotfile
source ~/.zshrc