kanso/kanso — pull request #338 by jhs (2011-12-20 04:01:46+00:00)
Title: Autocomplete work

I'm not super happy with this, so I branched off of "dev.

The goal is that we can source `scripts/autocomp.sh` and then typing `kanso ` works. Bash needs to run the `autocomp.js` script, and the idea is that Kanso doesn't worry about $NODE_PATH or $KANSO_DIR. That is NPM's problem.

The first commit set a "global" Bash variable with the location to the script. Ideally Kanso would not pollute the variable space like that.

My next try was to add a new "bin" command, which most people needn't know about: `kanso_completions`. NPM installs this into the $PATH, and the completer can use it. I'm not happy about adding a new command. In particular, if you type `kanso`, instead of getting a space because that is a unique command, now Bash beeps because it could mean either "kanso" or "kanso_completions". I suppose many people type "kanso" so maybe it's fine this way.

Alternative idea 1:

I investigated the `npm run-script` command. Instead of a "bin" field, you can use "scripts" similarly. Unfortunately, `npm run-script` does not pass command-line arguments through to the script. So we would have to maybe export a variable with `${COMP_WORDS[@]}`, and autocomp.js can pull it from process.env. Then unset it after the command runs to avoid polluting the variable space again. This seems like a lot of work.

Alternative idea 2:

Add a kanso command, `kanso completions` which does the same thing as autocomp.js. Perhaps it could be undocumented and "hidden" (at least for Kanso *users*, not Kanso developers). The advantage is, if "kanso" is in your path, then of course "kanso completions" would work. `autocomp.sh` stays simple too. Let me know if you think it's worth it. (I've never looked into the commands, especially considering this one might be hidden.)