aboutsummaryrefslogtreecommitdiff
path: root/src/actions/command.js
blob: c98327888fd82a9d2e859dab45ea604398a52087 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import actions from '../actions';

const normalizeUrl = (string) => {
  try {
    return new URL(string).href
  } catch (e) {
    return 'http://' + string;
  }
}

export function exec(line) {
  let name = line.split(' ')[0];
  let remaining = line.replace(name + ' ', '');

  switch (name) {
  case 'open':
    // TODO use search engined and pass keywords to them
    return {
      type: actions.COMMAND_OPEN_URL,
      url: normalizeUrl(remaining)
    };
  case 'tabopen':
    return {
      type: actions.COMMAND_TABOPEN_URL,
      url: normalizeUrl(remaining)
    };
  case 'b':
  case 'buffer':
    return {
      type: actions.COMMAND_BUFFER,
      keywords: remaining
    };
  }
  throw new Error(name + ' command is not defined');
}