From bb0a558efff30a9dab9a6561ca2d6cf99e9a41d6 Mon Sep 17 00:00:00 2001 From: boards Date: Sat, 2 Jan 2010 18:19:12 +0000 Subject: [PATCH] From issue 1: * Changed default option to search only user's processes. * Added option to search all user's processes. * Added header output from ps. Option to disable. * Fixed bug where processes with a leading dash couldn't be grep'd for. Other: * Updated man page reflecting new options. --HG-- extra : convert_revision : svn%3Aa4405340-9a3f-0410-a3d8-31b31f83d5c0/trunk%4015 --- psgrep | 24 +++++++++++++++++------- psgrep.1 | 20 +++++++++++++++----- 2 files changed, 32 insertions(+), 12 deletions(-) diff --git a/psgrep b/psgrep index 9365f3f..5c3ba92 100755 --- a/psgrep +++ b/psgrep @@ -17,7 +17,7 @@ # GNU General Public License for more details. PS_CMD="$(which ps)" -PS_OPTS="aux" +PS_OPTS="ux" GREP_CMD="$(which grep)" GREP_OPTS="" @@ -28,16 +28,19 @@ usage() echo "Usage: $0 [options] Options: - -b Search using BSD's ps format (aux) [default] + -n Don't print header + -a Search processes of all users + -b Search using BSD's ps format (ux) [default] -l Search using Linux's ps format (-ef) -s Search using simplified format (PID, user, command) -o Search using custom ps output format -i Ignore case in searches -e Use extended regexps (egrep) + -i Use case-insensitive regexps (grep -i) -p Use perl regexps (grep -P) -h View this message -v View version information" - exit 1 + exit 0 } version_info() @@ -54,20 +57,27 @@ Public License version 3, or (at your option) any later version." [ $# -lt 1 ] && usage -while getopts "blso:iephv" opt; do +while getopts "nablso:iephv" opt; do case $opt in h) usage;; v) version_info;; - b) PS_OPTS="aux";; + n) NO_HEADER=1;; + a) PS_OPTS="aux";; + b) PS_OPTS="ux";; l) PS_OPTS="-ef";; s) PS_OPTS="-eo pid,euser,comm";; o) PS_OPTS="-eo $OPTARG";; i) GREP_CMD="${GREP_CMD} -i";; e) GREP_CMD="${GREP_CMD} -E";; + i) GREP_CMD="${GREP_CMD} -i";; p) GREP_CMD="${GREP_CMD} -P";; esac done # now the actual execution -# HOLY SHIT did it take forever to figure out how to use the rest of the command -$PS_CMD $PS_OPTS | $GREP_CMD ${@:$OPTIND} | $GREP_CMD -v "$GREP_CMD" | $GREP_CMD -v "$0" +HEADER=$($PS_CMD $PS_OPTS | head -n1) +RESULT=$($PS_CMD $PS_OPTS | $GREP_CMD -- "${*:$OPTIND}" | $GREP_CMD -v "$GREP_CMD" | $GREP_CMD -v "$0") +if [ "$RESULT" ]; then + [ ! "$NO_HEADER" ] && echo "$HEADER" + echo "$RESULT" +fi diff --git a/psgrep.1 b/psgrep.1 index 44511ac..6500ccf 100644 --- a/psgrep.1 +++ b/psgrep.1 @@ -1,9 +1,9 @@ .\" vim:syn=groff: .\" Man page for psgrep -.TH PSGREP 1 "2007-06-30" "" "psgrep Manual" +.TH PSGREP 1 "2010-01-02" "" "psgrep Manual" . .SH NAME -psgrep \- search process list using the power of grep +psgrep \- search the process list using the power of grep . .SH SYNOPSIS psgrep [options] \fIPATTERN\fR @@ -29,8 +29,14 @@ of this script was entirely due to this annoyance with the given method. . .SH OPTIONS .TP +.B -a +Search the process list using BSD's \*(lqps aux\*(rq format. This option +includes all users' processes in the search. +. +.TP .B -b -Search the process list using BSD's \*(lqps aux\*(rq format (default). +Search the process list using BSD's \*(lqps ux\*(rq format (\fBdefault\fR). +This option only includes the running user's processes. . .TP .B -l @@ -62,6 +68,9 @@ Search using extended regular expressions (i.e., using \*(lqegrep\*(rq or Search using Perl regular expressions (i.e., using \*(lqgrep -P\*(rq). . .TP +.B -n +Don't display \fBps\fR(1) header information. +.TP .B -h Display a brief usage message, and exit with a status of 1. . @@ -70,14 +79,15 @@ Display a brief usage message, and exit with a status of 1. Display version and licensing info, and exit with a status of 2. . .SH BUGS -No known bugs, but if you find any, please email them to . +No known bugs, but if you find any, please email them to +or submit them to . .SH AUTHORS psgrep was written by Matt Sicker with help from your local manpages. . .SH COPYRIGHT .PP -psgrep is Copyright (C) 2006-2007 Matt Sicker. +psgrep is Copyright (C) 2006-2010 Matt Sicker. .PP This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by