aboutsummaryrefslogtreecommitdiff
path: root/src/actions
diff options
context:
space:
mode:
authorShin'ya Ueoka <ueokande@i-beam.org>2017-09-11 21:07:02 +0900
committerShin'ya Ueoka <ueokande@i-beam.org>2017-09-11 21:07:02 +0900
commitbf890a6d9d793b581a44ee267616ed589f429bef (patch)
tree56f0616eed462d825a5e9006f3994fea588df19a /src/actions
parent14d13e2c3abdb090431f59970681cdaf95f0a24a (diff)
command as action/reducer
Diffstat (limited to 'src/actions')
-rw-r--r--src/actions/command.js35
-rw-r--r--src/actions/index.js4
2 files changed, 39 insertions, 0 deletions
diff --git a/src/actions/command.js b/src/actions/command.js
new file mode 100644
index 0000000..982255c
--- /dev/null
+++ b/src/actions/command.js
@@ -0,0 +1,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: remaining
+ };
+ case 'b':
+ case 'buffer':
+ return {
+ type: actions.COMMAND_BUFFER,
+ keywords: remaining
+ };
+ }
+ throw new Error(name + ' command is not defined');
+}
diff --git a/src/actions/index.js b/src/actions/index.js
index 135dd4a..63d5f6f 100644
--- a/src/actions/index.js
+++ b/src/actions/index.js
@@ -33,4 +33,8 @@ export default {
// User input
INPUT_KEY_PRESS: 'input.key,press',
INPUT_CLEAR_KEYS: 'input.clear.keys',
+
+ COMMAND_OPEN_URL: 'command.open.url',
+ COMMAND_TABOPEN_URL: 'command.tabopen.url',
+ COMMAND_BUFFER: 'command.buffer',
};