Skip to content

Commit

Permalink
feat: rename cwd to exec_cwd for zellij 0.40.0
Browse files Browse the repository at this point in the history
  • Loading branch information
vdbulcke committed Apr 20, 2024
1 parent f6d6aa9 commit 34bede2
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 30 deletions.
20 changes: 16 additions & 4 deletions Cargo.lock

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

4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
36 changes: 23 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -52,6 +52,15 @@ go test -v ./...

## Install

### Upgrade

#### Breaking Change

##### v0.4.0

* renamed config `cwd` with `exec_cwd`


### Download WASM Binary


Expand All @@ -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

```
Expand Down Expand Up @@ -123,26 +132,27 @@ 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 |




## 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" {
Expand Down Expand Up @@ -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
Expand Down
26 changes: 14 additions & 12 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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()
);
}
Expand Down

0 comments on commit 34bede2

Please sign in to comment.