How to use shellwords - 10 common examples

To help you get started, we’ve selected a few shellwords 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 chrisallenlane / novahot / app / cmd / shell / adapter-edit.js View on Github external
module.exports = function(config, req, cmd, callback) {

  // tokenize the input string
  const tokenized = shellwords.split(cmd);
  const src       = tokenized[1] || '';

  // Generate a temporary file with an extension that mathces the source file.
  // The matching extension is important to allow editors to choose the
  // appropriate syntax-highlighting automatically.
  const dst = tmp.fileSync({ postfix: path.extname(src) }).name;

  // assert that src was provided
  if (! src) {

    // assemble an error message
    var err = [
      'Specify a file to edit.',
      'Usage: edit '
    ].join('\n');
github chrisallenlane / novahot / app / cmd / shell / adapter-upload.js View on Github external
module.exports = function(config, req, cmd, callback) {

  // tokenize the input string
  const tokenized = shellwords.split(cmd);
  const src       = tokenized[1] || '';
  const dst       = tokenized[2] || path.basename(src);

  // assert that src was provided
  if (src === '') {

    // assemble an error message
    var err = [
      'Specify a file to upload.',
      'Usage: upload  []'
    ].join('\n');

    return callback(new Error(err));
  }

  // read the file data
github ioquatix / script-runner / lib / script-runner-process.js View on Github external
execute(cmd, env, editor) {
		// Split the incoming command so we can modify it
		const args = Shellwords.split(cmd);
		
		if (this.resolveSelection(editor, (text, cwd) => {
			args.push(TempWrite.sync(text));
			return this.spawn(args, cwd, env);
		})) { return true; }
		
		if (this.resolvePath(editor, (path, cwd) => {
			args.push(path);
			return this.spawn(args, cwd, env);
		})) { return true; }
		
		if (this.resolveBuffer(editor, (text, cwd) => {
			args.push(TempWrite.sync(text));
			return this.spawn(args, cwd, env);
		})) { return true; }
github alan-ai / alan-sdk-reactnative / testtools / node_modules / node-notifier / lib / utils.js View on Github external
module.exports.command = function(notifier, options, cb) {
  notifier = shellwords.escape(notifier);
  if (process.env.DEBUG && process.env.DEBUG.indexOf('notifier') !== -1) {
    console.info('node-notifier debug info (command):');
    console.info('[notifier path]', notifier);
    console.info('[notifier options]', options.join(' '));
  }

  return cp.exec(notifier + ' ' + options.join(' '), function(
    error,
    stdout,
    stderr
  ) {
    if (error) return cb(error);
    cb(stderr, stdout);
  });
};
github esy / esy / esy-install / src / lib / shell.js View on Github external
export function split(str: string): Array {
  return shellwords.split(str);
}
github tj / parse-curl.js / index.js View on Github external
module.exports = exports.default = function(s) {
  if (0 != s.indexOf('curl ')) return
  var args = rewrite(words.split(s))
  var out = { method: 'GET', header: {} }
  var state = ''

  args.forEach(function(arg){
    switch (true) {
      case isURL(arg):
        out.url = arg
        break;

      case arg == '-A' || arg == '--user-agent':
        state = 'user-agent'
        break;

      case arg == '-H' || arg == '--header':
        state = 'header'
        break;
github brookshi / Hitchhiker / client / src / utils / curl_import.ts View on Github external
static do(target: string, collectionId: string = ''): DtoRecord | undefined {

        let content = this.prepare(target);
        if (!content.includes('curl ')) {
            return undefined;
        }

        content = content.replace(/--data\s+""/g, '');

        const args = words.split(content);
        const result: DtoRecord = getDefaultRecord();
        result.method = 'GET';
        const headers = result.headers || [];
        let state = '';
        args.forEach((arg: any) => {
            if (StringUtil.urlRegex().test(arg)) {
                result.url = arg;
                state = '';
            } else if (arg === '-I' || arg === '--head') {
                result.method = 'HEAD';
                state = '';
            } else {
                if (!state) {
                    state = this.parseState(arg);
                } else if (!!arg) {
                    switch (state) {
github ioquatix / script-runner / lib / script-runner.js View on Github external
ShellEnvironment.loginEnvironment((error, environment) => {
				if (environment) {
					const cmd = environment['SHELL'];
					const args = Shellwords.split(cmd).concat("-l");
					
					ScriptRunnerProcess.spawn(view, args, path, environment);
				} else {
					throw new Error(error);
				}
			});
		});
github lintopher0315 / Quick-Math / node_modules / node-notifier / lib / utils.js View on Github external
module.exports.command = function(notifier, options, cb) {
  notifier = shellwords.escape(notifier);
  if (process.env.DEBUG && process.env.DEBUG.indexOf('notifier') !== -1) {
    console.info('node-notifier debug info (command):');
    console.info('[notifier path]', notifier);
    console.info('[notifier options]', options.join(' '));
  }

  return cp.exec(notifier + ' ' + options.join(' '), function(
    error,
    stdout,
    stderr
  ) {
    if (error) return cb(error);
    cb(stderr, stdout);
  });
};
github mikaelbr / node-notifier / lib / utils.js View on Github external
module.exports.command = function(notifier, options, cb) {
  notifier = shellwords.escape(notifier);
  if (process.env.DEBUG && process.env.DEBUG.indexOf('notifier') !== -1) {
    console.info('node-notifier debug info (command):');
    console.info('[notifier path]', notifier);
    console.info('[notifier options]', options.join(' '));
  }

  return cp.exec(notifier + ' ' + options.join(' '), function(
    error,
    stdout,
    stderr
  ) {
    if (error) return cb(error);
    cb(stderr, stdout);
  });
};

shellwords

Manipulate strings according to the word parsing rules of the UNIX Bourne shell.

MIT
Latest version published 3 years ago

Package Health Score

65 / 100
Full package analysis

Popular shellwords functions