VSCode workspace shortcuts with .desktop files on Linux

Published 4/28/2025

One big frustration I have with my workflow currently is that I open all my apps with the app launcher (the menu that appears when you press the command key ) except one: VSCode1. And that’s a big “but” because this is probably the app I use the most after my browser. Instead, I open a terminal and type code-oss repos/name-of-my-repo; if I don’t, it just opens VSCode with the last workspace instead of the one I specifically want. But today, no more! Today I fixed my workflow with a simple hack: generating .desktop files.

But what is a .desktop file?

A .desktop file, or rather a desktop entry file, is a very simple config that applications can use to register themselves with GNOME or KDE’s application system. For example, the reason you can find VSCode in the app launcher is because when you installed it, it created a file called code.desktop in one of the following locations:

The content of /usr/share/applications/code-oss.desktop on Alpine Linux is:

[Desktop Entry]
Name=Code - OSS
Comment=Code Editing. Redefined.
GenericName=Text Editor
Exec=/usr/bin/code-oss %F
Icon=com.visualstudio.code.oss
Type=Application
StartupNotify=false
StartupWMClass=Code - OSS
Categories=TextEditor;Development;IDE;
MimeType=application/x-code-oss-workspace;
Actions=new-empty-window;
Keywords=vscode;

[Desktop Action new-empty-window]
Name=New Empty Window
Name[de]=Neues leeres Fenster
Name[es]=Nueva ventana vacía
Name[fr]=Nouvelle fenêtre vide
Name[it]=Nuova finestra vuota
Name[ja]=新しい空のウィンドウ
Name[ko]=새 빈 창
Name[ru]=Новое пустое окно
Name[zh_CN]=新建空窗口
Name[zh_TW]=開新空視窗
Exec=/usr/bin/code-oss --new-window %F
Icon=com.visualstudio.code.oss

As you can see, it contains a lot of metadata to help your desktop environment present and launch the app correctly. Here is a quick presentation of each field:

If you are interested, there are other options for more advanced functionality described in the desktop-entry specification. Most of those options won’t be very useful to us, but it’s always good to know what we are working with.

How does that help me open a workspace quickly?

We could add a custom action to VSCode to open a specific folder, but the downside of that is that the action is hidden behind a right-click and is not directly searchable.

Instead, whatwe’re going to do is create a .desktop file for our workspace with a custom Exec to open this specific folder. Here is an example:

# ~/.local/share/applications/code-tinyfeed.desktop
[Desktop Entry]
Name=tinyfeed workspace
Comment=Open the repository directly with code
GenericName=Text Editor
Exec=code-oss "/home/sebastien/repos/tinyfeed"
Icon=com.visualstudio.code.oss
Type=Application
StartupNotify=false
StartupWMClass=Code - OSS
Categories=TextEditor;Development;IDE;
Keywords=vscode;

Let’s analyze it step by step:

This gives us the following search result in the app launcher when I search for “tinyfeed2”:

workspace-shortcut-1

And when we press Enter ⏎ it will open the tinyfeed workspace successfully

Okay but now I need to manually maintain a file for each repos?

Indeed, maintaining that by hand would be annoying but you can trivially write a bash script to automate the generation of .desktop files:

#!/bin/sh

# Ensure the script exit on error or unbound variables
set -eu

# Configuration
REPOSITORIES_DIRECTORY="$HOME/repos"
APPLICATIONS_DIR="$HOME/.local/share/applications"

# Ensure the applications directory exists
mkdir -p "$APPLICATIONS_DIR"

for repo_path in "$REPOSITORIES_DIRECTORY"/*/; do
    REPOSITORY=$(basename "$repo_path")
    DESKTOP_FILE="$APPLICATIONS_DIR/code-$REPOSITORY.desktop"

    cat > "$DESKTOP_FILE" <<EOF
[Desktop Entry]
Name=$REPOSITORY workspace
Comment=Open the repository directly with code
GenericName=Text Editor
Exec=code-oss "$REPOSITORIES_DIRECTORY/$REPOSITORY"
Icon=com.visualstudio.code.oss
Type=Application
StartupNotify=false
StartupWMClass=Code - OSS
Categories=TextEditor;Development;IDE;
MimeType=application/x-code-oss-workspace;
Keywords=vscode;
EOF

done

This script will create a templated .desktop file for each folder in the ~/repos directory. This means you need to have all of your workspaces inside a single directory in a flat manner for it to work, but you can probably adapt it with a more advanced directory listing algorithm if you need.

Then you only have to call it in your .bashrc, and your workspace shortcuts will be updated every time you open a terminal. You could also just do it in a cron job if you prefer.

This is the final result, all my workspaces are searchable in the app launcher:

workspace-shortcut-2

Just for completeness: another solution could have been to use a customizable app launcher like Ulauncher with a VSCode extension, but I like to keep my setup as standard as possible for portability.

Footnotes

  1. VSCode vs Code-OSS vs Codium: In this article, when I refer to VSCode I actually refer to code-oss, the open-source version of VSCode—not the proprietary version, and also not Codium, the open-source and slightly modified version of VSCode. It matters because I launch it with the command code-oss, not code. You might need to adapt my scripts accordingly. Same goes for file paths.

  2. Check out tinyfeed, a minimalist self-hosted RSS reader that generates static HTML pages for your consumption.