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).
This commit is contained in:
2022-10-08 00:41:34 +02:00
parent b398375020
commit c0a741889b

View File

@@ -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).