Skip to main content

GNOME menu entries for Visual Studio Code projects

I work on a large number of code projects and I wanted a quick way to open any of my projects in Visual Studio Code, my preferred code editor. I figured the quickest way to do this under GNOME would be to create a .desktop file for each project directory. The idea being, I could just hit the Super key to bring up GNOME's overview, before typing a few characters to open a project.

To achieve this, I first spent a little while creating a file named .projectname in the root of each project directory. The file simply contained a short name for the project, something like ProjectFoo. I could have automated this process, but I wanted to use a custom short name for each project, as opposed to using the directory name or some other readable value. Also, the GNOME overview only shows limited characters for each entry with long names being truncated, so a short name was a must.

Next, I created a shell script to automate the process of creating the .desktop files. All my projects live under ~/Projects, so the script does a recursive lookup to find all .projectname files and creates a .desktop file in ~/.local/share/applications for each one. The .desktop files are all identical apart from their Name and Exec values.

The script:

#!/bin/bash

# Define the base Projects directory
PROJECTS_DIR="$HOME/Projects"

# Define the target application directory
APP_DIR="$HOME/.local/share/applications"
mkdir -p "$APP_DIR"

# VS Code executable (adjust if necessary)
VSCODE_EXECUTABLE="/usr/share/code/code"

# VS icon (adjust if necessary)
ICON_PATH="/usr/share/pixmaps/vscode.png"

# Find all .projectname files in subdirectories of PROJECTS_DIR
find "$PROJECTS_DIR" -type f -name ".projectname" | while read -r project_file; do
    # Get the parent directory of the .projectname file
    project_dir=$(dirname "$project_file")

    # Read the first line of the .projectname file as the project short name
    project_short_name=$(head -n 1 "$project_file" | tr -d '[:space:]')

    # Skip if the project short name is empty
    if [ -z "$project_short_name" ]; then
        echo "Skipping: Empty short name in '$project_file'"
        continue
    fi

    # Define the desktop file path
    desktop_file="$APP_DIR/vscode-$project_short_name.desktop"

    # Create the .desktop file
    cat > "$desktop_file" <<EOL
[Desktop Entry]
Type=Application
Name=Code $project_short_name
Exec=$VSCODE_EXECUTABLE "$project_dir"
Icon=$ICON_PATH
Terminal=false
Categories=Development;IDE;
EOL

    # Make the file executable
    chmod +x "$desktop_file"
    echo "Created: $desktop_file (opens $project_dir)"
done

echo "Done. You may need to refresh your desktop environment for changes to take effect."

Whenever I create a new project, I make sure to create the .projectname file for it, before rerunning the script.

View as: JSON Markdown

If you enjoyed this post or found it useful, you can subscribe to my RSS feed.

Similar posts

  1. How to Launch VS Code Projects via macOS Spotlight

    I recently traded my Linux setup for a MacBook Pro, but I wasn't willing to give up my custom project launchers. With a little help from Claude, I've ported my original Bash script to macOS so I can open any project instantly using Cmd + Space.

    macos apple vscode spotlight
  2. Upgrading from Fedora 41 to Fedora 42

    If someone were to ask me which Linux distro has provided the best desktop experience, I wouldn't hesitate to answer: Fedora Workstation 41. So of course I upgraded to Fedora 42.

    fedora linux
  3. How to install PHP extension for Microsoft SQL Server under Fedora

    I found myself needing to connect to a Microsoft SQL Server via a PHP application running under Fedora. Finding concise details about installing the necessary drivers and extensions was not easy, so here is a blog post detailing how I did it.

    php microsoft fedora mssql sql linux
  4. My Debian 12 (bookworm) server set-up

    I've been running Debian on my servers for years. It's dependable. I guess my server set-up is pretty common, consisting of Apache, PHP and MariaDB, but I figure it is still worth sharing details of how I provision my servers.

    php composer mariadb apache debian linux node fish
  5. My Debian 12 (bookworm) desktop set-up

    Creating a good Debian desktop experience is not too difficult, thanks to the excellent work of the Debian developers, but I thought it might be interesting to share how I set-up my Debian systems.

    debian linux
  6. Upgrading from Fedora 40 to Fedora 41

    A post describing my first experience of upgrading a Fedora installation. TLDR: The upgrade went smoothly and Fedora continues to impress me.

    fedora linux
  7. Vivaldi notes

    I've been reading a lot of good things about the Vivaldi web browser of late, so I thought I would give it a try. These are my notes on what I did to personalise Vivaldi.

    vivaldi firefox css gnome
  8. Desktop Linux and compiling from source

    If anyone is in any doubt as to whether you need to compile any software from source in order to use desktop Linux, you really don't.

    linux
  9. Switching desktop Linux from Debian to Fedora

    Last week I switched the operating system on my daily driver (Lenovo ThinkPad T14s) from Debian 12 to Fedora 40. In this post I write a little about why I switched and how the switch went.

    debian linux fedora
  10. How to create Bash aliases in Fedora

    Creating your own Bash aliases is a relatively easy process. That said, I recently switched my desktop linux distribution from Debian to Fedora and there are subtle differences.

    linux fedora debian bash
  11. How to set-up a crontab file

    In Linux, Cron is a daemon/service that executes shell commands periodically on a given schedule. Cron is driven by a crontab, a configuration file that holds details of what commands are to be run along with a timetable of when to run them. Knowing how to use Cron is key to mastering automation with Linux.

    cron automation linux