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,38 +29,66 @@ 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
21- install_vscode () {
22-
34+ install_vscode_or_codium () {
2335 _log_ " "
24- _log_ " Installing Visual Studio Code..."
36+ _log_ " Installing Visual Studio Code ( ${code_name_short} ) ..."
2537 _log_ " "
2638
27- if which code > /dev/null; then
28- _log_ " Visual Studio Code is already installed."
39+ if which $code_exec > /dev/null; then
40+ _log_ " Visual Studio Code ( ${code_name_short} ) is already installed."
2941 return
3042 fi
3143
32- local download_url= ' https://code.visualstudio.com/sha/download?build=stable&os=linux-deb-x64 '
44+ echo " Downloading ( ${code_name_short} ) from ${ download_url} . "
3345
34- if [ " $( uname -m) " = ' aarch64' ]; then
35- download_url=' https://code.visualstudio.com/sha/download?build=stable&os=linux-deb-arm64'
46+ if ! curl --silent --fail --location " ${download_url} " -o /tmp/${code_name_short} .tar.gz; then
47+ _log_ " Failed to download Visual Studio Code (${code_name_short} )."
48+ exit 1
3649 fi
3750
38- if ! curl --silent --fail --location " ${download_url} " -o /tmp/code.deb; then
39- _log_ " Failed to download Visual Studio Code."
51+ if ! sudo mkdir -p /opt/${code_name_short} ; then
52+ _log_ " Failed to make /opt/${code_name_short} ."
53+ rm /tmp/${code_name_short} .tar.gz
4054 exit 1
4155 fi
4256
43- if ! sudo apt install /tmp/code.deb ; then
44- _log_ " Failed to install Visual Studio Code."
45- rm /tmp/code.deb
57+ if ! sudo tar -xvf /tmp/${code_name_short} .tar.gz -C /opt/ ${code_name_short} ; then
58+ _log_ " Failed to install Visual Studio Code ( ${code_name_short} ) ."
59+ rm /tmp/${code_name_short} .tar.gz
4660 exit 1
4761 fi
4862
49- rm /tmp/code.deb
63+ rm /tmp/${code_name_short} .tar.gz
5064 _log_ " "
51- _log_ " Visual Studio Code has been installed."
65+ _log_ " Visual Studio Code (${code_name_short} ) has been installed."
66+ }
67+
68+ install_vscode () {
69+ arch=$( dpkg --print-architecture)
70+ code_exec=/opt/code/VSCode-linux-${arch} /bin/code
71+ code_icon=/opt/code/VSCode-linux-${arch} /resources/app/resources/linux/code.png
72+ code_name_short=code
73+ download_url=" https://code.visualstudio.com/sha/download?build=stable&os=linux-${arch} "
74+
75+ install_vscode_or_codium
76+ }
77+
78+ install_vscodium () {
79+ code_exec=/opt/codium/bin/codium
80+ arch=$( dpkg --print-architecture)
81+ code_icon=/opt/codium/resources/app/resources/linux/code.png
82+ code_name_short=codium
83+
84+ # Get the redirect to find the current version
85+ download_page=$( curl --url https://github.com/VSCodium/vscodium/releases/latest --output /dev/null --silent --location --head --write-out ' %{url_effective}' )
86+ url_parts=(${download_page// \/ / } )
87+ version=" ${url_parts[-1]} "
88+
89+ download_url=" https://github.com/VSCodium/vscodium/releases/download/${version} /VSCodium-linux-${arch} -${version} .tar.gz"
90+
91+ install_vscode_or_codium
5292}
5393
5494install_extension () {
@@ -59,7 +99,7 @@ install_extension() {
5999 local response
60100 local installed_extensions
61101
62- readarray installed_extensions < <( code --list-extensions)
102+ readarray installed_extensions < <( $code_exec --list-extensions)
63103
64104 if [[ " ${installed_extensions[*]} " =~ " ${extension_name} " ]]; then
65105 _log_ " VSCode extension already installed: ${extension_name} "
@@ -75,7 +115,7 @@ install_extension() {
75115 _log_ " Installing VSCode extension: ${extension_name} (${description} )..."
76116 fi
77117
78- if ! code --install-extension " ${extension_name} " & > /dev/null; then
118+ if ! ${code_exec} --install-extension " ${extension_name} " & > /dev/null; then
79119 _log_ " Failed to install VSCode extension: ${extension_name} "
80120 exit 1
81121 fi
@@ -96,15 +136,78 @@ install_extensions() {
96136 install_extension ms-python.python " Python support" true
97137}
98138
139+ # These are VERY helpful for WebKit development, but we won't override existing settings if the user already has them.
140+ default_settings () {
141+ if argsparse_is_option_set " no-proprietary" ; then
142+ VSCODE_CONFIG_PATH=${HOME} /.config/VSCodium/User/
143+ else
144+ VSCODE_CONFIG_PATH=${HOME} /.config/Code/User/
145+ fi
146+ if [[ ! -e " ${VSCODE_CONFIG_PATH} /settings.json" ]]; then
147+ mkdir -p " ${VSCODE_CONFIG_PATH} "
148+ tee " ${VSCODE_CONFIG_PATH} /settings.json" << HERE
149+ {
150+ "clangd.arguments": [
151+ "-header-insertion=never"
152+ ],
153+ "editor.renderWhitespace": "trailing",
154+ }
155+ HERE
156+ echo " Installed default VSCode settings to ${VSCODE_CONFIG_PATH} ."
157+ else
158+ echo " There was already a VSCode settings.json (${VSCODE_CONFIG_PATH} ), skipping."
159+ fi
160+ }
161+
162+ install_xdg () {
163+ tee " /host/${HOME} /.local/share/applications/${code_name_short} -${WKDEV_CONTAINER_NAME_HOST} .desktop" << HERE
164+ [Desktop Entry]
165+ Name=(${WKDEV_CONTAINER_NAME_HOST} )${code_name_short}
166+ Comment=Code Editing. Redefined.
167+ GenericName=Text Editor
168+ Exec="${WKDEV_SDK_HOST} /scripts/host-only/wkdev-enter" --name "${WKDEV_CONTAINER_NAME_HOST} " --exec --no-interactive -- ${code_exec} %F
169+ Icon=${code_name_short} -wkdev
170+ Type=Application
171+ StartupNotify=false
172+ StartupWMClass=VSCode
173+ Categories=TextEditor;Development;IDE;
174+ MimeType=text/plain;inode/directory;application/x-codium-workspace;
175+ Keywords=vscode;code;vscode;
176+ Actions=new-empty-window;
177+
178+ [Desktop Action new-empty-window]
179+ Name=New Empty Window
180+ Exec="${WKDEV_SDK_HOST} /scripts/host-only/wkdev-enter" --name "${WKDEV_CONTAINER_NAME_HOST} " --exec --no-interactive -- ${code_exec} --new-window %F
181+ Icon=${code_name_short} -wkdev
182+ HERE
183+ chmod +x " /host/${HOME} /.local/share/applications/${code_name_short} -${WKDEV_CONTAINER_NAME_HOST} .desktop"
184+ echo " Installed VSCode (${code_name_short} ) host launcher"
185+ }
186+
187+ install_icon () {
188+ mkdir -p " /host/${HOME} /.local/share/icons/hicolor/256x256/apps/"
189+ cp ${code_icon} " /host/${HOME} /.local/share/icons/hicolor/256x256/apps/${code_name_short} -wkdev.png"
190+ echo " Installed VSCode host icon."
191+ }
192+
99193run () {
100194
101195 argsparse_parse_options " ${@ } "
102196
103- install_vscode
197+ if argsparse_is_option_set " no-proprietary" ; then
198+ install_vscodium
199+ else
200+ install_vscode
201+ fi
104202
105203 if ! argsparse_is_option_set " no-extensions" ; then
106204 install_extensions
107205 fi
206+
207+ install_xdg
208+ install_icon
209+
210+ default_settings
108211}
109212
110213run " ${@ } "
0 commit comments