aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTeddy Wing2018-10-03 20:33:37 +0200
committerTeddy Wing2018-10-03 23:17:17 +0200
commitd5b7cee9733531c3e273794dbf1a5264c6e96b3c (patch)
treecf8be176b0e7bcdad3735ed74bc84a0eec12b0a2 /src
parent0dad180d2f64e3260a1c71551dc4d8e6d027a171 (diff)
downloaddome-key-map-d5b7cee9733531c3e273794dbf1a5264c6e96b3c.tar.bz2
run_key_action_for_mode(): Run mode-level commands
Originally I was going to use `Action::Command` for this, which was intended to hold a `Vec` of command arguments. I decided against that approach. After thinking about command parsing a bit, it's of course not just splitting into a `Vec` on whitespace. You need to take into account quoting and whatever other idiosyncrasies. Instead, I think I'm going to leave commands as `Action::String`s and end up not using `Action::Command` for anything. We take the shell command string from the action and feed it to a new `Command`, executed using the `-c` option to the parent shell. As I understand it, `spawn()` will reuse the parent process' stdout etc. descriptors.
Diffstat (limited to 'src')
-rw-r--r--src/cocoa_bridge.rs22
1 files changed, 21 insertions, 1 deletions
diff --git a/src/cocoa_bridge.rs b/src/cocoa_bridge.rs
index ec9497d..addf340 100644
--- a/src/cocoa_bridge.rs
+++ b/src/cocoa_bridge.rs
@@ -1,6 +1,8 @@
-use std::ffi::{CStr, CString};
+use std::env;
+use std::ffi::{CStr, CString, OsString};
use std::fs;
use std::mem;
+use std::process::Command;
use std::ptr;
use std::slice;
@@ -303,6 +305,24 @@ mode <play><up> {
}
},
MapKind::Command => {
+ if let Action::String(action) = &map.action {
+ let shell = match env::var_os("SHELL") {
+ Some(s) => s,
+ None => OsString::from("/bin/sh"),
+ };
+
+ match Command::new(shell)
+ .arg("-c")
+ .arg(action)
+ .spawn() {
+ Ok(_) => (),
+ Err(e) => error!(
+ "Command failed to start: `{}'",
+ e
+ ),
+ }
+ }
+
Some(
KeyActionResult::new(ActionKind::Command)
.in_mode(trigger)