Skip to content

Commit

Permalink
From issue 1:
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
boards committed Jan 2, 2010
1 parent f51866a commit bb0a558
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 12 deletions.
24 changes: 17 additions & 7 deletions psgrep
Original file line number Diff line number Diff line change
Expand Up @@ -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=""

Expand All @@ -28,16 +28,19 @@ usage()
echo "Usage: $0 [options] <search terms>
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 <opts> 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()
Expand All @@ -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
20 changes: 15 additions & 5 deletions psgrep.1
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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.
.
Expand All @@ -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 <boards@gmail.com>.
No known bugs, but if you find any, please email them to <boards@gmail.com>
or submit them to <http://code.google.com/p/psgrep/issues/list>
.
.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
Expand Down

0 comments on commit bb0a558

Please sign in to comment.