40_linux.zsh 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #
  2. # Linux Stuff
  3. #
  4. #
  5. # Alias / Functions
  6. #
  7. mdstat() {
  8. if [ -f /proc/mdstat ]; then
  9. cat /proc/mdstat
  10. else
  11. print "Linux Software RAID not available on this system."
  12. return 1
  13. fi
  14. }
  15. # Fancy cp with progressbar (using strace)
  16. # from http://chris-lamb.co.uk/2008/01/24/can-you-get-cp-to-give-a-progress-bar-like-wget/
  17. cp_p() {
  18. strace -q -ewrite cp -- "${1}" "${2}" 2>&1 | awk '{
  19. count += $NF
  20. if (count % 10 == 0) {
  21. percent = count / total_size * 100
  22. printf "%3d%% [", percent
  23. for (i=0;i<=percent;i++)
  24. printf "="
  25. printf ">"
  26. for (i=percent;i<100;i++)
  27. printf " "
  28. printf "]\r"
  29. }
  30. }
  31. END { print "" }' total_size=$(stat -c '%s' "${1}") count=0
  32. }
  33. lsswap () {
  34. awk 'BEGIN{printf "%-7s %-16s %s (KB)\n", "PID","COMM","VMSWAP"} {
  35. if($1 == "Name:"){
  36. n=$2
  37. }
  38. if($1 == "Pid:"){
  39. p=$2
  40. }
  41. if($1 == "VmSwap:" && $2 != "0"){
  42. printf "%-7s %-16s %s\n", p,n,$2 | "sort -nrk3"
  43. }
  44. }' /proc/*/status
  45. }