-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrestore.sh
More file actions
120 lines (100 loc) · 4.04 KB
/
Copy pathrestore.sh
File metadata and controls
120 lines (100 loc) · 4.04 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
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#!/usr/bin/env bash
set -euo pipefail
# restore.sh — restores VS Code configuration from this repo to the live system.
# Companion to copy.sh (which captures VS Code config) and install.sh (which
# handles shell/vim/cheat config but not VS Code).
#
# Run this after install.sh on any host where you want VS Code settings restored.
read -p "Are you sure you wish to overwrite VS Code config on this system? (yes/no): " confirm
if [[ "$confirm" != "yes" ]]; then
echo "Aborting."
exit 1
fi
# Ensure the parent directory of a destination file exists. If the destination
# is a symlink, resolve it and create the parent of the symlink's target so
# that `cp` (which follows symlinks) can write through it.
ensure_dest_dir() {
local dest="$1"
if [[ -L "$dest" ]]; then
local target
target="$(readlink "$dest")"
if [[ "$target" != /* ]]; then
target="$(dirname "$dest")/$target"
fi
mkdir -p "$(dirname "$target")"
else
mkdir -p "$(dirname "$dest")"
fi
}
if [[ "$(uname -s)" == "Linux" ]]; then
echo "Restoring VS Code config for Fedora"
dotfiles_vscode="$HOME/.dotfiles/vscode/personal"
mkdir -p "$HOME/.config/Code/User/snippets"
ensure_dest_dir "$HOME/.config/Code/User/settings.json"
cp -v \
"$dotfiles_vscode/.config/Code/User/settings.json" \
"$HOME/.config/Code/User/settings.json"
ensure_dest_dir "$HOME/.config/Code/User/chatLanguageModels.json"
cp -v \
"$dotfiles_vscode/.config/Code/User/chatLanguageModels.json" \
"$HOME/.config/Code/User/chatLanguageModels.json"
rsync -av --delete \
"$dotfiles_vscode/.config/Code/User/snippets/" \
"$HOME/.config/Code/User/snippets/"
if [[ -f "$dotfiles_vscode/.config/Code/User/keybindings.json" ]]; then
ensure_dest_dir "$HOME/.config/Code/User/keybindings.json"
cp -v \
"$dotfiles_vscode/.config/Code/User/keybindings.json" \
"$HOME/.config/Code/User/keybindings.json"
fi
# Restore project settings if the project directory exists
pastebooks_dir="$HOME/Projects/public/pastebooks"
if [[ -d "$pastebooks_dir" ]]; then
mkdir -p "$pastebooks_dir/.vscode"
ensure_dest_dir "$pastebooks_dir/.vscode/settings.json"
cp -v \
"$dotfiles_vscode/Projects/public/pastebooks/.vscode/settings.json" \
"$pastebooks_dir/.vscode/settings.json"
fi
# home-projects.code-workspace is NOT restored here. It lives in the
# vscode-personal stow package and is symlinked into ~/Projects by
# install.sh, so edits to it are tracked in git the moment they are made.
# Copying it here would replace that symlink with a stale regular file.
elif [[ "$(uname -s)" == "Darwin" ]]; then
echo "Restoring VS Code config for macOS"
dotfiles_vscode="$HOME/.dotfiles/vscode/professional"
vscode_user="$HOME/Library/Application Support/Code/User"
mkdir -p "$vscode_user"
ensure_dest_dir "$vscode_user/settings.json"
cp -v \
"$dotfiles_vscode/Library/Application Support/Code/User/settings.json" \
"$vscode_user/settings.json"
ensure_dest_dir "$vscode_user/keybindings.json"
cp -v \
"$dotfiles_vscode/Library/Application Support/Code/User/keybindings.json" \
"$vscode_user/keybindings.json"
projects_dir="$HOME/Projects"
if [[ -d "$projects_dir" ]]; then
ensure_dest_dir "$projects_dir/kevins-work.code-workspace"
cp -v \
"$dotfiles_vscode/Projects/kevins-work.code-workspace" \
"$projects_dir/kevins-work.code-workspace"
if [[ -f "$dotfiles_vscode/Projects/kevins-acst.code-workspace" ]]; then
ensure_dest_dir "$projects_dir/kevins-acst.code-workspace"
cp -v \
"$dotfiles_vscode/Projects/kevins-acst.code-workspace" \
"$projects_dir/kevins-acst.code-workspace"
fi
fi
else
echo "Unrecognized OS '$(uname -s)' — no VS Code config defined for this platform."
exit 1
fi
# Restore extensions
if command -v code &>/dev/null && [[ -f "$dotfiles_vscode/extensions.txt" ]]; then
echo "Installing VS Code extensions..."
while IFS= read -r ext; do
code --install-extension "$ext" --force
done < "$dotfiles_vscode/extensions.txt"
fi
echo "VS Code restore complete."