From: Ian Kelling Date: Fri, 9 Sep 2016 20:52:37 +0000 (-0700) Subject: add psg-function X-Git-Url: https://iankelling.org/git/?a=commitdiff_plain;h=d45fc11e96ef63e654f12a7ca91a8ce2c0145cb8;p=small-misc-bash add psg-function --- diff --git a/psg-function b/psg-function new file mode 100644 index 0000000..ccdd12a --- /dev/null +++ b/psg-function @@ -0,0 +1,31 @@ +#!/bin/bash +# Copyright (C) 2016 Ian Kelling + +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 + +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +psg () { + local x y help + help="Usage: psg [--help] GREP_ARGS +grep ps and output in a nice format" + if [[ $1 == --help ]]; then + echo "$help" + return + fi + x=$(sudo ps -eF) + # final grep is because some commands tend to have a lot of trailing spaces + y=$(echo "$x" | grep -P "$@" | grep -o '.*[^ ]') + if [[ $y ]]; then + echo "$x" | head -n 1 + echo "$y" + fi +}