88 echo " Please set \$ {WKDEV_SDK} to point to the root of the wkdev-sdk checkout."
99 exit 1
1010fi
11+ if [[ -z ${WKDEV_SDK_HOST} ]]; then
12+ echo " Please set \$ {WKDEV_SDK_HOST} to point to the wkdev-sdk checkout (from the host perspective). This is used when creating .desktop entries."
13+ exit 1
14+ fi
15+ if [[ -z ${WKDEV_CONTAINER_NAME_HOST} ]]; then
16+ echo " Please set \$ {WKDEV_CONTAINER_NAME_HOST} to the name of the wkdev container. This is used when creating .desktop entries."
17+ exit 1
18+ fi
19+ if [[ ! -d /host/${HOME} ]]; then
20+ echo " Host and container home must have the same path: /host/${HOME} "
21+ exit 1
22+ fi
1123source " ${WKDEV_SDK} /utilities/prerequisites.sh"
1224
1325init_application " ${0} " " Configures Visual Studio Code." container-only
@@ -17,8 +29,10 @@ verify_executables_exist curl
1729argsparse_allow_no_argument true
1830argsparse_use_option " =yes" " Assume yes for all prompts."
1931argsparse_use_option " no-extensions" " Don't install extensions."
32+ argsparse_use_option " no-proprietary" " Use VSCodium instead of VSCode."
2033
2134install_vscode () {
35+ CODE_EXEC=code
2236
2337 _log_ " "
2438 _log_ " Installing Visual Studio Code..."
@@ -40,7 +54,7 @@ install_vscode() {
4054 exit 1
4155 fi
4256
43- if ! sudo apt install /tmp/code.deb; then
57+ if ! sudo apt install -y /tmp/code.deb; then
4458 _log_ " Failed to install Visual Studio Code."
4559 rm /tmp/code.deb
4660 exit 1
@@ -51,6 +65,39 @@ install_vscode() {
5165 _log_ " Visual Studio Code has been installed."
5266}
5367
68+ install_vscodium () {
69+ CODE_EXEC=codium
70+
71+ _log_ " "
72+ _log_ " Installing Visual Studio Code (oss)..."
73+ _log_ " "
74+
75+ if which codium > /dev/null; then
76+ _log_ " Visual Studio Code (oss) is already installed."
77+ return
78+ fi
79+
80+ wget -qO - https://gitlab.com/paulcarroty/vscodium-deb-rpm-repo/raw/master/pub.gpg \
81+ | gpg --dearmor \
82+ | sudo dd of=/usr/share/keyrings/vscodium-archive-keyring.gpg
83+
84+ echo ' deb [ signed-by=/usr/share/keyrings/vscodium-archive-keyring.gpg ] https://download.vscodium.com/debs vscodium main' \
85+ | sudo tee /etc/apt/sources.list.d/vscodium.list
86+
87+ if ! sudo apt update; then
88+ _log_ " Failed to install Visual Studio Code (oss) repo."
89+ exit 1
90+ fi
91+
92+ if ! sudo apt install -y codium; then
93+ _log_ " Failed to install Visual Studio Code (oss)."
94+ exit 1
95+ fi
96+
97+ _log_ " "
98+ _log_ " Visual Studio Code (oss) has been installed."
99+ }
100+
54101install_extension () {
55102
56103 local extension_name=" ${1} "
@@ -59,7 +106,7 @@ install_extension() {
59106 local response
60107 local installed_extensions
61108
62- readarray installed_extensions < <( code --list-extensions)
109+ readarray installed_extensions < <( $CODE_EXEC --list-extensions)
63110
64111 if [[ " ${installed_extensions[*]} " =~ " ${extension_name} " ]]; then
65112 _log_ " VSCode extension already installed: ${extension_name} "
@@ -75,7 +122,7 @@ install_extension() {
75122 _log_ " Installing VSCode extension: ${extension_name} (${description} )..."
76123 fi
77124
78- if ! code --install-extension " ${extension_name} " & > /dev/null; then
125+ if ! ${CODE_EXEC} --install-extension " ${extension_name} " & > /dev/null; then
79126 _log_ " Failed to install VSCode extension: ${extension_name} "
80127 exit 1
81128 fi
@@ -96,15 +143,114 @@ install_extensions() {
96143 install_extension ms-python.python " Python support" true
97144}
98145
146+ # These are VERY helpful for WebKit development, but we won't override existing settings if the user already has them.
147+ default_settings () {
148+ if argsparse_is_option_set " no-proprietary" ; then
149+ VSCODE_CONFIG_PATH=${HOME} /.config/VSCodium/User/
150+ else
151+ VSCODE_CONFIG_PATH=${HOME} /.config/Code/User/
152+ fi
153+ if [[ ! -e " ${VSCODE_CONFIG_PATH} /settings.json" ]]; then
154+ mkdir -p " ${VSCODE_CONFIG_PATH} "
155+ tee " ${VSCODE_CONFIG_PATH} /settings.json" << HERE
156+ {
157+ "clangd.arguments": [
158+ "-header-insertion=never"
159+ ],
160+ "editor.renderWhitespace": "trailing",
161+ }
162+ HERE
163+ echo " Installed default VSCode settings to ${VSCODE_CONFIG_PATH} ."
164+ else
165+ echo " There was already a VSCode settings.json (${VSCODE_CONFIG_PATH} ), skipping."
166+ fi
167+ }
168+
169+ install_xdg () {
170+ tee " /host/${HOME} /.local/share/applications/code-${WKDEV_CONTAINER_NAME_HOST} .desktop" << HERE
171+ [Desktop Entry]
172+ Name=VSCode ${WKDEV_CONTAINER_NAME_HOST}
173+ Comment=Code Editing. Redefined.
174+ GenericName=Text Editor
175+ Exec="${WKDEV_SDK_HOST} /scripts/host-only/wkdev-enter" --name "${WKDEV_CONTAINER_NAME_HOST} " --exec --no-interactive -- $CODE_EXEC %F
176+ Icon=vscode-wkdev
177+ Type=Application
178+ StartupNotify=false
179+ StartupWMClass=VSCode
180+ Categories=TextEditor;Development;IDE;
181+ MimeType=text/plain;inode/directory;application/x-codium-workspace;
182+ Keywords=vscode;code;vscode;
183+ Actions=new-empty-window;
184+
185+ [Desktop Action new-empty-window]
186+ Name=New Empty Window
187+ Exec="${WKDEV_SDK_HOST} /scripts/host-only/wkdev-enter" --name "${WKDEV_CONTAINER_NAME_HOST} " --exec --no-interactive -- $CODE_EXEC --new-window %F
188+ Icon=vscode-wkdev
189+ HERE
190+ chmod +x " /host/${HOME} /.local/share/applications/code-${WKDEV_CONTAINER_NAME_HOST} .desktop"
191+ echo " Installed VSCode host launcher"
192+ }
193+
194+ install_xdg_oss () {
195+ tee " /host/${HOME} /.local/share/applications/codium-${WKDEV_CONTAINER_NAME_HOST} .desktop" << HERE
196+ [Desktop Entry]
197+ Name=VSCodium ${WKDEV_CONTAINER_NAME_HOST}
198+ Comment=Code Editing. Redefined.
199+ GenericName=Text Editor
200+ Exec="${WKDEV_SDK_HOST} /scripts/host-only/wkdev-enter" --name "${WKDEV_CONTAINER_NAME_HOST} " --exec --no-interactive -- $CODE_EXEC %F
201+ Icon=vscodium-wkdev
202+ Type=Application
203+ StartupNotify=false
204+ StartupWMClass=VSCodium
205+ Categories=TextEditor;Development;IDE;
206+ MimeType=text/plain;inode/directory;application/x-codium-workspace;
207+ Keywords=vscodium;codium;vscode;
208+ Actions=new-empty-window;
209+
210+ [Desktop Action new-empty-window]
211+ Name=New Empty Window
212+ Exec="${WKDEV_SDK_HOST} /scripts/host-only/wkdev-enter" --name "${WKDEV_CONTAINER_NAME_HOST} " --exec --no-interactive -- $CODE_EXEC --new-window %F
213+ Icon=vscodium-wkdev
214+ HERE
215+ chmod +x " /host/${HOME} /.local/share/applications/codium-${WKDEV_CONTAINER_NAME_HOST} .desktop"
216+ echo " Installed VSCodium host launcher"
217+ }
218+
219+ install_icon () {
220+ mkdir -p " /host/${HOME} /.local/share/icons/hicolor/256x256/apps/"
221+ cp /usr/share/pixmaps/vscode.png " /host/${HOME} /.local/share/icons/hicolor/256x256/apps/vscode-wkdev.png"
222+ echo " Installed VSCode host icon."
223+ }
224+
225+ install_icon_oss () {
226+ mkdir -p " /host/${HOME} /.local/share/icons/hicolor/256x256/apps/"
227+ cp /usr/share/pixmaps/vscodium.png " /host/${HOME} /.local/share/icons/hicolor/256x256/apps/vscodium-wkdev.png"
228+ echo " Installed VSCodium host icon."
229+ }
230+
99231run () {
100232
101233 argsparse_parse_options " ${@ } "
102234
103- install_vscode
235+ if argsparse_is_option_set " no-proprietary" ; then
236+ install_vscodium
237+ else
238+ install_vscode
239+ fi
104240
105241 if ! argsparse_is_option_set " no-extensions" ; then
106242 install_extensions
107243 fi
244+
245+ if argsparse_is_option_set " no-proprietary" ; then
246+ install_xdg_oss
247+ install_icon_oss
248+ else
249+ install_xdg
250+ install_icon
251+ fi
252+
253+ default_settings
108254}
109255
110256run " ${@ } "
0 commit comments