Skip to content

Instantly share code, notes, and snippets.

@tdlm
Last active November 4, 2016 23:25
Show Gist options
  • Save tdlm/fd6c074cc098d5f3361f0b5fef5d41f7 to your computer and use it in GitHub Desktop.
Save tdlm/fd6c074cc098d5f3361f0b5fef5d41f7 to your computer and use it in GitHub Desktop.
The idea of processizer is to list all running processes on the Mac and display the man page description inline. If there is no man page description, eventually this process would reach out to an external API and try to find a match, which it would cache locally. Holistically, the idea is to know what's running on your system.
#!/usr/bin/env bash
function get_process_description {
local __page=$(MANWIDTH=200 man "$@" 2>&1 | col -bx)
local __desc=$(echo "$__page" | pcregrep -M -o2 '(DESCRIPTION)\n(.*)' | sed -e :a -e '/./,$!d;/^\n*$/{$d;N;};/\n$/ba')
if [[ -z "$__desc" ]]; then
return 2
else
echo $__page
fi
return 0
}
PROCESS_IDS=$(ps -xo pid | grep -v PID)
for PROCESS_ID in $PROCESS_IDS ; do
PROCESS_PATH=$(ps -o command $PROCESS_ID | grep -v COMMAND | grep -o '^[^\-]' | tr -d '\n')
if [ ! -z "$PROCESS_PATH" ]; then
PROCESS_NAME=$(basename "$PROCESS_PATH")
PROCESS_DESC=$(get_process_description "$PROCESS_NAME")
echo "PID: $PROCESS_ID"
echo "Name: $PROCESS_NAME"
if [ ! -z "$PROCESS_DESC" ]; then
echo "Description: $PROCESS_DESC"
fi
echo "---"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment