From c94a3826dfd2eae66a80d4691cd7c9a5ebc06430 Mon Sep 17 00:00:00 2001 From: Matej Cotman Date: Wed, 15 Mar 2023 20:52:48 +0200 Subject: [PATCH] fix(command): accept command arg as space delimited string --- Cargo.lock | 2 +- Cargo.toml | 2 +- README.md | 5 ++--- src/main.rs | 14 +++++++------- 4 files changed, 11 insertions(+), 12 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5e13922..f462f24 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -721,7 +721,7 @@ checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" [[package]] name = "sway-scratchpad" -version = "0.1.3" +version = "0.1.4" dependencies = [ "async-process", "clap", diff --git a/Cargo.toml b/Cargo.toml index 7a81079..aca1e78 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "sway-scratchpad" -version = "0.1.3" +version = "0.1.4" description = "Convert a command to a scratchpad" homepage = "https://github.com/matejc/sway-scratchpad" repository = "https://github.com/matejc/sway-scratchpad" diff --git a/README.md b/README.md index f81fbb0..b033018 100644 --- a/README.md +++ b/README.md @@ -15,8 +15,7 @@ Usage: sway-scratchpad [OPTIONS] --command --mark Options: -s, --sock Sway/i3 socket path [default: /run/user/1000/sway-ipc.1000.2278443.sock] - -c, --command Execute command - -a, --arguments Execute command with this arguments + -c, --command Execute command with arguments --width Width of scratchpad in percent [default: 95] --height Height of scratchpad in percent [default: 90] -m, --mark Mark the container (executed command) with with this value @@ -30,7 +29,7 @@ Options: Put this in you sway config (`~/.config/sway/config`) ``` -bindsym F12 exec sway-scratchpad --command kitty --mark terminal +bindsym F12 exec sway-scratchpad --command "kitty -d /home/user/projects" --mark terminal for_window [con_mark="SCRATCHPAD_terminal"] border pixel 1 ``` diff --git a/src/main.rs b/src/main.rs index 0c2ed87..81a54a1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -16,13 +16,9 @@ struct Args { #[arg(short, long, default_value_t = var("SWAYSOCK").unwrap())] sock: String, - /// Execute command - #[arg(short, long)] - command: String, - - /// Execute command with this arguments + /// Execute command with arguments #[arg(short, long, default_value = None, use_value_delimiter = true, value_delimiter = ' ')] - arguments: Vec, + command: Vec, /// Width of scratchpad in percent #[arg(long, default_value_t = 95)] @@ -132,12 +128,16 @@ fn main() { let args: Args = Args::parse(); let mark = format!("{}{}", MARK_PREFIX, args.mark); + let argv: &mut Vec = &mut args.command.to_owned(); + let command: String = argv[0].to_owned(); + let arguments: Vec = argv[1..].to_vec(); + let mut client = Client::connect_to_path(args.sock.to_owned()).unwrap(); let tree_data: Value = from_str(&String::from_utf8_lossy(&client.ipc(ipc_command::get_tree()).unwrap())).unwrap(); let containers = find_edges(&tree_data); let marked = get_mark_container(&containers, mark.to_owned()); match marked { - Err(_) => exec(&mut client, mark, args.command, args.arguments, args.width, args.height), + Err(_) => exec(&mut client, mark, command, arguments, args.width, args.height), Ok(c) if c["focused"].as_bool().unwrap() => hide(&mut client, mark), Ok(c) if !c["focused"].as_bool().unwrap() => switch(&mut client, mark, args.width, args.height), _ => {}