{"id":3928,"date":"2026-05-30T19:22:25","date_gmt":"2026-05-30T17:22:25","guid":{"rendered":"https:\/\/planetozh.com\/blog\/?p=3928"},"modified":"2026-05-30T19:22:58","modified_gmt":"2026-05-30T17:22:58","slug":"open-php-files-in-the-right-editor-automatically","status":"publish","type":"post","link":"https:\/\/planetozh.com\/blog\/2026\/05\/open-php-files-in-the-right-editor-automatically\/","title":{"rendered":"Open PHP files in the right editor, automatically."},"content":{"rendered":"<p>This is one of those cases when, viewing a file in your window manager, you see a <tt>.php<\/tt> file you want to quickly inspect. You double click on it, and&#8230;<\/p>\n<ul>\n<li>It quickly opens Geany, or your default quick file editor, but PHPStorm is already running <em>right there<\/em>&#8230;<\/li>\n<li>Or the opposite: you just want a quick peak for a single little file, but it slowly cold starts your 4 GB IDE :x<\/li>\n<\/ul>\n<p>What if your file manager just knew? That&#39;s the idea of the following bash script that acts as the default handler for <tt>.php<\/tt> files:<\/p>\n<ul>\n<li>PhpStorm is running? Open the file there, in the existing instance.<\/li>\n<li>PhpStorm is not running? Open in Geany &#8211; fast, lightweight, no wait for a quick glance.<\/li>\n<\/ul>\n<h2>The script<\/h2>\n<p>Drop this in <tt>~\/.local\/bin\/open-php<\/tt>:<\/p>\n<div class=\"igsh-code-box\" id=\"ig-sh-1\"><pre class=\"language-bash line-numbers\" data-no-optimize=\"1\" data-cfasync=\"false\"><code class=\"language-bash\">#!\/bin\/bash\r\n# Open .php files: use PhpStorm if running, otherwise Geany\r\n\r\nif pgrep -x &quot;phpstorm&quot; &gt; \/dev\/null || pgrep -f &quot;phpstorm&quot; &gt; \/dev\/null; then\r\n    # PhpStorm is running - open file in existing instance\r\n    phpstorm &quot;$@&quot;\r\nelse\r\n    geany &quot;$@&quot;\r\nfi<\/code><\/pre><\/div>\n<p>Then <tt>chmod<\/tt> it <tt>+x<\/tt>. Also make sure obviously that your IDE and light editor binaries are in the path. To find the exact name of your IDE process, you can use <tt>pgrep -a -f [Pp]hp[Ss]torm<\/tt> for example.<\/p>\n<h2>The setup<\/h2>\n<p>Set <tt>open-php<\/tt> as the default application for <tt>.php<\/tt> files. Right-click any <tt>.php<\/tt> in your file manager, pick &quot;Open With Other Application&quot;, point to <tt>~\/.local\/bin\/open-php<\/tt>, and set it as default.<\/p>\n<p>Alternatively, at least if using Nemo (Linux Mint for instance), you can create <tt>~\/.local\/share\/applications\/open-php.desktop<\/tt> with the following:<\/p>\n<div class=\"igsh-code-box\" id=\"ig-sh-2\"><pre class=\"language-ini line-numbers\" data-no-optimize=\"1\" data-cfasync=\"false\"><code class=\"language-ini\">[Desktop Entry]\r\nName=Open PHP File\r\nExec=\/home\/YOUR_USERNAME\/.local\/bin\/open-php %F\r\nType=Application\r\nNoDisplay=true\r\nMimeType=application\/x-php;text\/x-php;<\/code><\/pre><\/div>\n<p>Replace YOUR_USERNAME with your own user name, then register it as the new handler:<\/p>\n<div class=\"igsh-code-box\" id=\"ig-sh-3\"><pre class=\"language-bash line-numbers\" data-no-optimize=\"1\" data-cfasync=\"false\"><code class=\"language-bash\">update-desktop-database ~\/.local\/share\/applications\r\n\r\nxdg-mime default open-php.desktop application\/x-php\r\nxdg-mime default open-php.desktop text\/x-php<\/code><\/pre><\/div>\n<p>From now on, double-clicking a PHP file does the right thing automatically. Heavy tooling when it&#39;s already warm, or the lightweight editor when it&#39;s not. Best of both worlds!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This is one of those cases when, viewing a file in your window manager, you see a .php file you want to quickly inspect. You double click on it, and&#8230; It quickly opens Geany, or your default quick file editor, but PHPStorm is already running right there&#8230; Or the opposite: you just want a quick peak for a single little\u2026<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[21],"tags":[5,412,3,411],"class_list":["post-3928","post","type-post","status-publish","format-standard","hentry","category-published","tag-bash","tag-geany","tag-linux","tag-phpstorm"],"_links":{"self":[{"href":"https:\/\/planetozh.com\/blog\/wp-json\/wp\/v2\/posts\/3928","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/planetozh.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/planetozh.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/planetozh.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/planetozh.com\/blog\/wp-json\/wp\/v2\/comments?post=3928"}],"version-history":[{"count":3,"href":"https:\/\/planetozh.com\/blog\/wp-json\/wp\/v2\/posts\/3928\/revisions"}],"predecessor-version":[{"id":3931,"href":"https:\/\/planetozh.com\/blog\/wp-json\/wp\/v2\/posts\/3928\/revisions\/3931"}],"wp:attachment":[{"href":"https:\/\/planetozh.com\/blog\/wp-json\/wp\/v2\/media?parent=3928"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/planetozh.com\/blog\/wp-json\/wp\/v2\/categories?post=3928"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/planetozh.com\/blog\/wp-json\/wp\/v2\/tags?post=3928"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}