Created
January 30, 2015 14:57
-
-
Save markogresak/33327b78145ad9e63dc5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| function help { | |
| echo -en "\033cPritisnite: | |
| q - izhod iz programa (quit) | |
| h - izpiše pomoč in čaka na pritisk tipke (help) | |
| c - menjava vidnosti izpisa ukaza (command toggle display) | |
| m - menjava vidnosti izpisa porabe pomnilnika (memory toggle display) | |
| p - menjava vidnosti izpisa zasedenosti cpu (cpu toggle display) | |
| u - menjava izpisa uporabnika (user toggle display) | |
| \nPritisnite 'q' za nadalejevanje..." | |
| while read -n 1 -s; do if [[ "$REPLY" == "q" ]]; then return; fi; done | |
| } | |
| flags=("pid" "comm" "%mem" "user" "%cpu") | |
| while true; do | |
| echo -e "\033c $(ps -Ao "$(echo "${flags[*]}" | sed -e 's/\s\+/,/g;s/,$//g')" --sort=-pcpu | head -n11)" | |
| read -n 1 -s -t 1 | |
| case $REPLY in | |
| (q) exit ;; | |
| (h) help ;; | |
| (c) [[ -n "${flags[1]}" ]] && flags[1]="" || flags[1]="comm" ;; | |
| (m) [[ -n "${flags[2]}" ]] && flags[2]="" || flags[2]="%mem" ;; | |
| (p) [[ -n "${flags[4]}" ]] && flags[4]="" || flags[4]="%cpu" ;; | |
| (u) [[ -n "${flags[3]}" ]] && flags[3]="" || flags[3]="user" ;; | |
| esac | |
| done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment