diff --git a/.config/zsh/zshrc.d/40-functions.zsh b/.config/zsh/zshrc.d/40-functions.zsh index 6680c9d..37c3ca8 100644 --- a/.config/zsh/zshrc.d/40-functions.zsh +++ b/.config/zsh/zshrc.d/40-functions.zsh @@ -482,31 +482,21 @@ _page_readme_chpwd_handler() { done } -# Improved pgrep # I sometimes find `pgrep` not matching the processes I am searching for, but # `ps aux | grep ...` did not disappoint yet. -pgrep() { - # Fall back to real `pgrep` if options are specified. I have no interest in - # emulating `pgrep` features with `ps` and other tools. This function is - # only meant for quick searches - if (( $# > 1 )); then - command pgrep "$@" - return - fi - +psgrep() { # - Set EXTENDED_GLOB for the `b` globbing flag. - # - Set UNSET so that no arguments can be specified leading to `grep ""` - # matching everything, as `ps aux` without pipe would be my desired - # behavior. - emulate -L zsh -o extendedglob -o unset + emulate -L zsh -o extendedglob - # 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). - # So for example: "pattern" -> "[p]attern" - # This has the effect that the `grep` does not grep itself in the processes - # list. - ps aux | grep "${1/(#b)(?)/[$match]}" + for arg; do + # 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). + # So for example: "pattern" -> "[p]attern" + # This has the effect that the `grep` does not grep itself in the processes + # list. + ps aux | grep "${arg/(#b)(?)/[$match]}" + done } # Use shellcheck.net if shellcheck is not installed.