Skip to content

Instantly share code, notes, and snippets.

@thiagotalma
Last active May 15, 2018 17:20
Show Gist options
  • Save thiagotalma/fa5a54e1e34133f78f4538eb96c87ae8 to your computer and use it in GitHub Desktop.
Save thiagotalma/fa5a54e1e34133f78f4538eb96c87ae8 to your computer and use it in GitHub Desktop.
PhpStorm Protocol (Win)
<?php
'modules' => [
'debug' => [
'class' => 'yii\debug\Module',
'traceLink' => function ($trace) {
$path = str_replace('/srv/www/myproject/', 'D:\\www\\myproject\\', $trace['file']);
return '<a href="phpstorm://open?url=file://' . $path . '&line=' . $trace['line'] . '">' . $path . ':' . $trace['line'] . '</a>';
},
]
]
var settings = {
// Set to window title (only text after dash sign), that you see, when switching to running PhpStorm instance
window_title: 'PhpStorm',
// In case your file is mapped via a network share and paths do not match.
// eg. /var/www will can replaced with Y:/
projects_basepath: '/app/',
projects_path_alias: 'D:\\www\\'
};
// don't change anything below this line, unless you know what you're doing
var url = WScript.Arguments(0),
match = /^ide:\/\/open\/\?(url=file:\/\/|file=)(.+)&line=(\d+)$/.exec(url),
project = '';
if (match) {
var shell = new ActiveXObject('WScript.Shell'),
file_system = new ActiveXObject('Scripting.FileSystemObject'),
file = decodeURIComponent(match[2]).replace(/\+/g, ' '),
search_path = file.replace(/\//g, '\\'),
link = shell.CreateShortcut('C:\\Users\\Public\\Desktop\\phpstorm.lnk'),
editor = link.TargetPath;
if (settings.projects_basepath != '' && settings.projects_path_alias != '') {
file = file.replace(new RegExp('^' + settings.projects_basepath), settings.projects_path_alias);
}
while (search_path.lastIndexOf('\\') != -1) {
search_path = search_path.substring(0, search_path.lastIndexOf('\\'));
if (file_system.FileExists(search_path + '\\.idea\\.name')) {
project = search_path;
break;
}
}
if (project != '') {
editor += ' "%project%"';
}
editor += ' --line %line% "%file%"';
var command = editor.replace(/%line%/g, match[3])
.replace(/%file%/g, file)
.replace(/%project%/g, project)
.replace(/\//g, '\\');
//WScript.Echo(command);
shell.Exec(command);
shell.AppActivate(settings.window_title);
}
REGEDIT4
[HKEY_CLASSES_ROOT\phpstorm]
@="URL:phpstorm Protocol"
"URL Protocol"=""
[HKEY_CLASSES_ROOT\phpstorm\shell\open\command]
@="wscript \"C:\\Program Files\\PhpStorm Protocol (Win)\\run_editor.js\" \"%1\""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment