-
Notifications
You must be signed in to change notification settings - Fork 0
/
symup.sh
executable file
·92 lines (80 loc) · 2.53 KB
/
symup.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
91
92
#!/bin/bash
#
# symup.sh [Dotfile symlink manager]
#
#
# List of entries to ignore
IGNORE=".DS_Store .git .gitignore"
# Name of target dotfiles directory
DOTFILES="dotfiles"
# Paths of commands and script
BASEDIR=$(dirname $0)
LN=$(which ln)
SHASUM=$(which shasum)
function symlink {
$LN -nsf $1 $2
}
function checksum {
$SHASUM -a 512 $1
}
# Loop through dot entries
for ENTRY in "$BASEDIR"/.[^.]*
do
EBASE=$(basename $ENTRY)
ETARGET="$HOME/$EBASE"
EIGNORE=0
EDOTFILE="$DOTFILES/$EBASE"
# Ignore specific file or directory names
for IENTRY in $IGNORE
do
if [ "$IENTRY" = "$EBASE" ]; then
EIGNORE=1
fi
done
# Ignore entry
if [ $EIGNORE -eq 1 ]; then
echo -e "\x1B[93mIgnoring entry $EBASE\x1B[39m"
continue
fi
# Check for ~/.config directory
if [ -d "$EBASE" ]; then
echo -e "\x1B[91m$ETARGET is a directory. Symlinking subdirectories.\x1B[39m"
# Loop through subdirectories of ~/.config
for SUBENTRY in "$ENTRY"/*
do
SUBBASE=$(basename "$SUBENTRY")
SUBTARGET="$HOME/$EBASE/$SUBBASE"
SUBDOTFILE="$HOME/$DOTFILES/$EBASE/$SUBBASE"
# Check for existing symlink, create and/or update symlink in home directory
if [[ -h "$SUBTARGET" && ($(readlink "$SUBTARGET") == "$SUBDOTFILE") ]]; then
echo -e "\x1B[90m$SUBTARGET is linked to your dotfiles.\x1B[39m"
elif [[ -a "$SUBTARGET" ]]; then
read -p "$SUBTARGET exists and differs from your dotfile. Override? [yN] " REPLY
# Check answer
if [[ "$REPLY" =~ ^([yY]*)$ ]]; then
symlink "$SUBDOTFILE" "$HOME/$EBASE"
fi
else
echo -e "\x1B[92m$SUBTARGET does not exist. Linking to its dotfile.\x1B[39m"
symlink "$SUBDOTFILE" "$HOME/$EBASE"
fi
done
else
# Check for existing symlink, create and/or update symlink in home directory
if [[ -h "$ETARGET" && ($(readlink "$ETARGET") == "$EDOTFILE") ]]; then
echo -e "\x1B[90m$ETARGET is linked to your dotfiles.\x1B[39m"
elif [[ -f "$ETARGET" && $(checksum "$ETARGET" | awk '{print $2}') == $(checksum "$EBASE" | awk '{print $2}') ]]; then
echo -e "\x1B[93m$ETARGET exists and was identical to your dotfile. Overriding with symlink.\x1B[39m"
symlink "$EDOTFILE" "$HOME"
elif [[ -a "$ETARGET" ]]; then
read -p "$ETARGET exists and differs from your dotfile. Override? [yN] " REPLY
# Check answer
if [[ "$REPLY" =~ ^([yY]*)$ ]]; then
symlink "$EDOTFILE" "$HOME"
fi
else
echo -e "\x1B[92m$ETARGET does not exist. Linking to its dotfile.\x1B[39m"
symlink "$EDOTFILE" "$HOME"
fi
fi
done