forked from FruitieX/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsymlink.sh
executable file
·87 lines (69 loc) · 2.13 KB
/
symlink.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
#!/bin/zsh
# recursively symlink all files from paths in this array
FILES=( bin src .apvlvrc .compton.conf .config .colors .conkyrc .dir_colors .gconf .mozilla .synergy.conf .tmux.conf .tmux.servy .theme.cfg .urlview .vimrc .vim/autoload/pathogen.vim .xinitrc .Xdefaults .Xmodmap .zshrc .zprofile .zpreztorc .lock.sh)
# symlink these directories
DIRS=( .vim/bundle .vim/colors .vim/ftdetect .zprezto .i3 )
# cd to root of git repo
cd "$(dirname $0)"
CWD=$(pwd)
# dry run mode enabled?
if [[ $1 == '-d' ]]; then
DRYRUN=echo
else
DRYRUN=
fi
if [[ $1 != '-y' ]]; then
echo "WARNING! this script will backup the following files/dirs and put symlinks in their place:"
echo files:
echo ------
find "${FILES[@]}" -type f -printf "$HOME/%p\n"
echo
echo dirs:
echo -----
for DIR in $DIRS; do echo $HOME/$DIR; done
echo -e "\nare you sure you want to continue? (y/n)"
read answer
if [[ "$answer" != "y" ]]; then
echo "aborting."
exit
fi
fi
# symlink files
echo -e "\nsymlinking..."
find "${FILES[@]}" -type f -print0 | while read -d $'\0' FILE; do
# create parent directies if they do not exist
if [ ! -d "$(dirname "$HOME/$FILE")" ]; then
$DRYRUN mkdir -p $(dirname "$HOME/$FILE")
fi
# if file is a symlink, remove it and later make a new symlink
if [ -L "$HOME/$FILE" ]; then
$DRYRUN rm "$HOME/$FILE"
# elif file already exists, make a backup
elif [ -f "$HOME/$FILE" ]; then
$DRYRUN mv -f "$HOME/$FILE" "$HOME/$FILE.bak"
echo "backed up $HOME/$FILE => $HOME/$FILE.bak"
fi
echo "$FILE => $HOME/$FILE"
$DRYRUN ln -sr "$FILE" "$HOME/$FILE"
done
for DIR in $DIRS; do
# create parent directies if they do not exist
if [ ! -d "$(dirname "$HOME/$DIR")" ]; then
$DRYRUN mkdir -p $(dirname "$HOME/$DIR")
fi
# if dir is a symlink, remove it and later make a new symlink
if [ -L "$HOME/$DIR" ]; then
$DRYRUN rm "$HOME/$DIR"
# elif dir already exists, make a backup
elif [ -d "$HOME/$DIR" ]; then
$DRYRUN mv -f "$HOME/$DIR" "$HOME/$DIR.bak"
echo "backed up $HOME/$DIR => $HOME/$DIR.bak"
fi
echo "$DIR => $HOME/$DIR"
$DRYRUN ln -sr "$DIR" "$HOME/$DIR"
done
echo
echo "running compile.sh..."
./compile.sh
echo
echo "all done!"