Skip to content

Commit

Permalink
Widget: fix interpretation of ||
Browse files Browse the repository at this point in the history
Fixes #543
  • Loading branch information
denisidoro authored Aug 9, 2021
1 parent c976c91 commit 3abd3da
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,20 +46,21 @@ 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);
}
}
}

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() {
Expand Down

0 comments on commit 3abd3da

Please sign in to comment.