Skip to content

Commit

Permalink
Merge branch 'owtaylor:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
mrBen authored Mar 13, 2022
2 parents 20e8b45 + 39e3881 commit 8e41af1
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 26 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ This repository is intended for scripts and hooks to integrate [Toolbox](https:/

In particular, it provides a `code.sh` script that:
* If necessary, prompts to install the Flatpak of Visual Studio Code
* If necessary, configures the current toolbox container to work with the [Remote Containers](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote) Visual Studio Code extension.
* If necessary, configures the current toolbox container to work with the [Remote Containers](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers) Visual Studio Code extension.
* Opens a VSCode window using the remaining command line arguments

Installation
Expand All @@ -14,6 +14,7 @@ Installation
```
git clone https://github.com/owtaylor/toolbox-vscode.git
cd toolbox-vscode
[ -d ~/.local/bin ] || mkdir ~/.local/bin
ln -s "$PWD/code.sh" ~/.local/bin/code
```

Expand Down
28 changes: 17 additions & 11 deletions code.sh
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ fi
# different toolboxes step on each other.

homevar="$(flatpak-spawn --host podman inspect "$container_name" \
--format='{{ range .Config.Env }}{{ . }}{{"\n"}}{{ end }}' \
--format='{{ range .Config.Env }}{{ println . }}{{ end }}' \
| grep ^HOME=)"
homevar="${homevar#HOME=}"

Expand Down Expand Up @@ -383,16 +383,21 @@ if $toolbox_reset_configuration || [ ! -f $settings ] ; then
{
"remote.containers.copyGitConfig": false,
"remote.containers.gitCredentialHelperConfigLocation": "none",
"terminal.integrated.shell.linux": "/usr/sbin/capsh",
"terminal.integrated.shellArgs.linux": [
"--caps=",
"--",
"-c",
"exec \"\$@\"",
"/bin/sh",
"$SHELL",
"-l"
]
"terminal.integrated.defaultProfile.linux": "toolbox",
"terminal.integrated.profiles.linux": {
"toolbox": {
"path": "/usr/sbin/capsh",
"args": [
"--caps=",
"--",
"-c",
"exec \"\$@\"",
"/bin/sh",
"$SHELL",
"-l"
]
}
}
}
EOF
fi
Expand Down Expand Up @@ -459,6 +464,7 @@ else
$verbose && set -x
$flatpak enter "$existing" sh -c "$script" "$PWD" "$HOME" \
/app/extra/vscode/code /app/extra/vscode/resources/app/out/cli.js \
--ms-enable-electron-run-as-node \
--extensions-dir="$HOME/.var/app/com.visualstudio.code/data/vscode/extensions" \
--remote attached-container+"$container_name_encoded" "${new_args[@]}"
fi
33 changes: 19 additions & 14 deletions tests/test-basic.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ test_basic() {

assert_contents /logs/basic.cmd <<'EOF'
flatpak list --app --columns=application
podman inspect toolbox-vscode-test --format={{ range .Config.Env }}{{ . }}{{"\n"}}{{ end }}
podman inspect toolbox-vscode-test --format={{ range .Config.Env }}{{ println . }}{{ end }}
flatpak ps --columns=instance,application,pid
flatpak run com.visualstudio.code --remote attached-container+746f6f6c626f782d7673636f64652d74657374 /home/testuser/project
EOF
Expand All @@ -26,16 +26,21 @@ EOF
{
"remote.containers.copyGitConfig": false,
"remote.containers.gitCredentialHelperConfigLocation": "none",
"terminal.integrated.shell.linux": "/usr/sbin/capsh",
"terminal.integrated.shellArgs.linux": [
"--caps=",
"--",
"-c",
"exec \"$@\"",
"/bin/sh",
"/bin/bash",
"-l"
]
"terminal.integrated.defaultProfile.linux": "toolbox",
"terminal.integrated.profiles.linux": {
"toolbox": {
"path": "/usr/sbin/capsh",
"args": [
"--caps=",
"--",
"-c",
"exec \"$@\"",
"/bin/sh",
"/bin/bash",
"-l"
]
}
}
}
EOF

Expand Down Expand Up @@ -66,7 +71,7 @@ test_installation() {
flatpak list --app --columns=application
flatpak remotes --columns=name
flatpak install flathub com.visualstudio.code
podman inspect toolbox-vscode-test --format={{ range .Config.Env }}{{ . }}{{"\n"}}{{ end }}
podman inspect toolbox-vscode-test --format={{ range .Config.Env }}{{ println . }}{{ end }}
flatpak ps --columns=instance,application,pid
flatpak run com.visualstudio.code --remote attached-container+746f6f6c626f782d7673636f64652d74657374 /home/testuser/project
EOF
Expand Down Expand Up @@ -98,7 +103,7 @@ test_running() {

assert_contents /logs/running.cmd <<'EOF'
flatpak list --app --columns=application
podman inspect toolbox-vscode-test --format={{ range .Config.Env }}{{ . }}{{"\n"}}{{ end }}
podman inspect toolbox-vscode-test --format={{ range .Config.Env }}{{ println . }}{{ end }}
flatpak ps --columns=instance,application,pid
flatpak enter 123456 sh -c
cd $0
Expand All @@ -114,6 +119,6 @@ flatpak enter 123456 sh -c
ELECTRON_RUN_AS_NODE=1 \
PATH="${PATH}:$XDG_CONFIG_HOME/node_modules/bin" \
exec "$@"
/home/testuser/project /home/testuser /app/extra/vscode/code /app/extra/vscode/resources/app/out/cli.js --extensions-dir=/home/testuser/.var/app/com.visualstudio.code/data/vscode/extensions --remote attached-container+746f6f6c626f782d7673636f64652d74657374 /home/testuser/project
/home/testuser/project /home/testuser /app/extra/vscode/code /app/extra/vscode/resources/app/out/cli.js --ms-enable-electron-run-as-node --extensions-dir=/home/testuser/.var/app/com.visualstudio.code/data/vscode/extensions --remote attached-container+746f6f6c626f782d7673636f64652d74657374 /home/testuser/project
EOF
}

0 comments on commit 8e41af1

Please sign in to comment.