From d5b7cee9733531c3e273794dbf1a5264c6e96b3c Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Wed, 3 Oct 2018 20:33:37 +0200 Subject: 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. --- src/cocoa_bridge.rs | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'src') 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 { } }, 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) -- cgit v1.2.3