diff --git a/Cargo.lock b/Cargo.lock index b138f88..98735a4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -125,6 +125,16 @@ version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "23b62fc65de8e4e7f52534fb52b0f3ed04746ae267519eef2a83941e8085068b" +[[package]] +name = "async-attributes" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a3203e79f4dd9bdda415ed03cf14dae5a2bf775c683a00f94e9cd1faf0f596e5" +dependencies = [ + "quote", + "syn 1.0.109", +] + [[package]] name = "async-channel" version = "1.9.0" @@ -218,6 +228,7 @@ version = "1.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "62565bb4402e926b29953c785397c6dc0391b7b446e45008b0049eb43cec6f5d" dependencies = [ + "async-attributes", "async-channel", "async-global-executor", "async-io", @@ -1085,6 +1096,7 @@ dependencies = [ "owo-colors", "shellwords", "zellij-tile", + "zellij-utils", ] [[package]] @@ -3617,9 +3629,9 @@ dependencies = [ [[package]] name = "zellij-tile" -version = "0.39.0" +version = "0.40.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eacfea6cb4aeae01ebecec27e5003daa51078a8812a402f462fb872dbeb150c4" +checksum = "58471198b62771e4387ac00c072e9b1d8ebd87db2568bdb5fbb60dd99d8552bd" dependencies = [ "clap", "serde", @@ -3631,9 +3643,9 @@ dependencies = [ [[package]] name = "zellij-utils" -version = "0.39.0" +version = "0.40.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d0f8bcd0ce51223b2124470e70bdbbaac17aa0281abcbb0defb2c41026e84f0e" +checksum = "5289f6ff643db4f7f772f090cede454cd1be276a3a5654464c402094b625524f" dependencies = [ "anyhow", "async-channel", diff --git a/Cargo.toml b/Cargo.toml index 5cf2fff..326a8f8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,7 +7,9 @@ edition = "2021" [dependencies] ansi_term = "0.12.1" -zellij-tile = "0.39.0" +zellij-tile = "0.40.0" +zellij-utils = "0.40.0" + owo-colors = "3.5.0" shellwords = "1.0.0" fuzzy-matcher = "0.3.7" diff --git a/README.md b/README.md index 8d0b404..f4bda4a 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ If the plugin finds a `.ghost` at the working dir of the plugin, it will add the ## Requirements -Zellij version `v0.38.0` or later. +Zellij version `v0.40.0` or later. ### Zellij Plugin Permission @@ -52,6 +52,15 @@ go test -v ./... ## Install +### Upgrade + +#### Breaking Change + +##### v0.4.0 + +* renamed config `cwd` with `exec_cwd` + + ### Download WASM Binary @@ -72,9 +81,9 @@ Then you can use the `./verify_signature.sh` in this repo: ``` for example ```bash -$ ./verify_signature.sh ~/Downloads/ghost.wasm v0.1.0 +$ ./verify_signature.sh ~/Downloads/ghost.wasm v0.4.0 -Checking Signature for version: v0.1.0 +Checking Signature for version: v0.4.0 Verified OK ``` @@ -123,13 +132,14 @@ Verified OK ### Optional Configuration -| Key | value | desctiption | -|---------------------|----------------------------|------------------------------------------------------------| -| `cwd` | directory path | set working dir for command | -| `embedded` | `true` | created command panes are embedded instead of floating | -| `ghost_launcher` | GhostLauncher pane name | plugin will automatically close that pane | -| `debug` | `true` | display debug info | -| `global_completion` | multine list of completion | global list of completion to inlude to `/host/.ghost` file | +| Key | value | desctiption | +|----------------------------------------------------|----------------------------|------------------------------------------------------------| +| ~~ `cwd` (**deprecate** use `exec_cwd` instead) ~~ | directory path | set working dir for command | +| `exec_cwd` (zellij `0.40.0`) | directory path | set working dir for command | +| `embedded` | `true` | created command panes are embedded instead of floating | +| `ghost_launcher` | GhostLauncher pane name | plugin will automatically close that pane | +| `debug` | `true` | display debug info | +| `global_completion` | multine list of completion | global list of completion to inlude to `/host/.ghost` file | @@ -137,12 +147,12 @@ Verified OK ## Launch Plugin ```bash -zellij action launch-or-focus-plugin --floating --configuration "shell=zsh,shell_flag=-ic,cwd=$(pwd)" "file:$HOME/.config/zellij/plugins/ghost.wasm" +zellij plugin --floating --configuration "shell=zsh,shell_flag=-ic,cwd=$(pwd)" -- "file:$HOME/.config/zellij/plugins/ghost.wasm" ``` ## Config Keybindings -> NOTE: The `LaunchOrFocusPlugin` keybing action does not allow to dynamically pass the cwd to the plugin. As a workaround, you can use the `Run` keybinding action to execute the `zellij action launch-or-focus-plugin` from a RunCommand pane where you can pass the plugin config `cwd=$(pwd)`. The cwd should be the same as the previously focused pane. +> NOTE: The `LaunchOrFocusPlugin` keybing action does not allow to dynamically pass the cwd to the plugin. As a workaround, you can use the `Run` keybinding action to execute the `zellij plugin` from a RunCommand pane where you can pass the plugin config `exec_cwd=$(pwd)`. The cwd should be the same as the previously focused pane. ```kdl shared_except "locked" { @@ -175,7 +185,7 @@ shared_except "locked" { // using GhostLauncher "hack" to pass the cwd=$(pwd) as runtime config bind "Alt )" { // NOTE: you can pass the global_completion as runtim config with the '\n' delimiter between commands - Run "bash" "-ic" "zellij action launch-or-focus-plugin --floating --configuration \"shell=zsh,shell_flag=-ic,cwd=$(pwd),ghost_launcher=GhostLauncher,debug=false,global_competion=tf apply -auto-approve \ncargo build \ngo test -v ./...\" \"file:$HOME/.config/zellij/plugins/ghost.wasm\"" { + Run "bash" "-ic" "zellij plugin --floating --configuration \"shell=zsh,shell_flag=-ic,cwd=$(pwd),ghost_launcher=GhostLauncher,debug=false,global_completion=tf apply -auto-approve \ncargo build \ngo test -v ./...\" -- \"file:$HOME/.config/zellij/plugins/ghost.wasm\"" { floating true name "GhostLauncher" // this must match ghost_launcher=GhostLauncher // the plugin will automatically close the pane diff --git a/src/main.rs b/src/main.rs index 01234d9..a1be22b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,14 +1,13 @@ use ansi_term::{Colour::Fixed, Style}; +use fuzzy_matcher::skim::SkimMatcherV2; use fuzzy_matcher::FuzzyMatcher; use owo_colors::OwoColorize; use shellwords::MismatchedQuotes; -use zellij_tile::prelude::*; - -use fuzzy_matcher::skim::SkimMatcherV2; use std::fs::File; use std::io::{self, BufRead}; use std::path::Path; use std::{collections::BTreeMap, path::PathBuf}; +use zellij_tile::prelude::*; // use sprintf::sprintf; struct State { @@ -192,7 +191,7 @@ impl State { /// Create a RunCommand pane with input_cmd if valid fn run_command(&mut self, input_cmd: String) { // get working dir from config - let plugin_cwd = self.userspace_configuration.get("cwd"); + let plugin_cwd = self.userspace_configuration.get("exec_cwd"); let cwd = match plugin_cwd { Some(path) => { let mut pb = PathBuf::new(); @@ -225,11 +224,14 @@ impl State { cwd, }); } else { - open_command_pane_floating(CommandToRun { - path: exec, - args: zsh_args, - cwd, - }); + open_command_pane_floating( + CommandToRun { + path: exec, + args: zsh_args, + cwd, + }, + None, + ); } if self.launcher_pane_id.is_some() { close_terminal_pane(self.launcher_pane_id.unwrap()); @@ -295,7 +297,7 @@ impl ZellijPlugin for State { let filename = "/host/.ghost".to_owned(); if let Ok(lines) = read_lines(filename) { // Consumes the iterator, returns an (Optional) String - for cmd in lines.flatten() { + for cmd in lines.map_while(Result::ok) { // ignore commented lines starting with '#' // or empty line if !cmd.trim_start().starts_with('#') && !cmd.trim_start().is_empty() { @@ -450,11 +452,11 @@ impl ZellijPlugin for State { } // current dir view - if let Some(plugin_cwd) = self.userspace_configuration.get("cwd") { + if let Some(plugin_cwd) = self.userspace_configuration.get("exec_cwd") { println!(); println!( " {}: {}", - color_bold(WHITE, "cwd"), + color_bold(WHITE, "exec_cwd"), plugin_cwd.blue().bold() ); }