Skip to content

Commit 3e1d171

Browse files
committed
- Allow installing VSCodium
- Add helpful clangd default settings - Make VSCode .application file by default
1 parent 9d84de4 commit 3e1d171

File tree

3 files changed

+158
-4
lines changed

3 files changed

+158
-4
lines changed

scripts/container-only/wkdev-setup-vscode

+152-4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@ else
88
echo "Please set \${WKDEV_SDK} to point to the root of the wkdev-sdk checkout."
99
exit 1
1010
fi
11+
if [[ -z ${WKDEV_SDK_HOST} ]]; then
12+
echo "Please set \${WKDEV_SDK_HOST} to point to the the wkdev-sdk checkout (from the host perspective). This is used when creating .desktop entries."
13+
exit 1
14+
fi
15+
if [[ ! -d /host/${HOME} ]]; then
16+
echo "Host and container home must have the same path: /host/${HOME}"
17+
exit 1
18+
fi
1119
source "${WKDEV_SDK}/utilities/prerequisites.sh"
1220

1321
init_application "${0}" "Configures Visual Studio Code." container-only
@@ -17,8 +25,10 @@ verify_executables_exist curl
1725
argsparse_allow_no_argument true
1826
argsparse_use_option "=yes" "Assume yes for all prompts."
1927
argsparse_use_option "no-extensions" "Don't install extensions."
28+
argsparse_use_option "no-proprietary" "Use VSCodium instead of VSCode."
2029

2130
install_vscode() {
31+
CODE_EXEC=code
2232

2333
_log_ ""
2434
_log_ "Installing Visual Studio Code..."
@@ -40,7 +50,7 @@ install_vscode() {
4050
exit 1
4151
fi
4252

43-
if ! sudo apt install /tmp/code.deb; then
53+
if ! sudo apt install -y /tmp/code.deb; then
4454
_log_ "Failed to install Visual Studio Code."
4555
rm /tmp/code.deb
4656
exit 1
@@ -51,15 +61,50 @@ install_vscode() {
5161
_log_ "Visual Studio Code has been installed."
5262
}
5363

64+
install_vscodium() {
65+
CODE_EXEC=codium
66+
67+
_log_ ""
68+
_log_ "Installing Visual Studio Code (oss)..."
69+
_log_ ""
70+
71+
if which codium > /dev/null; then
72+
_log_ "Visual Studio Code (oss) is already installed."
73+
return
74+
fi
75+
76+
wget -qO - https://gitlab.com/paulcarroty/vscodium-deb-rpm-repo/raw/master/pub.gpg \
77+
| gpg --dearmor \
78+
| sudo dd of=/usr/share/keyrings/vscodium-archive-keyring.gpg
79+
80+
echo 'deb [ signed-by=/usr/share/keyrings/vscodium-archive-keyring.gpg ] https://download.vscodium.com/debs vscodium main' \
81+
| sudo tee /etc/apt/sources.list.d/vscodium.list
82+
83+
if ! sudo apt update; then
84+
_log_ "Failed to install Visual Studio Code (oss) repo."
85+
exit 1
86+
fi
87+
88+
if ! sudo apt install -y codium; then
89+
_log_ "Failed to install Visual Studio Code (oss)."
90+
exit 1
91+
fi
92+
93+
_log_ ""
94+
_log_ "Visual Studio Code (oss) has been installed."
95+
}
96+
5497
install_extension() {
5598

99+
sudo chown "${USER}" "${HOME}/.config"
100+
56101
local extension_name="${1}"
57102
local description="${2}"
58103
local ask="${3:-false}"
59104
local response
60105
local installed_extensions
61106

62-
readarray installed_extensions < <(code --list-extensions)
107+
readarray installed_extensions < <($CODE_EXEC --list-extensions)
63108

64109
if [[ "${installed_extensions[*]}" =~ "${extension_name}" ]]; then
65110
_log_ "VSCode extension already installed: ${extension_name}"
@@ -75,7 +120,7 @@ install_extension() {
75120
_log_ "Installing VSCode extension: ${extension_name} (${description})..."
76121
fi
77122

78-
if ! code --install-extension "${extension_name}" &>/dev/null; then
123+
if ! ${CODE_EXEC} --install-extension "${extension_name}" &>/dev/null; then
79124
_log_ "Failed to install VSCode extension: ${extension_name}"
80125
exit 1
81126
fi
@@ -96,15 +141,118 @@ install_extensions() {
96141
install_extension ms-python.python "Python support" true
97142
}
98143

144+
# These are VERY helpful for WebKit development, but we won't override existing settings if the user already has them.
145+
default_settings() {
146+
if argsparse_is_option_set "no-proprietary"; then
147+
VSCODE_CONFIG_PATH=${HOME}/.config/VSCodium/User/
148+
else
149+
VSCODE_CONFIG_PATH=${HOME}/.config/Code/User/
150+
fi
151+
if [[ ! -e "${VSCODE_CONFIG_PATH}/settings.json" ]]; then
152+
mkdir -p "${VSCODE_CONFIG_PATH}"
153+
tee "${VSCODE_CONFIG_PATH}/settings.json" << HERE
154+
{
155+
"clangd.arguments": [
156+
"-header-insertion=never"
157+
],
158+
"editor.renderWhitespace": "trailing",
159+
"workbench.colorCustomizations": {
160+
"editorWhitespace.foreground": "#FF0000",
161+
"editorWhitespace.background": "#FF0000"
162+
},
163+
}
164+
HERE
165+
echo "Installed default VSCode settings to ${VSCODE_CONFIG_PATH}."
166+
else
167+
echo "There was already a VSCode settings.json (${VSCODE_CONFIG_PATH}), skipping."
168+
fi
169+
}
170+
171+
install_xdg() {
172+
tee "/host/${HOME}/.local/share/applications/code-wkdev.desktop" << HERE
173+
[Desktop Entry]
174+
Name=VSCode WKDev
175+
Comment=Code Editing. Redefined.
176+
GenericName=Text Editor
177+
Exec="${WKDEV_SDK_HOST}/scripts/host-only/wkdev-enter" --exec --no-interactive -- $CODE_EXEC %F
178+
Icon=vscode-wkdev
179+
Type=Application
180+
StartupNotify=false
181+
StartupWMClass=VSCode
182+
Categories=TextEditor;Development;IDE;
183+
MimeType=text/plain;inode/directory;application/x-codium-workspace;
184+
Keywords=vscode;code;vscode;
185+
Actions=new-empty-window;
186+
187+
[Desktop Action new-empty-window]
188+
Name=New Empty Window
189+
Exec="${WKDEV_SDK_HOST}/scripts/host-only/wkdev-enter" --exec --no-interactive -- $CODE_EXEC --new-window %F
190+
Icon=vscode-wkdev
191+
HERE
192+
chmod +x "/host/${HOME}/.local/share/applications/code-wkdev.desktop"
193+
echo "Installed VSCode host launcher"
194+
}
195+
196+
install_xdg_oss() {
197+
tee "/host/${HOME}/.local/share/applications/codium-wkdev.desktop" << HERE
198+
[Desktop Entry]
199+
Name=VSCodium WKDev
200+
Comment=Code Editing. Redefined.
201+
GenericName=Text Editor
202+
Exec="${WKDEV_SDK_HOST}/scripts/host-only/wkdev-enter" --exec --no-interactive -- $CODE_EXEC %F
203+
Icon=vscodium-wkdev
204+
Type=Application
205+
StartupNotify=false
206+
StartupWMClass=VSCodium
207+
Categories=TextEditor;Development;IDE;
208+
MimeType=text/plain;inode/directory;application/x-codium-workspace;
209+
Keywords=vscodium;codium;vscode;
210+
Actions=new-empty-window;
211+
212+
[Desktop Action new-empty-window]
213+
Name=New Empty Window
214+
Exec="${WKDEV_SDK_HOST}/scripts/host-only/wkdev-enter" --exec --no-interactive -- $CODE_EXEC --new-window %F
215+
Icon=vscodium-wkdev
216+
HERE
217+
chmod +x "/host/${HOME}/.local/share/applications/codium-wkdev.desktop"
218+
echo "Installed VSCodium host launcher"
219+
}
220+
221+
install_icon() {
222+
mkdir -p "/host/${HOME}/.local/share/icons/hicolor/256x256/apps/"
223+
cp /usr/share/pixmaps/vscode.png "/host/${HOME}/.local/share/icons/hicolor/256x256/apps/vscode-wkdev.png"
224+
echo "Installed VSCode host icon."
225+
}
226+
227+
install_icon_oss() {
228+
mkdir -p "/host/${HOME}/.local/share/icons/hicolor/256x256/apps/"
229+
cp /usr/share/pixmaps/vscodium.png "/host/${HOME}/.local/share/icons/hicolor/256x256/apps/vscodium-wkdev.png"
230+
echo "Installed VSCodium host icon."
231+
}
232+
99233
run() {
100234

101235
argsparse_parse_options "${@}"
102236

103-
install_vscode
237+
if argsparse_is_option_set "no-proprietary"; then
238+
install_vscodium
239+
else
240+
install_vscode
241+
fi
104242

105243
if ! argsparse_is_option_set "no-extensions"; then
106244
install_extensions
107245
fi
246+
247+
if argsparse_is_option_set "no-proprietary"; then
248+
install_xdg_oss
249+
install_icon_oss
250+
else
251+
install_xdg
252+
install_icon
253+
fi
254+
255+
default_settings
108256
}
109257

110258
run "${@}"

scripts/host-only/wkdev-create

+3
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,9 @@ build_podman_create_arguments() {
431431
# Always set XDG_RUNTIME_DIR to the same value.
432432
arguments+=("--env" "XDG_RUNTIME_DIR=/run/user/${host_user_id}")
433433

434+
# This is needed for some scripts like wkdev-setup-vscode
435+
arguments+=("--env" "WKDEV_SDK_HOST=${WKDEV_SDK}")
436+
434437
if argsparse_is_option_set "no-pull"; then
435438
arguments+=("--pull=never")
436439
else

scripts/host-only/wkdev-enter

+3
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,9 @@ run() {
169169
# Ensure WKDEV_SDK is set. It is done here and not creation to support older containers.
170170
podman_exec_arguments+=("--env" "WKDEV_SDK=/wkdev-sdk")
171171

172+
# This is needed for some scripts like wkdev-setup-vscode
173+
podman_exec_arguments+=("--env" "WKDEV_SDK_HOST=${WKDEV_SDK}")
174+
172175
# Choose root or regular user.
173176
if argsparse_is_option_set "root"; then
174177
podman_exec_arguments+=("--user" "0:0")

0 commit comments

Comments
 (0)