Skip to content

Instantly share code, notes, and snippets.

@cfg
Created August 15, 2013 20:09
Show Gist options
  • Select an option

  • Save cfg/6244347 to your computer and use it in GitHub Desktop.

Select an option

Save cfg/6244347 to your computer and use it in GitHub Desktop.
Save as /usr/local/bin/handler-subl and use with https://gist.github.com/cfg/6244326
#!/usr/bin/env php -q
<?php
$subl = '/usr/local/bin/subl';
if( empty($argv[1]) )
exit(1);
$parts = parse_url( $argv[1] );
$scheme = $parts['scheme'];
$action = $parts['host'];
$query = $parts['query'];
$file = false;
$line = false;
parse_str( $query );
if( empty($file) )
exit(1);
if( !empty($line) && intval($line) )
$file = $file . ':' . intval($line);
$cmd = escapeshellcmd($subl) . ' ' . escapeshellarg( $file );
exec( $cmd, $output, $retval );
exit($retval);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment