From d45fc11e96ef63e654f12a7ca91a8ce2c0145cb8 Mon Sep 17 00:00:00 2001 From: Ian Kelling Date: Fri, 9 Sep 2016 13:52:37 -0700 Subject: [PATCH] add psg-function --- psg-function | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 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 +} -- 2.30.2