Permalink
Browse files

Initial commit

  • Loading branch information...
0 parents commit 7785b7df75c3469fdbc39815aa6af3d026d46a8c @tj committed Aug 24, 2011
Showing with 147 additions and 0 deletions.
  1. +3 −0 .gitignore
  2. +4 −0 .npmignore
  3. +5 −0 History.md
  4. +5 −0 Makefile
  5. +29 −0 Readme.md
  6. +90 −0 bin/nack
  7. +11 −0 package.json
@@ -0,0 +1,3 @@
+.DS_Store
+node_modules
+*.sock
@@ -0,0 +1,4 @@
+support
+test
+examples
+*.sock
@@ -0,0 +1,5 @@
+
+0.0.1 / 2010-01-03
+==================
+
+ * Initial release
@@ -0,0 +1,5 @@
+
+test:
+ @echo "populate me"
+
+.PHONY: test
@@ -0,0 +1,29 @@
+
+# nack
+
+ "ack" written with nodejs
+
+## License
+
+(The MIT License)
+
+Copyright (c) 2011 TJ Holowaychuk <tj@vision-media.ca>
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+'Software'), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,90 @@
+#!/usr/bin/env node
+
+/**
+ * Module dependencies.
+ */
+
+var program = require('commander')
+ , path = require('path')
+ , join = path.join
+ , fs = require('fs');
+
+// options
+
+program
+ .version('0.0.1')
+ .usage('[options] <query> [path ...]')
+ .option('-H, --hidden', 'search hidden files and directories')
+ .parse(process.argv);
+
+// no args
+
+if (!program.args.length) {
+ process.stdout.write(program.helpInformation());
+ process.exit(0);
+}
+
+// arguments
+
+var query = program.args.shift()
+ , paths = program.args
+ , pending = paths.length
+ , re = new RegExp('(' + query + ')', 'ig');
+
+// whitespace
+
+process.on('exit', console.log);
+
+/**
+ * Search `path`.
+ *
+ * @param {String} path
+ */
+
+function search(path) {
+ fs.stat(path, function(err, stat){
+ if (err) throw err;
+ if (stat.isDirectory()) {
+ fs.readdir(path, function(err, files){
+ if (err) throw err;
+ files.filter(hidden).map(function(file){
+ return join(path, file);
+ }).forEach(search);
+ });
+ } else {
+ var lines = [];
+ fs.readFile(path, 'utf8', function(err, str){
+ if (err) throw err;
+ str.split('\n').forEach(function(line, i){
+ if (!re.test(line)) return;
+ lines.push([i, line]);
+ });
+
+ if (lines.length) {
+ console.log('\n \033[36m%s\033[0m', path);
+ lines.forEach(function(line){
+ var i = line[0]
+ , line = line[1];
+ line = line.replace(re, '\033[37;43m$1\033[0;90m');
+ console.log(' \033[90m%d: %s\033[0m', i, line);
+ });
+ }
+ });
+ }
+ });
+}
+
+/**
+ * Filter hidden paths unless `--hidden` is used.
+ */
+
+function hidden(path) {
+ if (program.hidden) return true;
+ return '.' != path[0];
+}
+
+/**
+ * Search the given paths.
+ */
+
+paths.forEach(search);
@@ -0,0 +1,11 @@
+{
+ "name": "nack"
+ , "version": "0.0.1"
+ , "description": "faster 'ack' written with nodejs"
+ , "keywords": ["ack", "grep", "search"]
+ , "author": "TJ Holowaychuk <tj@vision-media.ca>"
+ , "dependencies": { "commander": "0.1.0" }
+ , "bin": { "nack": "./bin/nack" }
+ , "main": "index"
+ , "engines": { "node": "0.4.x" }
+}

0 comments on commit 7785b7d

Please sign in to comment.