[MODX] Git Bash Inside PhpStorm

If you don’t use Git and Jetbrains’ fabulous editor, PhpStorm, this article probably won’t interest you. Likewise, if you use both and are used to using the Git features inside PhpStorm, this won’t be much use to you, although you can do other things in Git Bash like using SSH connections, copying files, running Grep, or issuing Composer or Perl commands. Of course you can also use it as a terminal.

I’m used to using the Git Bash command line tool. I trust it more than I do any IDE-based Git tool. The command line tool also allows you to quickly and safely perform the more complex operations necessary to recover from the disasters that will eventually strike when you’re working in the wee hours of the morning.

Of course I already had a Quick Start icon for the Bash shell at the bottom of my screen, so I could launch it any time, but it’s much more convenient to issue the commands in PhpStorm where the files you’ve been working on are visible. On Windows, another huge plus is that you have full copy and paste capability both ways (something I didn’t get in the Bash window launched from the Windows desktop). You can copy your commit message and paste it into your changelog, for example (or vice versa).

It took me most of an evening and a lot of trial and error to make this work and Google wasn’t much help, so I thought I’d document it here for others. These steps are for PhpStorm 8.0.1 with XAMPP on localhost under Windows Vista, so you’ll have to modify them somewhat if you’re on another platform. This assumes that you have a Git client and the Git Bash shell installed with XAMPP, though a similar process will work with cygwin.

MODX logo

The Terminal

I kept playing with various PhpStorm settings for Command Line Tools, since that’s what I think of Git Bash as (it looks and acts like the Windows cmd prompt). The fact is, though, that it’s a terminal client and that’s how PhpStorm thinks of it. To implement it, you have to go to:

[code language=”html”]
File -> Settings -> Tasks -> Terminal
[/code]

Once you’re there, here are the steps necessary to enable Git Bash in the Terminal dialog.

Put the following line in the Shell Path field (adjust as necessary for your platform):

[code language=”html”]
C:\Program Files (x86)\Git\bin\sh.exe -login -i
[/code]

The -login tells Bash to run its configuration files (more on that in the next article), and the -i tells Bash that you want interactive mode. You can add -v if you like verbose output from Bash.

As an alternative, you can click on the browse icon and navigate to the sh.exe file, wherever it is, but be sure to add the command-line options after the path.

I left all the checkboxes checked and it seems to work fine. When you’re done, click on “Apply” and then on “OK”. You may have to restart PhpStorm for this all to take effect.

At the bottom of the PhpStorm screen (bottom left on my version) you should see a “Terminal” button. When you click on it, you should see a window with the Bash prompt, followed by a cursor. If the cursor is white, your typing will be ignored until you click in the window — then it will turn black. If you don’t see that “Terminal” button, you can use the View -> Toolbars menu option or Alt-F12 to bring you the terminal window.

I prefer to have the window floating. You can select that option from the little gear icon at the upper right of the window. Clicking on the minimize icon next to the gear icon, or on the “Terminal” button will hide the window. If you click on the red X, it will close your terminal session and you’ll lose your place. You can also have multiple Bash windows open by clicking on the + symbol, which is handy if you want to repeat actions in different directories, especially since you can use copy and paste.


For more information on how to use MODX to create a web site, see my web site Bob’s Guides, or
better yet, buy my book: MODX: The Official Guide.

Looking for quality MODX Web Hosting? Look no further than Arvixe Web Hosting!

Tags: , , , | Posted under MODX, MODX | RSS 2.0

Author Spotlight

Bob Ray

Bob Ray is the author of MODX: The Official Guide and over 30 MODX add-on components. He hosts Bob's Guides, a source of valuable information for MODX users, and has been very active in the MODX Forums with over 19,000 posts.

Leave a Reply

Your email address will not be published. Required fields are marked *