diff --git a/Cargo.toml b/Cargo.toml index cafa17b..5c0a00a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "lines" -version = "0.1.17" +version = "0.1.18" edition = "2024" authors = ["janvete"] description = "TUI for running frequently used commands" diff --git a/src/custom.rs b/src/custom.rs index b803265..272e2b9 100644 --- a/src/custom.rs +++ b/src/custom.rs @@ -2,7 +2,9 @@ use crate::app::CustomState; pub fn build_commands(state: &CustomState) -> Vec { let command = state.command.trim(); - if command.is_empty() { + let pre_command = state.pre_command.trim(); + + if command.is_empty() && pre_command.is_empty() { return Vec::new(); } @@ -11,7 +13,6 @@ pub fn build_commands(state: &CustomState) -> Vec { return Vec::new(); } - let pre_command = state.pre_command.trim(); let prefix = if pre_command.is_empty() { String::new() } else { @@ -22,7 +23,9 @@ pub fn build_commands(state: &CustomState) -> Vec { .iter() .map(|line| { let line = line.trim(); - let built = if command.contains("{}") { + let built = if command.is_empty() { + line.to_string() + } else if command.contains("{}") { command.replace("{}", line) } else { format!("{} \"{}\"", line, command.replace('"', "\\\"")) @@ -116,4 +119,10 @@ mod tests { vec!["lview ssh root@ip1 lsblk", "lview ssh root@ip2 lsblk"] ); } + + #[test] + fn test_build_commands_pre_command_only() { + let state = make_state(vec!["ssh root@ip1", "ssh root@ip2"], vec![false, true], "", "lview"); + assert_eq!(build_commands(&state), vec!["lview ssh root@ip2"]); + } }