-
-
Notifications
You must be signed in to change notification settings - Fork 143
/
setup
executable file
·94 lines (80 loc) · 2.55 KB
/
setup
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
93
94
#!/bin/sh
# Install all dotfiles into the home directory
if [ -L "$0" ]; then
SCRIPTSETUP="$(readlink "$0")"
else
SCRIPTSETUP="$0"
fi
DOTFILESDIRREL=$(dirname "$SCRIPTSETUP")
cd "$DOTFILESDIRREL"/.. || exit
DOTFILESDIR=$(pwd -P)
[ $(uname -s) = "Darwin" ] && export MACOS=1 && export UNIX=1
[ $(uname -s) = "Linux" ] && export LINUX=1 && export UNIX=1
uname -s | grep -q "_NT-" && export WINDOWS=1
if [ "$MACOS" ]; then
VSCODE="$HOME/Library/Application Support/Code/User"
CURSOR="$HOME/Library/Application Support/Cursor/User"
elif [ "$LINUX" ]; then
VSCODE="$HOME/.config/Code/User"
CURSOR="$HOME/.config/Cursor/User"
elif [ "$WINDOWS" ]; then
VSCODE="$APPDATA/Code/User"
CURSOR="$APPDATA/Cursor/User"
fi
for DOTFILE in *; do
HOMEFILE="$HOME/.$DOTFILE"
[ -d "$DOTFILE" ] && DOTFILE="$DOTFILE/"
DIRFILE="$DOTFILESDIR/$DOTFILE"
# Don't mess with Codespaces' default GPG/SSH setup.
if [ -n "$CODESPACES" ]; then
echo "$DOTFILE" | egrep -q '^(gnupg|ssh)/' && continue
fi
# Don't try to install documentation/script files
echo "$DOTFILE" | egrep -q '(^script/$|\.txt$|\.md$)' && continue
# Fixup VSCode settings path
echo "$DOTFILE" | grep -q 'vscode-settings' &&
HOMEFILE="$VSCODE/settings.json" &&
mkdir -p "$VSCODE"
# Fixup Cursor settings path
echo "$DOTFILE" | grep -q 'cursor-settings' &&
HOMEFILE="$CURSOR/settings.json" &&
mkdir -p "$CURSOR"
# Fixup Cursor keybindings path
echo "$DOTFILE" | grep -q 'vscode-keybindings' &&
HOMEFILE="$CURSOR/keybindings.json" &&
mkdir -p "$CURSOR"
# Remove .sh extensions
echo "$DOTFILE" | grep -q '\.sh' &&
HOMEFILE="$HOME/.$(echo "$DOTFILE" | sed -e 's/\.sh//')"
# Fixup RuboCop configuration (if possible)
if echo "$DOTFILE" | grep -q 'rubocop-work.yml'; then
HOMEWORK="$HOME/Workbrew"
[ -d "$HOMEWORK" ] || continue
HOMEFILE="$HOMEWORK/.rubocop.yml"
elif echo "$DOTFILE" | grep -q 'rubocop-oss.yml'; then
HOMEOSS="$HOME/OSS"
[ -d "$HOMEOSS" ] || continue
HOMEFILE="$HOMEOSS/.rubocop.yml"
fi
if [ "$UNIX" ]; then
if ! [ -d "$DOTFILE" ]; then
if [ -L "$HOMEFILE" ]; then
ln -sf "$DIRFILE" "$HOMEFILE"
else
ln -svf "$DIRFILE" "$HOMEFILE"
fi
elif [ -L "$HOMEFILE" ]; then
rm -r "$HOMEFILE" 2>/dev/null
ln -s "$DIRFILE" "$HOMEFILE"
else
rm -rv "$HOMEFILE" 2>/dev/null
ln -sv "$DIRFILE" "$HOMEFILE"
fi
else
cp -rv "$DIRFILE" "$HOMEFILE"
fi
done
HOMEDOTFILES="$HOME/.dotfiles"
if [ "$DOTFILESDIR" != "$HOMEDOTFILES" ]; then
ln -sf "$DOTFILESDIR" "$HOMEDOTFILES"
fi