Skip to content

Commit

Permalink
make it look better
Browse files Browse the repository at this point in the history
  • Loading branch information
tiye committed May 23, 2014
1 parent a5c7ca3 commit 2d29081
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 13 deletions.
2 changes: 2 additions & 0 deletions .gitignore
@@ -1,2 +1,4 @@
node_modules
npm-debug.log

cofmon.js
7 changes: 0 additions & 7 deletions README

This file was deleted.

12 changes: 12 additions & 0 deletions README.md
@@ -0,0 +1,12 @@

A CoffeeScript Shell for MongoDB
------

so that you can write CoffeeScript instead of JavaScript in the Mongo Shell.

To use, just `npm install -g cofmon` and then use `cofmon` as you would the Mongo command.

In additon to being able to write CoffeeScript instead of JavaScript, any 24 character hex string that's wrapped in double quotes is automatically made into an `ObjectId`, i.e.

`"51bb660191888d7acc355ed8"` compiles to `ObjectId("51bb660191888d7acc355ed8")`
`'51bb660191888d7acc355ed8'` compiles to `'51bb660191888d7acc355ed8'`
8 changes: 4 additions & 4 deletions cofmon.coffee 100755 → 100644
Expand Up @@ -9,7 +9,7 @@ shell = proc.spawn 'mongo', process.argv.slice 2
rl = readline.createInterface process.stdin, process.stdout

query = ->
rl.question '>', (data) ->
rl.question '> ', (data) ->
try
data = data.replace /("[0-9a-f]{24}")/g, "ObjectId($1)"
if data.match /^(show|use|it)( |\n)/ then c = data+"\n"
Expand All @@ -22,12 +22,12 @@ query = ->
shell.stdout.on 'data', (data) ->
process.stdout.write data.toString()
if tid then clearTimeout tid
tid = setTimeout query, 100
tid = setTimeout query, 200

shell.stderr.on 'data', (data) ->
process.stderr.write data.toString()
if tid then clearTimeout tid
tid = setTimeout query, 100
tid = setTimeout query, 200

shell.on 'exit', ->
shell.on 'exit', ->
process.exit(0)
3 changes: 1 addition & 2 deletions index.js 100755 → 100644
@@ -1,3 +1,2 @@
#!/usr/bin/env node
require('coffee-script/register')
require(__dirname+"/cofmon.coffee")
require("./cofmon")

0 comments on commit 2d29081

Please sign in to comment.