Skip to content

Commit

Permalink
fix(command): accept command arg as space delimited string
Browse files Browse the repository at this point in the history
  • Loading branch information
matejc committed Mar 15, 2023
1 parent 6504211 commit c94a382
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ Usage: sway-scratchpad [OPTIONS] --command <COMMAND> --mark <MARK>
Options:
-s, --sock <SOCK> Sway/i3 socket path [default: /run/user/1000/sway-ipc.1000.2278443.sock]
-c, --command <COMMAND> Execute command
-a, --arguments <ARGUMENTS> Execute command with this arguments
-c, --command <COMMAND> Execute command with arguments
--width <WIDTH> Width of scratchpad in percent [default: 95]
--height <HEIGHT> Height of scratchpad in percent [default: 90]
-m, --mark <MARK> Mark the container (executed command) with with this value
Expand All @@ -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
```
14 changes: 7 additions & 7 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>,
command: Vec<String>,

/// Width of scratchpad in percent
#[arg(long, default_value_t = 95)]
Expand Down Expand Up @@ -132,12 +128,16 @@ fn main() {
let args: Args = Args::parse();
let mark = format!("{}{}", MARK_PREFIX, args.mark);

let argv: &mut Vec<String> = &mut args.command.to_owned();
let command: String = argv[0].to_owned();
let arguments: Vec<String> = 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),
_ => {}
Expand Down

0 comments on commit c94a382

Please sign in to comment.