-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvscode.sh
More file actions
executable file
·147 lines (121 loc) · 4.79 KB
/
Copy pathvscode.sh
File metadata and controls
executable file
·147 lines (121 loc) · 4.79 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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#!/bin/bash
set -euo pipefail
IDE_POSSIBLE_CONFIG_FILES=(
"$HOME/.config/Code/User/settings.json"
"$HOME/.config/Cursor/User/settings.json"
"$HOME/Library/Application Support/Code/User/settings.json"
"$HOME/Library/Application Support/Cursor/User/settings.json"
)
if [ -f "$PROVISION_CONFIG"/gui-vscode ]; then
rm -rf /tmp/current-vscode-extensions
fi
if [ -f "$PROVISION_CONFIG"/gui-cursor ]; then
rm -rf /tmp/current-cursor-extensions
fi
add_vscode_extension() {
if [ -f "$PROVISION_CONFIG"/gui-vscode ] || [ -f "$PROVISION_CONFIG"/gui-cursor ]; then
if [ -f "$PROVISION_CONFIG"/gui-vscode ] && [ "${2:-}" != "cursor" ]; then
if ! type code >/dev/null; then
echo "VSCode 未安裝,正在跳過擴充安裝: $1"
return
fi
if [ ! -f /tmp/current-vscode-extensions ]; then
code --list-extensions | sort -V >/tmp/current-vscode-extensions
fi
if [ -z "$(cat /tmp/current-vscode-extensions | grep "$1" || true)" ]; then
code --install-extension "$1"
fi
fi
if [ -f "$PROVISION_CONFIG"/gui-cursor ] && [ "${2:-}" != "vscode" ]; then
if ! type cursor >/dev/null 2>&1; then
if [ $IS_NIXOS != "1" ]; then
echo "Cursor 未安裝,正在跳過擴充安裝: https://cursor.com/home"
fi
return
fi
if [ ! -f /tmp/current-cursor-extensions ]; then
cursor --list-extensions | sort -V >/tmp/current-cursor-extensions
fi
if [ -z "$(cat /tmp/current-cursor-extensions | grep "$1" || true)" ]; then
cursor --install-extension "$1"
fi
fi
fi
}
provision_setup_vscode() {
if [ ! -f "$PROVISION_CONFIG"/gui-vscode ] && [ ! -f "$PROVISION_CONFIG"/gui-cursor ]; then
return
fi
for POSSIBLE_CONFIG_FILE in "${IDE_POSSIBLE_CONFIG_FILES[@]}"; do
local DIR_PATH="$(dirname "$POSSIBLE_CONFIG_FILE")"
if [ -d "$DIR_PATH" ]; then
cat ~/development/environment/src/config-files/vscode/settings.json |
jq -S >"$POSSIBLE_CONFIG_FILE"
jq --argjson new_data "$(cat ~/development/environment/src/config-files/vscode/vim-normal-mappings.json)" \
'."vim.normalModeKeyBindingsNonRecursive" = $new_data' \
"$POSSIBLE_CONFIG_FILE" | sponge "$POSSIBLE_CONFIG_FILE"
jq --argjson new_data "$(cat ~/development/environment/src/config-files/vscode/vim-visual-mappings.json)" \
'."vim.visualModeKeyBindingsNonRecursive" = $new_data' \
"$POSSIBLE_CONFIG_FILE" | sponge "$POSSIBLE_CONFIG_FILE"
cp $HOME/development/environment/src/config-files/vscode/common.code-snippets \
"$DIR_PATH"/snippets
mkdir -p "$DIR_PATH"/prompts
cp $HOME/development/environment/src/config-files/vscode/prompts/* \
"$DIR_PATH"/prompts
fi
done
add_vscode_extension "waderyan.gitblame"
add_vscode_extension "vscodevim.vim"
add_vscode_extension "jkillian.custom-local-formatters"
add_vscode_extension "cocopon.iceberg-theme"
add_vscode_extension "eamodio.gitlens"
if type ccls >/dev/null 2>&1; then
add_vscode_extension "ccls-project.ccls"
fi
# add_vscode_extension "ms-vscode-remote.remote-ssh" vscode
# add_vscode_extension "ms-vscode-remote.remote-ssh-edit" vscode
KEYBINDINGS_PATHS=(
"$HOME/.config/Cursor/User/keybindings.json"
"$HOME/.config/Code/User/keybindings.json"
"$HOME/Library/Application Support/Cursor/User/keybindings.json"
"$HOME/Library/Application Support/Code/User/keybindings.json"
)
for KEYBINDINGS_PATH in "${KEYBINDINGS_PATHS[@]}"; do
if [ -d "$(dirname "$KEYBINDINGS_PATH")" ]; then
cp $HOME/development/environment/src/config-files/vscode/key-mappings.json "$KEYBINDINGS_PATH"
fi
done
if [ ! -f "$PROVISION_CONFIG"/no-copilot ]; then
add_vscode_extension "github.copilot" vscode
fi
if [ "$IS_NIXOS" = "1" ] && [ -f "$PROVISION_CONFIG"/gui-cursor ]; then
add_desktop_common \
"$HOME/development/environment/src/scripts/misc/cursor_appimage.sh" 'cursor-appimage' 'Cursor AppImage'
fi
VSIX_FILE="$HOME/development/environment/src/vscode-extension/igncp-vscode-extension-0.0.1.vsix"
if [ "${PROVISION_REINSTALL_EXTENSIONS:-}" = "1" ]; then
rm -f "$VSIX_FILE"
fi
if [ ! -f "$VSIX_FILE" ]; then
cd ~/development/environment/src/vscode-extension
if type "bun" >/dev/null 2>&1; then
bun i && bun run package
else
npm i && npm run package
fi
type code >/dev/null 2>&1 && code --install-extension "$VSIX_FILE"
type cursor >/dev/null 2>&1 && cursor --install-extension "$VSIX_FILE"
fi
cat >>~/.shellrc <<"EOF"
if [ -d /Applications/Cursor.app/Contents/Resources/app/bin ]; then
export PATH="/Applications/Cursor.app/Contents/Resources/app/bin/:$PATH"
fi
EOF
cat >>~/.shell_aliases <<"EOF"
if type cursor >/dev/null 2>&1; then
alias XargsN='xargs cursor'
else
alias XargsN='xargs code'
fi
EOF
}