Created
August 9, 2012 20:35
-
-
Save pdt256/3307843 to your computer and use it in GitHub Desktop.
smack
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env php | |
<?php | |
/** | |
* Converts command line output into an html file for any browser | |
* | |
* @author Jamie Isaacs | |
* @package default | |
**/ | |
/** | |
* Define DocBlock | |
**/ | |
$title = 'smack on ' . date('m/d @ H:i'); | |
$cmd = 'unknown command | smack'; | |
#$cmd .= "\n" . 'Consider using "ackm search_terms"; just put this in your .bash_profile: function ackm() { tmpAckm="$@"; ack "$@" | mack --cmd="ack $tmpAckm"; }'; | |
$scriptName = array_shift($argv); | |
foreach ($argv as $arg) | |
{ | |
if (preg_match('/--cmd=(.*)/', $arg, $match)) | |
{ | |
$cmd = $match[1]; | |
$title = $cmd; | |
} | |
} | |
// Get header and styles | |
ob_start(); | |
?> | |
<html> | |
<head> | |
<?php if (!empty($title)) { echo '<title>' . htmlentities($title) . '</title>'; } ?> | |
<style type="text/css" media="screen"> | |
/* <![CDATA[ */ | |
body, table { | |
margin: 0; | |
padding: 0; | |
color #000; | |
} | |
body, th, td, pre { | |
} | |
th { | |
text-align: right; | |
} | |
a { | |
text-decoration: none; | |
} | |
a:link, | |
a:hover, | |
a:active { | |
color: blue; | |
} | |
a > span.code { | |
color: black; | |
} | |
#cmd { | |
padding: .5em 1em; | |
background: #333; | |
color: #fff; | |
} | |
#cmd .path { | |
color: #3c0; | |
} | |
#notes { | |
background: #ccc; | |
padding: .5em 1em; | |
} | |
#notes textarea { | |
width: 100%; | |
} | |
#results { | |
padding: .5em 1em; | |
white-space: pre; | |
} | |
#results div { | |
white-space: normal; | |
} | |
/* ]]> */ | |
</style> | |
</head> | |
<body> | |
<div id="cmd"><span class="path"><?php echo htmlentities($_SERVER['PWD']); ?>$</span> <?php echo nl2br(htmlentities($cmd)) ?></div> | |
<div id="notes">Notes:<br /><textarea rows="3" cols="100"></textarea></div> | |
<div id="results"><?php | |
$header = ob_get_clean(); | |
$footer = '</body></html>'; | |
// TextMate link format: txmt://open/?url=file://~/.bash_profile&line=11&column=2 | |
// See: http://manual.macromates.com/en/using_textmate_from_terminal#url_scheme_html | |
$tmpFileName = tempnam('/tmp', 'smack') . '.html'; | |
$handle = fopen($tmpFileName, "w"); | |
fwrite($handle, $header); | |
$i = 0; | |
$baseDir = getcwd() . '/'; | |
while ($line = fgets(STDIN)) | |
{ | |
fwrite($handle, $line); | |
} | |
fwrite($handle, $footer); | |
fclose($handle); | |
passthru('open ' . escapeshellarg($tmpFileName)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment