Skip to content

Instantly share code, notes, and snippets.

@ozh
Created May 3, 2026 15:32
Show Gist options
  • Select an option

  • Save ozh/3aed05d7d85edbc9c8eddd543d684753 to your computer and use it in GitHub Desktop.

Select an option

Save ozh/3aed05d7d85edbc9c8eddd543d684753 to your computer and use it in GitHub Desktop.
Open PHP with PhpStorm if already running, lightweight editor otherwise

Smart PHP file opener: PhpStorm if running, Geany otherwise

Double-click a .php file in Nemo: this setup opens it in PhpStorm only if PhpStorm is already running, or falls back to Geany otherwise.

The idea is that whenever I just want a quick edit, I don't want to load PhpStorm. And whenever I'm really coding, PhPStorm is already open.

Setup

1. Create the wrapper script

mkdir -p ~/.local/bin

cat > ~/.local/bin/open-php << 'EOF'
#!/bin/bash
# Open .php files: use PhpStorm if running, otherwise Geany

if pgrep -x "phpstorm" > /dev/null || pgrep -f "phpstorm" > /dev/null; then
    phpstorm "$@"
else
    geany "$@"
fi
EOF

chmod +x ~/.local/bin/open-php

Note: the PhpStorm process name may vary depending on how it was installed (JetBrains Toolbox, standalone, snap...). Check the actual process name while PhpStorm is running with:

pgrep -a -f [Pp]hp[Ss]torm

Adjust the pgrep calls in the script accordingly.

2. Create the .desktop entry

cat > ~/.local/share/applications/open-php.desktop << 'EOF'
[Desktop Entry]
Name=Open PHP File
Exec=/home/YOUR_USERNAME/.local/bin/open-php %F
Type=Application
NoDisplay=true
MimeType=application/x-php;text/x-php;
EOF

Replace YOUR_USERNAME with your actual username

3. Register it as the default handler

update-desktop-database ~/.local/share/applications

xdg-mime default open-php.desktop application/x-php
xdg-mime default open-php.desktop text/x-php
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment