-
Notifications
You must be signed in to change notification settings - Fork 3
/
link.sh
executable file
·79 lines (72 loc) · 2.16 KB
/
link.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
#!/bin/bash
# Link a file from the dotfiles directory to its intended location.
link() {
# $1 is always the filename as it exists in dotfiles.
SOURCE_DOTFILE="$HOME/dotfiles/$1"
SOURCE_FILENAME=$(basename "$1")
# $2 can be:
# 1. Not provided, in which case the filename in $1 should simply be the
# target under $HOME.
if [[ -z "$2" ]]; then
TARGET="$HOME/$SOURCE_FILENAME"
# 2. A directory name ending in '/', in which case $1 should be linked
# under that directory in $HOME.
elif [[ -d "$HOME/$2" && "${2: -1}" == '/' ]]; then
TARGET="$HOME/$2$SOURCE_FILENAME"
# 3. An alternate name that the file should be renamed as under $HOME.
else
TARGET="$HOME/$2"
fi
# Remove existing symlinks. Otherwise, backup existing files.
if [[ -L "$TARGET" ]]; then
echo "[-] Remove: $TARGET@"
rm "$TARGET"
elif [[ -e "$TARGET" ]]; then
BACKUP="$TARGET.bu.$(date '+%s')"
echo "[+] Backup: $TARGET -> $BACKUP"
mv "$TARGET" "$BACKUP"
fi
# Finally, link the dotfile to its intended target.
echo "[*] Link: $LINK_MSG$SOURCE_DOTFILE -> $TARGET"
ln -s "$SOURCE_DOTFILE" "$TARGET"
}
# OS-agnostic files.
for FILE in \
.bash_profile \
.bashrc \
.bashrc.d \
.config \
.hushlogin \
.inputrc \
.inputrc.tmux \
.ipython \
.jq \
.local \
.tmux.conf \
.vimrc \
nvim; do
link "$FILE"
done
# OS-specific files.
case "$OSTYPE" in
'linux-gnu'*)
for FILE in \
.asoundrc \
.xinitrc \
.Xresources \
.XCompose; do
link "$FILE"
done
;;
'darwin'*)
link .finicky.js
link .skhdrc.yabai .skhdrc
link .yabairc
link .config/uebersicht/WidgetSettings.json 'Library/Application Support/tracesOf.Uebersicht/'
link .config/uebersicht/widgets 'Library/Application Support/Übersicht/'
link .config/arc/StorableKeyBindings.json 'Library/Application Support/Arc/'
# for PROFILE in $(ls "$HOME/Library/Application Support/Firefox/Profiles/"); do
# link .config/firefox/user.js "Library/Application Support/Firefox/Profiles/$PROFILE"
# done
;;
esac