Skip to content

Commit

Permalink
Fix external command parsing. Added examples
Browse files Browse the repository at this point in the history
  • Loading branch information
shantanugoel committed Jun 13, 2021
1 parent d4c6702 commit 4fc69c2
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 4 deletions.
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ notifica = "3"
log = "0.4"
env_logger = "0.8"
thiserror = "1.0"
shlex = "1.0"

[dependencies.reqwest]
version = "0.11"
Expand Down
22 changes: 21 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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=<Your telegram bot token>
$ sup -m "Hello world!" -d telegram -c <your-telegram-chat-id>
# 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
Expand Down
7 changes: 4 additions & 3 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> = 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..]);
}
Expand Down

0 comments on commit 4fc69c2

Please sign in to comment.