fix: allow pre-command without command in custom mode

This commit is contained in:
SW 2026-07-10 10:41:58 +02:00
parent 0544eb0582
commit bc8f0de5c3
2 changed files with 13 additions and 4 deletions

View file

@ -1,6 +1,6 @@
[package] [package]
name = "lines" name = "lines"
version = "0.1.17" version = "0.1.18"
edition = "2024" edition = "2024"
authors = ["janvete"] authors = ["janvete"]
description = "TUI for running frequently used commands" description = "TUI for running frequently used commands"

View file

@ -2,7 +2,9 @@ use crate::app::CustomState;
pub fn build_commands(state: &CustomState) -> Vec<String> { pub fn build_commands(state: &CustomState) -> Vec<String> {
let command = state.command.trim(); 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(); return Vec::new();
} }
@ -11,7 +13,6 @@ pub fn build_commands(state: &CustomState) -> Vec<String> {
return Vec::new(); return Vec::new();
} }
let pre_command = state.pre_command.trim();
let prefix = if pre_command.is_empty() { let prefix = if pre_command.is_empty() {
String::new() String::new()
} else { } else {
@ -22,7 +23,9 @@ pub fn build_commands(state: &CustomState) -> Vec<String> {
.iter() .iter()
.map(|line| { .map(|line| {
let line = line.trim(); 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) command.replace("{}", line)
} else { } else {
format!("{} \"{}\"", line, command.replace('"', "\\\"")) format!("{} \"{}\"", line, command.replace('"', "\\\""))
@ -116,4 +119,10 @@ mod tests {
vec!["lview ssh root@ip1 lsblk", "lview ssh root@ip2 lsblk"] 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"]);
}
} }