Monthly Archives: November 2013

Tab Colors in iTerm2 v1.0

Version 1.0 of iTerm2 for OS X was recently released. They removed one of my favorite features: tab coloring. You used to be able to right click on a tab to change its color. For example, I changed the tab with my ssh connection to our production server would be red and the tab with the ssh connection to our test server would be green.

I looked into it, and there is a way to set the tab color from the command line itself. This turns out to be much more helpful because I can add the following lines to my bash profile:

alias ssh-dev="tab-green; ssh [email protected]"
alias ssh-prod="tab-red; ssh [email protected]"

Now each time I want to ssh to the dev server, the tab changes to green before the ssh begins. Same for production with a red tab.

The full tab coloring script I created is below. I just threw it into ~/.bash_profile.

# iterm coloring
function tab-color() {
if [[ $# == 1 ]]
# convert hex to decimal
if [[ ${hex:0:1} == "#" ]]
# strip leading hash sign
if [[ ${#hex} == 3 ]]
# handle 3-letter hex codes
r=$(printf "%d" 0x${hex:0:2})
g=$(printf "%d" 0x${hex:2:2})
b=$(printf "%d" 0x${hex:4:2})
echo -ne "\033]6;1;bg;red;brightness;$r\a"
echo -ne "\033]6;1;bg;green;brightness;$g\a"
echo -ne "\033]6;1;bg;blue;brightness;$b\a"
function tab-red() { tab-color 203 111 111; }
function tab-green() { tab-color 6cc276; }
function tab-yellow() { tab-color "#e8e9ac"; }
function tab-blue() { tab-color 6f8ccc; }
function tab-purple() { tab-color a789d4; }
function tab-orange() { tab-color fbbc79; }
function tab-white() { tab-color fff; }
function tab-gray() { tab-color c3c3c3c; }

Note that the tab-color function accepts colors in rgb, 6-character hex codes and 3-character hex codes.

Edit: It appears that this functionality was restored in April 2014. Thanks! 7/22/2014

Creating an API Endpoint in WordPress

It turns out that creating an endpiont for an API in WordPress is super easy. Use cases for such a plugin include:

  • Add new posts from an external application
  • Request data from WordPress such as a feed of latest posts

query_vars['pagename'] == 'my/endpoint' ) {
require_once( __DIR__ . '/my/endpoint.php' );
}, 0 );

I’ve tested it in version 3.7. The parse request hook was added in WordPress 2.0 so theoretically it should work back to version 2.0.

If you have several endpoints, you may want to test $wp->query_vars['pagename'] with a regex or against an array of endpoints.

Be sure to make your endpoints secure. The plugin I created has a table of known API logins and password. The connection is initiated on the WordPress side on the plugin’s settings page and an API login and password is stored in the table to authenticate incoming requests.