Permalink
Browse files

completion on completion

  • Loading branch information...
1 parent 79f7cf0 commit b9e41369dabe89a437c4c673fb3048c5fb206d69 @isaacs isaacs committed Mar 22, 2011
Showing with 28 additions and 0 deletions.
  1. +28 −0 lib/completion.js
View
@@ -15,6 +15,34 @@ var output = require("./utils/output")
, stdio = process.binding("stdio")
, npm = require("../npm")
+completion.completion = function (opts, cb) {
+ if (opts.w > 3) return cb()
+
+ var fs = require("fs")
+ , path = require("path")
+ , bashExists = null
+ , zshExists = null
+ , bashProfExists = null
+ fs.stat(path.resolve(process.env.HOME, ".bashrc"), function (er, b) {
+ bashExists = !er
+ next()
+ })
+ fs.stat(path.resolve(process.env.HOME, ".zshrc"), function (er, b) {
+ zshExists = !er
+ next()
+ })
+ function next () {
+ if (zshExists === null || bashExists === null) return
+ var out = []
+ if (zshExists) out.push("~/.zshrc")
+ if (bashExists) out.push("~/.bashrc")
+ if (opts.w === 2) out = out.map(function (m) {
+ return [">>", m]
+ })
+ cb(null, out)
+ }
+}
+
function completion (args, cb) {
// if the COMP_* isn't in the env, then just dump the script.
if (process.env.COMP_CWORD === undefined

0 comments on commit b9e4136

Please sign in to comment.