How to use shell-quote - 10 common examples

To help you get started, we’ve selected a few shell-quote examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github heroku / cli / packages / config / src / quote.ts View on Github external
export function parse(a: string): string {
  if (a.startsWith('"')) {
    a = a.replace(/\\n/g, '\n')
  } else if (a.startsWith("'")) {
    a = a.replace(/\\\\/g, '\\')
  }
  let parsed = shell.parse(a)
  if (parsed.length > 1) throw new Error(`Invalid token: ${a}`)
  return parsed[0]
  // return parsed[0].replace(/\\\\n/g, '\n')
}
github vesln / nixt / lib / nixt / runner.js View on Github external
Runner.prototype.execFn = function(cmd) {
  var self = this;
  var args = require('shell-quote').parse(cmd);
  var bin = args.shift(0);

  return function(fn) {
    // Allow .run('') without attempting
    if (cmd === '') { fn(undefined); return; }

    var child = spawn(bin, args, self.world);
    var stdout = '';
    var stderr = '';
    var err;

    if (self.standardInput != null) {
      child.stdin.end(self.standardInput);
    }

    if (self.world.timeout) {
github sodiumjoe / lobar / src / interactive / compute.js View on Github external
.map(input => {
    try {
      return evalChain(data, parseArgs(parse(input)));
    } catch(e) { /* */ }
  });
github zubairghori / Ultimate_todo_list / node_modules / react-dev-utils / launchEditor.js View on Github external
function guessEditor() {
  // Explicit config always wins
  if (process.env.REACT_EDITOR) {
    return shellQuote.parse(process.env.REACT_EDITOR);
  }

  // We can find out which editor is currently running by:
  // `ps x` on macOS and Linux
  // `Get-Process` on Windows
  try {
    if (process.platform === 'darwin') {
      const output = child_process.execSync('ps x').toString();
      const processNames = Object.keys(COMMON_EDITORS_OSX);
      for (let i = 0; i < processNames.length; i++) {
        const processName = processNames[i];
        if (output.indexOf(processName) !== -1) {
          return [COMMON_EDITORS_OSX[processName]];
        }
      }
    } else if (process.platform === 'win32') {
github mysticatea / npm-run-all / lib / index.js View on Github external
return patterns.map(pattern => pattern.replace(ARGS_PATTERN, (whole, indirectionMark, id, options) => {
        if (indirectionMark != null) {
            throw Error(`Invalid Placeholder: ${whole}`)
        }
        if (id === "@") {
            return shellQuote.quote(args)
        }
        if (id === "*") {
            return shellQuote.quote([args.join(" ")])
        }

        const position = parseInt(id, 10)
        if (position >= 1 && position <= args.length) {
            return shellQuote.quote([args[position - 1]])
        }

        // Address default values
        if (options != null) {
            const prefix = options.slice(0, 2)

            if (prefix === ":=") {
                defaults[id] = shellQuote.quote([options.slice(2)])
github appium / node-teen_process / lib / exec.js View on Github external
async function exec (cmd, args = [], opts = {}) {
  // get a quoted representation of the command for error strings
  const rep = quote([cmd, ...args]);

  // extend default options; we're basically re-implementing exec's options
  // for use here with spawn under the hood
  opts = Object.assign({
    timeout: null,
    encoding: 'utf8',
    killSignal: 'SIGTERM',
    cwd: undefined,
    env: process.env,
    ignoreOutput: false,
    stdio: 'inherit',
    isBuffer: false,
    shell: undefined,
    logger: undefined,
    maxStdoutBufferSize: MAX_BUFFER_SIZE,
    maxStderrBufferSize: MAX_BUFFER_SIZE,
github jamesshore / automatopia / node_modules / browserify / bin / args.js View on Github external
.forEach(function (c) {
            var cmd = parseShell(c);
            b.transform(function (file) {
                var env = Object.keys(process.env).reduce(function (acc, key) {
                    acc[key] = process.env[key];
                    return acc;
                }, {});
                env.FILENAME = file;
                var ps = spawn(cmd[0], cmd.slice(1), { env: env });
                var error = '';
                ps.stderr.on('data', function (buf) { error += buf });
                
                ps.on('exit', function (code) {
                    if (code === 0) return;
                    console.error([
                        'error running source transform command: ' + c,
                        error.split('\n').join('\n  '),
                        ''
github release-it / release-it / lib / plugin / git / Git.js View on Github external
tag({ name = this.options.tagName, annotation = this.options.tagAnnotation, args = this.options.tagArgs } = {}) {
    const quotedMessage = quote([format(annotation, this.getContext())]);
    return this.exec(`git tag --annotate --message=${quotedMessage} ${args || ''} ${name}`)
      .then(() => this.setContext({ isTagged: true }))
      .catch(err => {
        const { latestTagName, tagName } = this.getContext();
        if (/tag '.+' already exists/.test(err) && latestTagName === tagName) {
          this.log.warn(`Tag "${tagName}" already exists`);
        } else {
          throw err;
        }
      });
  }
github scalameta / metals-vscode / src / getJavaOptions.ts View on Github external
function expandVariable(variable: string | undefined): string[] {
    if (variable) {
      outputChannel.appendLine("Using JAVA options set in JAVA_OPTS");
      return parse(variable).filter(
        (entry): entry is string => {
          if (typeof entry === "string") {
            return true;
          } else {
            outputChannel.appendLine(
              `Ignoring unexpected JAVA_OPTS token: ${entry}`
            );
            return false;
          }
        }
      );
    } else {
      return [];
    }
  }
  const javaOpts = expandVariable(process.env.JAVA_OPTS);
github runtools / run / core / old / 3 / src / resources / macro.js View on Github external
async $invoke(_expression, {owner} = {}) {
    const expressions = this.$expressions || [];
    let result;
    for (let expression of expressions) {
      const args = parse(expression, variable => '$' + variable);
      expression = parseCommandLineArguments(args);
      result = await this._invokeExpression(expression, {owner});
    }
    return result;
  }

shell-quote

quote and parse shell commands

MIT
Latest version published 2 years ago

Package Health Score

77 / 100
Full package analysis

Popular shell-quote functions