X-Git-Url: https://iankelling.org/git/?p=small-misc-bash;a=blobdiff_plain;f=psg-function;fp=psg-function;h=ccdd12aff199341b56c2c0d2c90cc99745122049;hp=0000000000000000000000000000000000000000;hb=d45fc11e96ef63e654f12a7ca91a8ce2c0145cb8;hpb=8584170426a7c06fb998992e9fdde659c1b418cb 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 +}