Guide To Having PhpStorm Use Windows Subsystem For Linux’s Git

I’m one of the rare Windows users at Automattic but thanks to the introduction of Windows Subsystem for Linux, my life is way easier. I can now run pretty much any Bash script without having to spin up a virtual machine like I used to have to. While it’s possible to build Node.js-powered projects natively under Windows thanks to the Windows-Build-Tools package, it’s a lot easier to just do everything within Linux. This is largely because building in one environment means that you can’t run the tools in the other environment.

The main time that this bites you is when the project you’re working on has a pre-commit hook in Git. If you build your project in Linux but attempt to commit from Windows, it won’t work. IDEs such as PhpStorm do all of their Git operations from Windows. This blog post will explain how to get it to use the copy of Git within Linux.

  1. Install Pageant from PuTTY or if you’re signing your commits, then Gpg4win (its gpg-connect-agent can be set to be PuTTY compatible). Have it start with Windows in order to load your SSH keys.
  2. Verify that the agent is working by using PuTTY to connect to github.com with the username git. GitHub won’t let you open a shell but it’ll let you know that you have successfully authenticated. Note that command line ssh won’t work because it’s not Pageant-compatible.
  3. Install weasel-pageant to allow you to use SSH keys from within Linux.
  4. Verify that the agent is working by running ssh-add -l in Linux. Your key(s) should be listed.
  5. Verify SSH is working by running ssh git@github.com. If it doesn’t work, append -vvv to the end of the command to enable debug output to see what’s wrong.

Now that you have Git authentication working within Linux, it’s time to get PhpStorm (or whatever IDE you use) to use Linux’s Git.

The trick here is instead of having PhpStorm use git.exe, you need to point it at a batch script. This Stack Overflow question helped me a ton, but I needed to modify it a little bit.

For whatever reason, my .bashrc file wasn’t being loaded when calling bash.exe -c which meant that agent wasn’t being loaded. So as a part of my batch script, I’m manually loading my personal file that contains my shell customizations. Here’s my full batch file:

@echo off
setlocal enabledelayedexpansion
set command=%*
set find=C:\Users\%USERNAME%\AppData\Local\Temp\git-commit-msg-.txt
set replace=/mnt/c/Users/%USERNAME%/AppData/Local/Temp/git-commit-msg-.txt
call set command=%%command:!find!=!replace!%%
If %PROCESSOR_ARCHITECTURE% == x86 (
    C:\Windows\sysnative\bash.exe -c 'source ~/.viper-common; git %command%'
) Else (
    bash.exe -c 'source ~/.viper-common; git %command%'
)

In PhpStorm, go to File → Settings (or Default Settings) → Version Control → Git and set the “Path to Git executable” to point at the batch file. Verify that it works by clicking the Test button.

With that, everything should work now!

Questions? Problems? Leave a comment below.

My WordPress-Branded MacBook Pro

After four years at Automattic, you are given an awesome MacBook that has been customized by ColorWare to have a glowing WordPress logo instead of an Apple logo as well as being painted any color you wish.

My four year anniversary of being officially hired was last March (I was also on contract for 9 months) but as one of the handful of Windows users in the company, I originally opted to pass on the custom MacBook and stick with normal Windows laptops. I’ve used Windows for 20 years now and my primary machine is a very powerful desktop computer that I’ve built for gaming.

However I recently tried to use a Mac for something and realized that I had absolutely no clue how to use it. I didn’t even know about Finder! Yeah, pretty bad.

Additionally I saw some very cool looking customized MacBooks at my company’s annual full company meetup that made me want one too.

So I decided to get one after all and I’m super happy I did! It’s absolutely beautiful and I can install Windows on it so that I can use both operating systems.

Specs:

  • 13″ MacBook Pro with Retina screen
  • 3.0GHz Dual-core Intel Core i7, Turbo Boost up to 3.5GHz
  • 16GB 1600MHz DDR3L SDRAM
  • 1TB PCIe-based Flash Storage

Here’s how they do the custom logo:

Ideal WordPress Plugin Development Using PhpStorm 8

The upcoming PhpStorm 8 features built-in WordPress support, as explained in this support document. However what’s the best way to set up your WordPress install in order to write plugins? Here’s my personal answer — feel free to suggest alternatives in the comments section.

When working on a WordPress plugin, you don’t want functions, classes, variables, etc. from other plugins to leak into your current plugin through auto-complete or other types of automation. For this reason, I suggest avoiding opening a whole WordPress checkout with all of your plugins inside of it using PhpStorm. At the same time, you don’t want to have a separate copy of WordPress for each plugin that you work on. This is redundant and makes keeping WordPress up to date harder.

So instead do a single checkout of WordPress to its own folder and then define WP_PLUGIN_DIR and WP_PLUGIN_URL, as described on the Codex, so that your plugins folder will live outside of your WordPress folder. This way you can open and index the WordPress folder without getting all of your plugins along with it.

Now create a new project for each individual plugin. When doing so, you’ll want to add the WordPress folder as an include path in PhpStorm, as described in their documentation.

All of this will result in only your individual plugin’s folder showing up in PhpStorm but with WordPress showing up under the “External Libraries” list. This one WordPress install can be used in your browser to test all of your plugins but the plugin codes won’t overlap.

iPad Mini Retina

iPad Mini Retina

I went out and bought an iPad Mini with Retina yesterday thanks to a new program at my company. They’ll buy me a new mobile device every 12 months in addition to the existing new laptop every 16 months program. I had originally planned on waiting (a long time) for the iPhone 6 but decided this was a better option.

It’s my first iPad and so far I’m pretty impressed with it, especially the display. The pixel density is quite impressive and makes for a great reading device. It makes my iPhone feel hilariously tiny and squished.

I do already have some complaints about it though:

  • iCloud: I’ve had an iPhone since launch day of the 4 and each time I upgraded or replaced it, it was just a matter of restoring the device from an iTunes or iCloud backup and it was exactly like the phone before it. Setting up the iPad however was nothing like that. Practically speaking it’s an entirely separate device from my iPhone. I had to set up all of my settings and apps from scratch. It would have been much nicer if it kept my app settings in sync between my two apps, at least at first. Or something. I don’t know. I just know it was a huge pain to get everything set back up.
  • Lack of universal apps: It was disappointing to discover just how many of my favorite apps were designed only for an iPhone. Thankfully a few of them (but not all) had separate apps designed just for iPads but come on developers, it’s nearly 2014. Get with the program.
  • Weight: It’s not heavy exactly but it’s not as light as I would like it to be either. If you’re holding it by one corner with your hand, it does make your hand tired after a bit. When I switch back to using my iPhone, it feels like I’m holding a feather.

Still, I’m not regretting getting one. It’ll be nice to have a device that I can more easily read stuff on and consume media with.

Portable PhpStorm

I use PhpStorm to write all of my code for my job at Automattic. It’s an amazing IDE and has made me so much more productive.

However I am an outlier at my company in that I use two different computers rather than only a laptop — my powerful desktop with a big screen at home and my super portable ultrabook laptop when on the go. In order to keep my working environment identical on both machines, I install all of my work applications in portable mode. That is they store their configuration options in files alongside themselves rather than in my user directory or in the computer’s registry. This allows me to keep the applications stored on Dropbox which in turn keeps them synced between my two machines.

PhpStorm by default stores your configuration settings in files inside of your user directory. This is ideal for multi-user machines where each user should have separate settings. This however doesn’t apply to me. So how do you get PhpStorm to store those settings somewhere else?

After installing PhpStorm inside of your Dropbox directory (I have a “Programs” folder for these kinds of things), you need to go into the bin folder inside of PhpStorm’s directory and then open up the idea.properties configuration file in your favorite basic text editor such as Sublime Text or even just Notepad.

EDIT: You don’t even have to install it. If you take the direct download link and swap out .exe for .zip, you’ll get a ZIP file containing all of PhpStorm. You can then extract it to your Dropbox. I’m sure the process is something similar for Mac users.

At the top of the file you’ll find some commented out that have values with ${user.home}/.WebIde/ in them. You need to uncomment these lines and then replace ${user.home}/.WebIde/ with something like ${idea.home}/prefs/ which will instead store things inside of a “prefs” folder inside of your PhpStorm folder.

Lastly you should probably copy the contents of your old .WebIde folder (instructions to locate it can be found here) into the new location so that you don’t lose your existing settings.

Enjoy!

Battery Life

The battery life on my new Sony Vaio Pro 13 ultrabook is pretty damn good:

Battery Life

Okay, to be fair that was with the extra battery attached to the bottom of it which doubles the battery life as well as the screen turned down all the way and the laptop sitting idle for about 15 minutes. I also suspect its estimate may be a bit off but I fully expect to get over 10 hours of battery life with more normal usage. Still, as I’m writing this with the brightness up all the way, the battery is still at 100%.

I love it.

UPDATE: Okay, this is getting silly. Maybe Windows 8.1 preview just can’t accurately read my battery levels?

More Battery Life

UPDATE #2: Okay, the second battery finally dropped to 99% after having the brightness on full and surfing the web for a while. The time left estimate seems a lot more realistic now. 🙂

Proper Battery Life

Google Maps For iOS Is Amazing

The new Google Maps app is simply amazing, by far the best mobile map app that I’ve used even if you take accuracy off the table. I used it this morning and its vocal driving directions are actually better than Apple’s app. They give more detail in road names and things like that and honestly I think the voice is better and more natural too. If you have an iPhone and haven’t tried it out, you really need to. The Verge has a good write-up about what’s new.