Skip to content

Commit

Permalink
Updating to use shell as defined in the plugin's config. Defaults to …
Browse files Browse the repository at this point in the history
…bash if none is defined.

See imsnif#1
  • Loading branch information
leakec committed Sep 22, 2023
1 parent 70f868a commit 8bdd881
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion dev.kdl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ 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'"
}
Expand Down
9 changes: 7 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,19 @@ struct State {
last_run: Option<Instant>,
is_hidden: bool,
plugin_id: Option<u32>,
shell: String,
}

impl ZellijPlugin for State {
fn load(&mut self, _: BTreeMap<String, String>) {
fn load(&mut self, config: BTreeMap<String, String>) {
request_permission(&[PermissionType::ReadApplicationState, PermissionType::ChangeApplicationState, PermissionType::RunCommands, PermissionType::OpenFiles, PermissionType::OpenTerminalsOrPlugins]);
subscribe(&[EventType::PaneUpdate, EventType::FileSystemUpdate, EventType::FileSystemDelete, EventType::Key]);
self.plugin_id = Some(get_plugin_ids().plugin_id);
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 @@ -107,7 +112,7 @@ impl State {
}
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
4 changes: 2 additions & 2 deletions src/multitask_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub fn create_file_with_text(path: &Path, text: &str) {
};
}

pub fn parse_multitask_file(filename: PathBuf) -> Result<Vec<ParallelTasks>, std::io::Error> {
pub fn parse_multitask_file(filename: PathBuf, shell: &str) -> Result<Vec<ParallelTasks>, std::io::Error> {
let stringified_file = std::fs::read_to_string(filename)?;
let mut parallel_tasks = vec![];
let mut current_tasks = vec![];
Expand All @@ -22,7 +22,7 @@ pub fn parse_multitask_file(filename: PathBuf) -> Result<Vec<ParallelTasks>, std
let line = line.to_string();
let line_is_empty = line.trim().is_empty();
if !line.starts_with("#") && !line_is_empty {
let task = RunTask::from_file_line(&line, current_step);
let task = RunTask::from_file_line(shell, &line, current_step);
current_tasks.push(task);
} else if line_is_empty && !current_tasks.is_empty() {
parallel_tasks.push(ParallelTasks::new(current_tasks.drain(..).collect()));
Expand Down
4 changes: 2 additions & 2 deletions src/parallel_tasks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ impl RunTask {
..Default::default()
}
}
pub fn from_file_line(file_line: &str, step_number: usize) -> Self {
Self::new(vec!["bash", "-c", file_line])
pub fn from_file_line(shell: &str, file_line: &str, step_number: usize) -> Self {
Self::new(vec![shell, "-c", file_line])
.pane_title(format!("STEP {} - {}", step_number, file_line))
}
pub fn pane_title(mut self, title: String) -> Self {
Expand Down

0 comments on commit 8bdd881

Please sign in to comment.