diff --git a/Cargo.lock b/Cargo.lock index 188423d..7d778ea 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1015,6 +1015,12 @@ dependencies = [ "serde", ] +[[package]] +name = "shlex" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42a568c8f2cd051a4d283bd6eb0343ac214c1b0f1ac19f93e1175b2dee38c73d" + [[package]] name = "slab" version = "0.4.3" @@ -1046,6 +1052,7 @@ dependencies = [ "log", "notifica", "reqwest", + "shlex", "thiserror", ] diff --git a/Cargo.toml b/Cargo.toml index 0164e95..f340ec6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,6 +13,7 @@ notifica = "3" log = "0.4" env_logger = "0.8" thiserror = "1.0" +shlex = "1.0" [dependencies.reqwest] version = "0.11" diff --git a/README.md b/README.md index d4349f0..005e4ec 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,26 @@ # sup! -`sup` is a simple cross-platform tool to send notifications via cli. It also supports an option to optionally run a given command and then send the notification once the command finishes execution. +`sup` is a simple cross-platform tool to send notifications via cli to local system or telegram. +It can also be used to get alerted after a long-running (or otherwise) command finishes. This can be used either by specifying the command at the end of the sup command, or by chaining sup with other commands. See the examples/CLI options below for more. + +## Examples +``` +# Send a notification to local system +$ sup -m "Hello world!" + +# Send a notification to telegram +$ export SUP_TG_BOT_TOKEN= +$ sup -m "Hello world!" -d telegram -c + +# Run a custom command and send notification after it finishes. Advantage of this is that sup will also report whether command was successful or not. +$ sup -m "Hello world!" sleep 5 + +# Alternate ways to run a custom command and send notification after it finishes +$ sleep 5; sup -m "Hello world!" # Always send notification +$ sleep 5 && sup -m "Hello world!" # Send notification only on success +$ sleep 5 || sup -m "Hello world!" # Send notification only on failure + +``` # Currently supported platforms - macOS diff --git a/src/cli.rs b/src/cli.rs index 0ddc0f9..19e8851 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -40,9 +40,10 @@ impl Opts { // TODO: Do this in a separate thread / async match &self.command { Some(run) => { - let split_cmd: Vec<&str> = run.split(' ').collect(); - let executable = split_cmd[0]; - let mut cmd = Command::new(&executable); + // let split_cmd: Vec<&str> = run.split(' ').collect(); + // let executable = split_cmd[0]; + let split_cmd: Vec = shlex::Shlex::new(run).by_ref().collect(); + let mut cmd = Command::new(&split_cmd[0]); if split_cmd.len() > 1 { cmd.args(&split_cmd[1..]); }