#! /usr/bin/env node
var program = require('commander');

// Googleit's version
// Only change this in release branch
program.version('1.1.4')

// Example command usages in --help
program
  .on('--help', function(){
    console.log('  Examples:');
    console.log('');
    console.log('    $ googleit weather-tomorrow');
    console.log('    $ googleit -i cat');
    console.log('    $ googleit -b harry-potter');
    console.log('');
});

program
  .arguments('<word>')
  .option('-i, --image', 'Search Image on Google')
  .option('-n, --news', 'Search News on Google')
  .option('-v, --video', 'Search Video on Google')
  .option('-p, --patent', 'Search Patent on Google')
  .option('-b, --book', 'Search Book on Google')

  .action(function(word) {
    String.prototype.replaceAll = function(search, replacement) {
      var target = this;
      return target.split(search).join(replacement);
    };

    wordValue = word;
    word = word.replaceAll("-", "%20");

    var exec = require('child_process').exec;
    var cmd = "open https://google.com/#q=" + word;
    let base = "open \'https://google.com/search?q="
    if (program.image) {
      cmd = base + word + "&tbm=isch\'"
      exec(cmd, function(error, stdout, stderr) {});
    } else if (program.news) {
      cmd = base + word + "&tbm=nws\'"
      exec(cmd, function(error, stdout, stderr) {});
    } else if (program.video) {
      cmd = base + word + "&tbm=vid\'"
      exec(cmd, function(error, stdout, stderr) {});
    } else if (program.patent) {
      cmd = base + word + "&tbm=pts\'"
      exec(cmd, function(error, stdout, stderr) {});
    } else if (program.book) {
      cmd = base + word + "&tbm=bks\'"
      exec(cmd, function(error, stdout, stderr) {});
    } else {
      exec(cmd, function(error, stdout, stderr) {});
    }
  })
  .parse(process.argv);

// Show error message when no search terms' argument provided
if (typeof wordValue === 'undefined') {
  console.error('Please enter searh terms "googleit <terms>"');
  process.exit(1);
}

@@ -433,16 +433,237 @@
 );%0A%7D);%0A%0A
+// ReplaceAll function(replaceThisWord, replacement)%0A// Use in multiple terms search%0AString.prototype.replaceAll = function(search, replacement) %7B%0A  var target = this;%0A  return target.split(search).join(replacement);%0A%7D;%0A%0A
 program%0A
@@ -969,159 +969,8 @@
 d) %7B
-%0A    String.prototype.replaceAll = function(search, replacement) %7B%0A      var target = this;%0A      return target.split(search).join(replacement);%0A    %7D;
 %0A%0A  

Move relaceAll function