Проект

Общее

Профиль

PhpStorm URL handler on Linux

To enable PhpStorm to handle custom phpstorm:// URLs on Linux, allowing you to open specific files at designated line numbers directly from your browser or other applications, you need to set up a custom URL protocol handler. This involves creating a script to parse the URL and launch PhpStorm, and then registering this script with your desktop environment.
Steps to set up the PhpStorm URL handler on Linux:
Create the Handler Script.
Create a script (e.g., phpstorm-handler.sh) that will parse the phpstorm:// URL and execute the PhpStorm command to open the file at the specified line.
Код

#!/bin/bash

URL="$1"
FILE=$(echo "$URL" | sed -n 's/.*file=\([^&]*\).*/\1/p' | sed 's/%2F/\//g')
LINE=$(echo "$URL" | sed -n 's/.*line=\([^&]*\).*/\1/p')

# Adjust the path to your PhpStorm executable if necessary
/path/to/phpstorm/bin/phpstorm --line "$LINE" "$FILE"

Replace /path/to/phpstorm/bin/phpstorm with the actual path to your PhpStorm executable. If you installed it via JetBrains Toolbox, the path might be different.
Make the script executable: chmod +x phpstorm-handler.sh
Create a Desktop Entry.
Create a .desktop file in ~/.local/share/applications/ (e.g., phpstorm-protocol.desktop) to register the custom phpstorm:// scheme.
Код

[Desktop Entry]
Name=PhpStorm Protocol Handler
Exec=/path/to/your/script/phpstorm-handler.sh %u
Terminal=false
Type=Application
MimeType=x-scheme-handler/phpstorm;

Replace /path/to/your/script/phpstorm-handler.sh with the full path to the script you created in step 1.
Update Desktop Database.
Inform your desktop environment about the new .desktop file by updating the desktop database.
Код

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

Register as Default Handler.
Set your newly created handler as the default application for the phpstorm scheme.
Код

xdg-mime default phpstorm-protocol.desktop x-scheme-handler/phpstorm

After these steps, when you click a phpstorm:// link (e.g., phpstorm://open?file=/path/to/your/file.php&line=100), your system should launch PhpStorm and open the specified file at the given line number.