VSCode/Toolbx

A GUI script to run VSCode in a toolbox container.


Recently, I switched to [Fedora Silverblue] as my desktop operating system. To give a basic summary, Silverblue is an operating system where the system files are immutable, and can be restored to a previous state at any time. This version of Fedora does not ship the package manager dnf. Instead, you are expected to install applications in one of three ways:

Toolbx

I set up toolboxes for a few projects to test the waters:

Great, I’m all set up!

So… How do I develop in here?

Some DDGing led me to the amazing [toolbox-vscode] script. It gives you a script that you can place into ~/.local/bin/code. The first time you run it, it sets up everything for connecting to the container via VSCode’s remote feature, and launches it. The setup needs to be performed once per container, which wasn’t the most convenient, but oh well.

In which I have to have my GUIs

Previously, I would launch VSCode and pick my project from the Open Recent menu. The flow of

was far too janky. What I wanted was:

After some relearning Bash and overengineering later, I have a script in my hands.

vstlbx
#!/usr/bin/env bash

# Depends on: bash zenity

set -e

Title="VS Toolbx"
Text="Select a container to open in VS Code:"

## list-containers > containers
list-containers() {
	toolbox list --containers | tail -n +2 | tr -s ' +' "\t" | cut -f 2
}

## containers | user-pick-container > container
user-pick-container() {
	zenity \
		--title "$Title" \
		--text "$Text" \
		--list \
  	--column 'Name' \
  	--hide-header \
  	2>/dev/null
}

## get-project-dir container > project
get-project-dir() {
	if [ "$1" == "hyperscript" ]; then
		echo "$HOME/Projects/_hyperscript"
	else
		echo "$HOME/Projects/$1"
	fi
}

## run-container container
run-container() {
	toolbox run --container "$1" -- $(which code) $(get-project-dir "$1")
}

## run-ui
run-ui() {
	container=$(list-containers | user-pick-container)
	run-container "$container"
}

install-desktop-file() {
	desktop_file="$HOME/.local/share/applications/com.dz4k.vstlbx.desktop"
	cat <<-EOF >"$desktop_file"
		[Desktop Entry]
		Type=Application
		Name[en_US]=VS/Toolbx
		Categories=Development;
		X-GNOME-FullName[en_US]=VS/Toolbx
		Comment[en_US.UTF-8]=Attach VSCode to toolboxes
		NoDisplay=false
		Exec=/var/home/deniz/Applications/vstlbx
		Path=.
		Terminal=false
		X-GNOME-UsesNotifications=false
  	StartupWMClass=zenity
		Name[en_US.UTF-8]=VS/Toolbx
		X-GNOME-FullName[en_US.UTF-8]=VS/Toolbx
	EOF
}

if [ "$#" == 0 ]; then
	run-ui
	exit 0
fi

while [ "$#" -gt 0 ]; do
	case "$1" in
		'install-desktop')
			install-desktop-file
		;;
		'container')
			run-container "$2"
			shift
		;;
		'ui')
			run-ui
		;;
	esac
	shift
done

who needs Gists anyway

Here’s what the UI looks like:

A dialog with a list of container names: fedora-toolbox-35, hyperscript, this=week-in-htmx, www

I’m still getting myself set up, but I’m happy that I figured this part out early on.