Permalink
Browse files

Add COMP environment vars. Log to npm-completion.log

  • Loading branch information...
1 parent 299a9a4 commit 18b95cf2978be532e999430ce9a2ff3654140e1c @isaacs isaacs committed Nov 29, 2010
Showing with 21 additions and 11 deletions.
  1. +7 −0 lib/completion.js
  2. +14 −11 npm-completion.sh
View
@@ -10,10 +10,16 @@ var npm = require("../npm")
, containsSingleMatch = require("./utils/completion/contains-single-match")
, output = require("./utils/output")
, index = npm.config.get("comp-cword") || process.env.COMP_CWORD
+ , log = require("./utils/log")
function completion (args, cb_) {
var cmd = args[1] || ""
, complFullList = getCompletions(cmd, npm.fullList, true)
+ Object.keys(process.env).filter(function (e) {
+ return e.toUpperCase().match(/^COMP/)
+ }).forEach(function (e) {
+ log.warn(e+"="+process.env[e], "completion env")
+ })
function cb (er, list) {
if (er) return cb_(er)
@@ -31,5 +37,6 @@ function completion (args, cb_) {
function outputCompletions (list, cb_) {
var outfd = npm.config.get("outfd")
function cb () { cb_(list.length ? null : "no match found", list) }
+ log.warn(list, "completion output")
output.write(outfd, list, false, cb)
}
View
@@ -2,30 +2,33 @@
# npm command completion script
#
# Install Method 1: Automatic
-# Drop this file in /etc/bash-completion.d or /usr/local/etc/bash-completion.d
+# Put this file in /etc/bash-completion.d or /usr/local/etc/bash-completion.d
# or wherever bash-completion scripts are sourced on your system.
#
# Install Method 2: Generic
-# Put this in your .bashrc or whatever file you run when you log into a machine:
+# Put this in .bashrc or whatever file you run when you log into a machine:
# . path/to/npm-completion.sh
#
-# Then use the tab key to complete commands, which executes the "npm completion"
-# command.
+# Then use the tab key, which executes the "npm completion" command.
#
-# Note that command completion is very rudimentary and incomplete (harhar) as of
-# this time. Patches welcome!
-#
-# --i
+# Special thanks to Evan Meagher for making the npm completion command
+# much more useful and complete.
+export COMP_WORDBREAKS=${COMP_WORDBREAKS/@/}
__npm_completion () {
COMPREPLY=()
local cur prev opts
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
# opts=$(npm complete --loglevel silent --color false -- "$cur")
- COMPREPLY=( $(COMP_CWORD=${COMP_CWORD} \
- npm completion --color false \
- -- "${COMP_WORDS[@]}" ) )
+ COMPREPLY=( $(COMP_CWORD=$COMP_CWORD \
+ COMP_LINE=$COMP_LINE \
+ COMP_POINT=$COMP_POINT \
+ COMP_WORDBREAKS=$COMP_WORDBREAKS \
+ COMP_WORDS="${COMP_WORDS[@]}" \
+ npm completion --color false --loglevel warn \
+ -- "${COMP_WORDS[@]}" \
+ 2>>./npm-completion.log ) )
return $?
}

0 comments on commit 18b95cf

Please sign in to comment.