Open phpstorm:// uri:s using xdg-open in Linux

I couldn’t get this to work properly on my Linux box; so I wrote a litte script that parses the uri scheme and launches phpstorm.

Script

<?php
$arg = $argv[1];
$parts = parse_url($arg);
$query = $parts['query'];
parse_str($query, $output);
$file = $output['file'];
$line = $output['line'];
$cmd = '/usr/bin/phpstorm --line ' . $line . ' ' . $file;
exec($cmd);

Then create a new file in ~/.local/share/applications/phpstorm-protocol.desktop

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

Make it available, run:

update-desktop-database

and then register it with xdg-open

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

Now, when you click a phpstorm:// link in your browser choose to open it with xdg-open.

Lämna ett svar

Din e-postadress kommer inte publiceras. Obligatoriska fält är märkta *