Skip to content

Commit

Permalink
Merge pull request #2 from leakec/feature/user_shell
Browse files Browse the repository at this point in the history
Use user $SHELL to run commands rather than bash
  • Loading branch information
leakec authored Sep 26, 2023
2 parents 44845cb + 7cdd860 commit 67b9752
Show file tree
Hide file tree
Showing 7 changed files with 176 additions and 34 deletions.
154 changes: 145 additions & 9 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[package]
name = "multitask"
version = "0.37.2"
version = "0.38.2"
authors = ["Aram Drevekenin <[email protected]>"]
edition = "2018"

[dependencies]
zellij-tile = "0.37.2"
zellij-tile = "0.38.2"
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ echo "so will I!"
## Installation
1. Download the `multitask.wasm` file from the release matching your installed Zellij version
2. Place it in `~/zellij-plugins`
3. From within Zellij, run `zellij action start-or-reload-plugin file:~/zellij-plugins/multitask.wasm`
3. From within Zellij, run `zellij action start-or-reload-plugin file:~/zellij-plugins/multitask.wasm --configuration "shell=$SHELL"`

## Development

Expand Down
8 changes: 1 addition & 7 deletions dev.kdl
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,11 @@ layout {
}
pane stacked=true {
pane size="10%" command="bash" name="COMPILE AND RELOAD PLUGIN" {
args "-c" "cargo build && zellij action start-or-reload-plugin file:target/wasm32-wasi/debug/multitask.wasm"
args "-c" "cargo build && zellij action start-or-reload-plugin file:target/wasm32-wasi/debug/multitask.wasm --configuration \"shell=$SHELL\""
// if you have "watchexec" installed, you can comment the above line and uncomment the below one to build + reload the plugin on fs changes
// args "-c" "watchexec 'cargo build && zellij action start-or-reload-plugin file:target/wasm32-wasi/debug/multitask.wasm'"
}
pane expanded=true {
plugin location="file:target/wasm32-wasi/debug/multitask.wasm"
}
}
}
}
pane size=2 borderless=true {
plugin location="zellij:status-bar"
}
}
32 changes: 22 additions & 10 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ mod parallel_tasks;
mod multitask_file;
use zellij_tile::prelude::*;

use std::collections::VecDeque;
use std::collections::{VecDeque, BTreeMap};

use std::path::PathBuf;
use std::time::{Instant, Duration};

Expand All @@ -21,15 +22,19 @@ struct State {
last_run: Option<Instant>,
is_hidden: bool,
plugin_id: Option<u32>,
shell: String,
}

register_plugin!(State);

impl ZellijPlugin for State {
fn load(&mut self) {
fn load(&mut self, config: BTreeMap<String, String>) {
request_permission(&[PermissionType::ReadApplicationState, PermissionType::ChangeApplicationState, PermissionType::RunCommands, PermissionType::OpenFiles]);
subscribe(&[EventType::PaneUpdate, EventType::FileSystemUpdate, EventType::FileSystemDelete, EventType::Key]);
self.plugin_id = Some(get_plugin_ids().plugin_id);
self.multitask_file = PathBuf::from(".multitask");
self.multitask_file = PathBuf::from("/host").join(".multitask");
self.shell = match config.get("shell") {
Some(s) => String::from(s),
_ => String::from("bash")
};
show_self(true);
}

Expand Down Expand Up @@ -65,21 +70,26 @@ impl State {
pub fn start_current_tasks(&mut self) {
if let Some(running_tasks) = &self.running_tasks {
for task in &running_tasks.run_tasks {
open_command_pane_floating(&task.command, task.args.iter().map(|a| a.as_str()).collect());
let cmd = CommandToRun {
path: (&task.command).into(),
args: task.args.clone(),
cwd: None
};
open_command_pane_floating(cmd);
}
}
}
pub fn progress_running_tasks(&mut self) {
if let Some(running_tasks) = self.running_tasks.as_ref() {
for task in &running_tasks.run_tasks {
if let Some(terminal_pane_id) = task.terminal_pane_id {
focus_terminal_pane(terminal_pane_id as i32, true);
focus_terminal_pane(terminal_pane_id as u32, true);
toggle_pane_embed_or_eject();
self.completed_task_ids.push(terminal_pane_id);
}
}
if let Some(edit_pane_id) = self.edit_pane_id {
focus_terminal_pane(edit_pane_id as i32, false);
focus_terminal_pane(edit_pane_id as u32, false);
}
}
self.running_tasks = None;
Expand All @@ -95,14 +105,14 @@ impl State {
}
all_tasks.append(&mut self.completed_task_ids.drain(..).collect());
for pane_id in all_tasks {
close_terminal_pane(pane_id as i32);
close_terminal_pane(pane_id as u32);
}
self.running_tasks = None;
self.completed_task_ids = vec![];
}
pub fn parse_file(&mut self) -> bool {
let filename = PathBuf::from("/host").join(&self.multitask_file);
match parse_multitask_file(filename) {
match parse_multitask_file(filename, self.shell.as_str()) {
Ok(new_tasks) => {
self.tasks = new_tasks.into();
return true;
Expand Down Expand Up @@ -162,3 +172,5 @@ impl State {
return false;
}
}

register_plugin!(State);
Loading

0 comments on commit 67b9752

Please sign in to comment.