-
Notifications
You must be signed in to change notification settings - Fork 0
/
linkup
executable file
·54 lines (46 loc) · 1.53 KB
/
linkup
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
#!/usr/bin/env zsh
#
# Links the contents of the `dotfiles` directory into the home directory,
# prefixing each with a `.`.
RELATIVE_PATH=`dirname $0`
BASE_PATH=`( cd ${RELATIVE_PATH} && pwd)`
BACKUP_PATH=$RELATIVE_PATH/backup/`date +%Y%m%d%k%M%S`
DOTFILES_PATH=${BASE_PATH}/dotfiles
for FILE in $DOTFILES_PATH/*; do
NAME=`basename $FILE`
DEST=~/.$NAME
if [[ -L $DEST ]] && [[ `readlink $DEST` == $FILE ]]; then
# The link is already to the destination; we don't need to do
# anything.
continue
elif [[ -e $DEST ]] then
mkdir -p $BACKUP_PATH
echo "Backing up $DEST"
mv $DEST $BACKUP_PATH/$NAME
fi
ln -s $FILE $DEST
done
mkdir -p ~/bin
for FILE in ${BASE_PATH}/bin/*; do
NAME=`basename $FILE`
DEST=~/bin/$NAME
if [[ -L $DEST ]] && [[ `readlink $DEST` == $FILE ]]; then
# The link is already to the destination; we don't need to do
# anything.
continue
elif [[ -e $DEST ]] then
mkdir -p $BACKUP_PATH/bin
echo "Backing up $DEST"
mv $DEST $BACKUP_PATH/bin/$NAME
fi
ln -s $FILE $DEST
done
# Karabiner doesn't let us customize where it's config lives, it must be at
# ~/.config/karabiner/karabiner.json, and that file is not allowed to be a
# symlink itself. I don't want to track the entire `~/.config` directory
# (because some other things like iTerm also stuff cruft in there), so here's a
# custom link only for macos (Darwin).
if [[ $(uname) == "Darwin" ]]; then
mkdir -p ~/.config
ln -s $BASE_PATH/karabiner ~/.config
fi