#!/bin/sh # The MIT License (MIT) # # Copyright (c) 2026 pacman64 # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in # all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. # nps [seconds...] [options...] [ps options...] # # # Nice `Process Show` displays all current processes using ANSI styles, so # things are easier to scan/read. All data come from the `ps` command: when # not given any `ps`-specific options, `ps aux` is run by default. # # The options are the same as those for `ps`, as well as the ones listed # below, available in single and double-dashed versions # # -c reverse-sort entries by latest sampled CPU use # -cpu reverse-sort entries by latest sampled CPU use # # -h show this help message # -help show this help message # # -i sort entries by PID # -id sort entries by PID # -pid sort entries by PID # # -m reverse-sort entries by latest sampled RSS (memory) use # -mem reverse-sort entries by latest sampled RSS (memory) use # -rss reverse-sort entries by latest sampled RSS (memory) use case "$1" in -h|--h|-help|--help) awk '/^# +nps /, /^$/ { gsub(/^# ?/, ""); print }' "$0" ps --help exit 0 ;; esac for arg in "$@"; do if [ "${arg}" = '--' ]; then break fi case "${arg}" in a|u|x|au|ax|ua|ux|xa|xu) options="${options} ${arg}";; aux|axu|uax|uxa|xau|xua) options="${options} ${arg}";; -c|--c|-cpu|--cpu) options="${options} --sort=-%cpu,-rss";; -i|--i|-id|--id|-pid|--pid) options="${options} --sort=pid";; -m|--m|-mem|--mem|-rss|--rss) options="${options} --sort=-rss,-%cpu";; -u|--u|-user|--user) options="${options} --sort=user,-%cpu,-rss";; --sort=*) options="${options} ${arg}";; esac done res="$(ps ${options:-aux})" code=$? if [ "${code}" -ne 0 ]; then return "${code}" fi echo "${res}" | # restyle numbers with at least 4 digits to make them easier to read; restyle # lines where root is the user; make 0 values stand out in any line sed -E \ -e 's-([0-9]{1,3})([0-9]{6}|[0-9]{3})( |$)-\x1b[36m\1\x1b[0m\2\3-g' \ -e '/^root/s-\x1b\[0m-\x1b[0m\x1b[33m-g; /^root/s-^-\x1b[33m-' \ -e 's-0(\.00*|:00)-\x1b[34m0\1\x1b[0m-g' | # add a header line with the current time/date and empty lines to chunk things awk ' BEGIN { now = strftime("%a %b %d %Y %H:%M:%S") printf "%26s\x1b[7m%s\x1b[0m\n\n", "", now } (NR - 1) % 5 == 1 { print "" } 1 ' | { less -MKiCRS --header=3 2> /dev/null || cat; }