<commit_before>
module.exports = completion

completion.usage = 'source <(npm completion)'

var npm = require('./npm.js')
var npmconf = require('./config/core.js')
var configDefs = npmconf.defs
var configTypes = configDefs.types
var shorthands = configDefs.shorthands
var nopt = require('nopt')
var configNames = Object.keys(configTypes)
  .filter(function (e) { return e.charAt(0) !== '_' })
var shorthandNames = Object.keys(shorthands)
var allConfs = configNames.concat(shorthandNames)
var once = require('once')

completion.completion = function (opts, cb) {
  if (opts.w > 3) return cb()

  var fs = require('graceful-fs')
  var path = require('path')
  var bashExists = null
  var zshExists = null
  fs.stat(path.resolve(process.env.HOME, '.bashrc'), function (er) {
    bashExists = !er
    next()
  })
  fs.stat(path.resolve(process.env.HOME, '.zshrc'), function (er) {
    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 (process.platform === 'win32') {
    var e = new Error('npm completion not supported on windows')
    e.code = 'ENOTSUP'
    e.errno = require('constants').ENOTSUP
    return cb(e)
  }

  // if the COMP_* isn't in the env, then just dump the script.
  if (process.env.COMP_CWORD === undefined ||
      process.env.COMP_LINE === undefined ||
      process.env.COMP_POINT === undefined) {
    return dumpScript(cb)
  }

  console.error(process.env.COMP_CWORD)
  console.error(process.env.COMP_LINE)
  console.error(process.env.COMP_POINT)

  // get the partial line and partial word,
  // if the point isn't at the end.
  // ie, tabbing at: npm foo b|ar
  var w = +process.env.COMP_CWORD
  var words = args.map(unescape)
  var word = words[w]
  var line = process.env.COMP_LINE
  var point = +process.env.COMP_POINT
  var partialLine = line.substr(0, point)
  var partialWords = words.slice(0, w)

  // figure out where in that last word the point is.
  var partialWord = args[w]<commit_msg>completion: enable on Windows in git bash<commit_after>
module.exports = completion

completion.usage = 'source <(npm completion)'

var npm = require('./npm.js')
var npmconf = require('./config/core.js')
var configDefs = npmconf.defs
var configTypes = configDefs.types
var shorthands = configDefs.shorthands
var nopt = require('nopt')
var configNames = Object.keys(configTypes)
  .filter(function (e) { return e.charAt(0) !== '_' })
var shorthandNames = Object.keys(shorthands)
var allConfs = configNames.concat(shorthandNames)
var once = require('once')

completion.completion = function (opts, cb) {
  if (opts.w > 3) return cb()

  var fs = require('graceful-fs')
  var path = require('path')
  var bashExists = null
  var zshExists = null
  fs.stat(path.resolve(process.env.HOME, '.bashrc'), function (er) {
    bashExists = !er
    next()
  })
  fs.stat(path.resolve(process.env.HOME, '.zshrc'), function (er) {
    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 (process.platform === 'win32' && !(/^MINGW(32|64)$/.test(process.env.MSYSTEM))) {
    var e = new Error('npm completion supported only in MINGW / Git bash on Windows')
    e.code = 'ENOTSUP'
    e.errno = require('constants').ENOTSUP
    return cb(e)
  }

  // if the COMP_* isn't in the env, then just dump the script.
  if (process.env.COMP_CWORD === undefined ||
      process.env.COMP_LINE === undefined ||
      process.env.COMP_POINT === undefined) {
    return dumpScript(cb)
  }

  console.error(process.env.COMP_CWORD)
  console.error(process.env.COMP_LINE)
  console.error(process.env.COMP_POINT)

  // get the partial line and partial word,
  // if the point isn't at the end.
  // ie, tabbing at: npm foo b|ar
  var w = +process.env.COMP_CWORD
  var words = args.map(unescape)
  var word = words[w]
  var line = process.env.COMP_LINE
  var point = +process.env.COMP_POINT
  var partialLine = line.substr(0, point)
  var partialWords = words.slice(0, w)

  // figure out where in that last word the point is.
  var partialWord = args[w]
{'fraction_non_alphanumeric': 0.14687909209951985, 'fraction_numerical': 0.00392841553906591, 'mean_word_length': 3.299249530956848, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5785763', 'n_tokens_mistral': 1612, 'n_tokens_neox': 1556, 'n_words': 418}