#!/bin/sh # The MIT License (MIT) # # Copyright © 2020-2025 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. # tip [seconds...] [options...] # # # Top ImProved runs `top` using better default settings, offering # easier-to-use command-line options. Updates happen every 2 seconds # by default, unless another number is given; these interval numbers # can also have decimals. # # The options are, available both in single and double-dash 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/RES (memory) use # -mem reverse-sort entries by latest sampled RSS/RES (memory) use # -res reverse-sort entries by latest sampled RSS/RES (memory) use # -rss reverse-sort entries by latest sampled RSS/RES (memory) use # # -shr reverse-sort entries by latest sampled shared memory use # # -t reverse-sort entries by running time # -time reverse-sort entries by running time # # -u sort entries by user # -user sort entries by user # # -v reverse-sort entries by latest sampled VIRTual memory use # -virt reverse-sort entries by latest sampled VIRTual memory use case "$1" in -h|--h|-help|--help) awk '/^# +tip /, /^$/ { gsub(/^# ?/, ""); print }' "$0" exit 0 ;; esac sort="" seconds=2 num_regex='^(\.[0-9]+|[1-9]+(\.[0-9]+)?)$' for arg in "$@"; do case "${arg}" in --) break;; -c|--c|-cpu|--cpu) sort="-o %CPU";; -i|--i|-id|--id|-pid|--pid) sort="-o PID";; -m|--m|-mem|--mem|-res|--res|-rss|--rss) sort="-o RES";; -shr|--shr) sort="-o SHR";; -t|--t|-time|--time) sort="-o TIME+";; -u|--u|-user|--user) sort="-o USER";; -v|--v|-virt|--virt) sort="-o VIRT";; *) if echo "${arg}" | grep -E -q "${num_regex}"; then seconds="${arg}" fi ;; esac done # restore previous screen contents when sent an INT signal, which usually # happens by pressing Ctrl+C trap 'tput rmcup; exit 130' INT tput smcup top -d "${seconds}" ${sort} code=$? tput rmcup exit "${code}"