-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·65 lines (59 loc) · 1.72 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·65 lines (59 loc) · 1.72 KB
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
#!/usr/bin/env bash
# Idempotent: safe to run more than once. Existing files are backed up
# once, never clobbered silently.
set -euo pipefail
REPO_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
VSCODE_USER_DIR="${HOME}/.config/Code/User"
link() {
local src="$1" dst="$2"
mkdir -p "$(dirname "$dst")"
if [ -L "$dst" ] && [ "$(readlink -f "$dst")" = "$(readlink -f "$src")" ]; then
echo "ok $dst (already linked)"
return
fi
if [ -e "$dst" ]; then
mv "$dst" "${dst}.bak.$(date +%s)"
echo "backup $dst -> ${dst}.bak.*"
fi
ln -s "$src" "$dst"
echo "linked $dst -> $src"
}
echo "== dotfiles =="
link "$REPO_DIR/vscode/settings.json" "$VSCODE_USER_DIR/settings.json"
link "$REPO_DIR/git/gitconfig" "$HOME/.gitconfig"
echo ""
echo "== shell aliases =="
MARKER="# >>> dev-setup aliases >>>"
if ! grep -qF "$MARKER" "$HOME/.bashrc" 2>/dev/null; then
{
echo ""
echo "$MARKER"
echo "source \"$REPO_DIR/shell/aliases.sh\""
echo "# <<< dev-setup aliases <<<"
} >> "$HOME/.bashrc"
echo "added source line to ~/.bashrc"
else
echo "ok ~/.bashrc already sources aliases.sh"
fi
echo ""
echo "== VS Code extensions =="
if command -v code >/dev/null 2>&1; then
while read -r ext; do
if code --list-extensions | grep -qxF "$ext"; then
echo "ok $ext already installed"
else
code --install-extension "$ext" --force
fi
done < <(python3 - "$REPO_DIR/vscode/extensions.json" <<'PY'
import json, re, sys
raw = open(sys.argv[1]).read()
raw = re.sub(r"//.*", "", raw)
for ext in json.loads(raw)["recommendations"]:
print(ext)
PY
)
else
echo "skip 'code' CLI not found, install VS Code first"
fi
echo ""
echo "Done. Open a new shell (or 'source ~/.bashrc') to pick up the aliases."