From c0a741889b4c254c9cb1e228bf59c1c272a4ddd0 Mon Sep 17 00:00:00 2001 From: Julian Prein Date: Sat, 8 Oct 2022 00:41:34 +0200 Subject: [PATCH] zsh:funcs:psgrep: Pass regex directly If a pattern is passed that starts with a special character, the `[]`-"quoting" would possible lead to errors or change it's meaning. To prevent that, pass the argument directly to grep if it looks like a regex (i.e. contains a special character). --- .config/zsh/zshrc.d/40-functions.zsh | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.config/zsh/zshrc.d/40-functions.zsh b/.config/zsh/zshrc.d/40-functions.zsh index bea270a..e5e926b 100644 --- a/.config/zsh/zshrc.d/40-functions.zsh +++ b/.config/zsh/zshrc.d/40-functions.zsh @@ -492,6 +492,12 @@ psgrep() { ps u | head -1 for arg; do + # Pass to grep directly if it looks like a regex + if [[ "$arg" =~ '[][$|.*?+\\()^]' ]]; then + ps aux | grep -E "$arg" + continue + fi + # Substitute the captured first character with itself surrounded by # brackets. The `(#b)` turns on backreferences, storing the match in the # array $match (in this case with only one element).