{"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 id=\"ig-sh-1\" class=\"syntax_hilite\">\n\n\t\t<div class=\"toolbar\">\n\n\t\t<div class=\"view-different-container\">\n\t\t\t\t\t\t<a href=\"#\" class=\"view-different\">&lt; View <span>plain text<\/span> &gt;<\/a>\n\t\t\t\t\t<\/div>\n\n\t\t<div class=\"language-name\">bash<\/div>\n\n\t\t\n\t\t<br clear=\"both\">\n\n\t<\/div>\n\t\n\t<div class=\"code\">\n\t\t<ol class=\"bash\" style=\"font-family:monospace\"><li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\"><span style=\"color: #666666;font-style: italic\">#!\/bin\/bash<\/span><\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\"><span style=\"color: #666666;font-style: italic\"># Open .php files: use PhpStorm if running, otherwise Geany<\/span><\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">&nbsp;<\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\"><span style=\"color: #000000;font-weight: bold\">if<\/span> pgrep <span style=\"color: #660033\">-x<\/span> <span style=\"color: #ff0000\">&quot;phpstorm&quot;<\/span> <span style=\"color: #000000;font-weight: bold\">&gt;<\/span> <span style=\"color: #000000;font-weight: bold\">\/<\/span>dev<span style=\"color: #000000;font-weight: bold\">\/<\/span>null <span style=\"color: #000000;font-weight: bold\">||<\/span> pgrep <span style=\"color: #660033\">-f<\/span> <span style=\"color: #ff0000\">&quot;phpstorm&quot;<\/span> <span style=\"color: #000000;font-weight: bold\">&gt;<\/span> <span style=\"color: #000000;font-weight: bold\">\/<\/span>dev<span style=\"color: #000000;font-weight: bold\">\/<\/span>null; <span style=\"color: #000000;font-weight: bold\">then<\/span><\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">&nbsp; &nbsp; <span style=\"color: #666666;font-style: italic\"># PhpStorm is running - open file in existing instance<\/span><\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">&nbsp; &nbsp; phpstorm <span style=\"color: #ff0000\">&quot;$@&quot;<\/span><\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\"><span style=\"color: #000000;font-weight: bold\">else<\/span><\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">&nbsp; &nbsp; geany <span style=\"color: #ff0000\">&quot;$@&quot;<\/span><\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\"><span style=\"color: #000000;font-weight: bold\">fi<\/span><\/div><\/li>\n<\/ol>\t<\/div>\n\n<\/div>\n\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 id=\"ig-sh-2\" class=\"syntax_hilite\">\n\n\t\t<div class=\"toolbar\">\n\n\t\t<div class=\"view-different-container\">\n\t\t\t\t\t\t<a href=\"#\" class=\"view-different\">&lt; View <span>plain text<\/span> &gt;<\/a>\n\t\t\t\t\t<\/div>\n\n\t\t<div class=\"language-name\">ini<\/div>\n\n\t\t\n\t\t<br clear=\"both\">\n\n\t<\/div>\n\t\n\t<div class=\"code\">\n\t\t<ol class=\"ini\" style=\"font-family:monospace\"><li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\"><span style=\"color: #000066;font-weight:bold\"><span>&#091;<\/span>Desktop Entry<span>&#093;<\/span><\/span><\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\"><span style=\"color: #000099\">Name<\/span><span style=\"color: #000066;font-weight:bold\">=<\/span><span style=\"color: #660066\">Open PHP File<\/span><\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\"><span style=\"color: #000099\">Exec<\/span><span style=\"color: #000066;font-weight:bold\">=<\/span><span style=\"color: #660066\">\/home\/YOUR_USERNAME\/.local\/bin\/open-php %F<\/span><\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\"><span style=\"color: #000099\">Type<\/span><span style=\"color: #000066;font-weight:bold\">=<\/span><span style=\"color: #660066\">Application<\/span><\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\"><span style=\"color: #000099\">NoDisplay<\/span><span style=\"color: #000066;font-weight:bold\">=<\/span><span style=\"color: #660066\">true<\/span><\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\"><span style=\"color: #000099\">MimeType<\/span><span style=\"color: #000066;font-weight:bold\">=<\/span><span style=\"color: #660066\">application\/x-php<\/span><span style=\"color: #666666;font-style: italic\">;text\/x-php;<\/span><\/div><\/li>\n<\/ol>\t<\/div>\n\n<\/div>\n\n<p>Replace YOUR_USERNAME with your own user name, then register it as the new handler:<\/p>\n<div id=\"ig-sh-3\" class=\"syntax_hilite\">\n\n\t\t<div class=\"toolbar\">\n\n\t\t<div class=\"view-different-container\">\n\t\t\t\t\t\t<a href=\"#\" class=\"view-different\">&lt; View <span>plain text<\/span> &gt;<\/a>\n\t\t\t\t\t<\/div>\n\n\t\t<div class=\"language-name\">bash<\/div>\n\n\t\t\n\t\t<br clear=\"both\">\n\n\t<\/div>\n\t\n\t<div class=\"code\">\n\t\t<ol class=\"bash\" style=\"font-family:monospace\"><li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">update-desktop-database ~<span style=\"color: #000000;font-weight: bold\">\/<\/span>.local<span style=\"color: #000000;font-weight: bold\">\/<\/span>share<span style=\"color: #000000;font-weight: bold\">\/<\/span>applications<\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">&nbsp;<\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">xdg-mime default open-php.desktop application<span style=\"color: #000000;font-weight: bold\">\/<\/span>x-php<\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">xdg-mime default open-php.desktop text<span style=\"color: #000000;font-weight: bold\">\/<\/span>x-php<\/div><\/li>\n<\/ol>\t<\/div>\n\n<\/div>\n\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}]}}