Widget: fix interpretation of ||

Fixes #543
This commit is contained in:
Denis Isidoro 2021-08-09 10:42:51 -03:00 committed by GitHub
parent c976c9199d
commit 3abd3dad6e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -46,13 +46,13 @@ pub fn widget_last_command() -> Result<()> {
let mut text = String::new();
io::stdin().read_to_string(&mut text)?;
let replacements = vec![("|", ""), ("||", ""), ("&&", "")];
let replacements = vec![("||", ""), ("|", ""), ("&&", "")];
let parts = shellwords::split(&text).unwrap_or_else(|_| text.split('|').map(|s| s.to_string()).collect());
for p in parts {
for (pattern, escaped) in replacements.clone() {
if p.contains(pattern) && p != pattern {
if p.contains(pattern) && p != pattern && p != format!("{}{}", pattern, pattern) {
let replacement = p.replace(pattern, escaped);
text = text.replace(&p, &replacement);
}
@ -60,6 +60,7 @@ pub fn widget_last_command() -> Result<()> {
}
let mut extracted = text.clone();
for (pattern, _) in replacements.clone() {
let mut new_parts = text.rsplit(pattern);
if let Some(extracted_attempt) = new_parts.next() {