aboutsummaryrefslogtreecommitdiff
path: root/src/actions/command.js
diff options
context:
space:
mode:
authorShin'ya Ueoka <ueokande@i-beam.org>2017-09-11 21:45:48 +0900
committerShin'ya Ueoka <ueokande@i-beam.org>2017-09-11 21:45:48 +0900
commitb2cddcd69b4ae06770d66808624fc43f3dcbcb0e (patch)
tree548eb65f678cfa1dca36773f01c635ec6c0e2066 /src/actions/command.js
parent15d39a479aa7f2c4b804bac8c4352dd0a120bc75 (diff)
parent7bc569eac745b97137e1db8b9271493b3e5c8a20 (diff)
Merge branch 'message-passing-refactoring'
Diffstat (limited to 'src/actions/command.js')
-rw-r--r--src/actions/command.js35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/actions/command.js b/src/actions/command.js
new file mode 100644
index 0000000..c983278
--- /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: normalizeUrl(remaining)
+ };
+ case 'b':
+ case 'buffer':
+ return {
+ type: actions.COMMAND_BUFFER,
+ keywords: remaining
+ };
+ }
+ throw new Error(name + ' command is not defined');
+}