mirror of
https://github.com/FliegendeWurst/tmux-thumbs.git
synced 2024-11-22 12:54:59 +00:00
Handle better wrong executions of tmux-thumbs
This commit is contained in:
parent
674bec31fc
commit
eeb2b5f98f
@ -250,21 +250,23 @@ impl<'a> Swapper<'a> {
|
||||
pub fn execute_command(&mut self) {
|
||||
let content = self.content.clone().unwrap();
|
||||
let mut splitter = content.splitn(2, ':');
|
||||
let upcase = splitter.next().unwrap().trim_end();
|
||||
let text = splitter.next().unwrap().trim_end();
|
||||
|
||||
let execute_command = if upcase == "true" {
|
||||
if let Some(upcase) = splitter.next() {
|
||||
if let Some(text) = splitter.next() {
|
||||
let execute_command = if upcase.trim_end() == "true" {
|
||||
self.upcase_command.clone()
|
||||
} else {
|
||||
self.command.clone()
|
||||
};
|
||||
|
||||
let final_command = str::replace(execute_command.as_str(), "{}", text);
|
||||
let final_command = str::replace(execute_command.as_str(), "{}", text.trim_end());
|
||||
let retrieve_command = vec!["bash", "-c", final_command.as_str()];
|
||||
let params = retrieve_command.iter().map(|arg| arg.to_string()).collect();
|
||||
|
||||
self.executor.execute(params);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
@ -359,6 +361,10 @@ fn main() -> std::io::Result<()> {
|
||||
let command = args.value_of("command").unwrap();
|
||||
let upcase_command = args.value_of("upcase_command").unwrap();
|
||||
|
||||
if dir.is_empty() {
|
||||
panic!("Invalid tmux-thumbs execution. Are you trying to execute tmux-thumbs directly?")
|
||||
}
|
||||
|
||||
let mut executor = RealShell::new();
|
||||
let mut swapper = Swapper::new(
|
||||
Box::new(&mut executor),
|
||||
|
Loading…
Reference in New Issue
Block a user