Last active
February 26, 2016 17:18
-
-
Save kossoy/1266890 to your computer and use it in GitHub Desktop.
WhatSize in shell
This file contains 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
#!/usr/bin/env bash | |
# Thanks to bolk http://bolknote.ru/2011/09/14/~3407#07 | |
function PrintBar { | |
if [[ $TERM =~ 256 || $TERM_PROGRAM = "iTerm.app" ]]; then | |
local colors=("38;5;34" "38;5;220" "38;5;160") | |
else | |
local colors=(32 33 31) | |
fi | |
local c=${colors[0]} | |
[ $1 -ge 13 ] && c=${colors[1]} | |
[ $1 -ge 20 ] && c=${colors[2]} | |
local bar=$(cat) | |
local prg=$(printf "%0$1s" | tr 0 ${bar:2:1}) | |
local rep="\033[${c}m$prg\033[30m" | |
echo -e ${bar/$prg/$rep} | |
} | |
function PrintItems { | |
du -s .[!.]* * | sort -rn | head -n $listlength \ | |
| sed s/^[0-9]*// | while read item | |
do | |
if [ "$item" != "" ]; then | |
local cur=$(du -s "$item" | awk '{ print $1 }' ) | |
[[ $max = "" ]] && max=$cur | |
let percent="($cur*40/$max)" | |
folder=`du -hs "$item"` | |
echo -e "│ ████████████████████████████████████████ \033[0m│ $folder" \ | |
| PrintBar $percent | |
fi | |
done | |
} | |
if [ "$1" = "" ]; then | |
listlength=10 | |
else | |
listlength=$1 | |
fi | |
echo ┌──────────────────────────────────────────┐ | |
PrintItems | |
echo └──────────────────────────────────────────┘ | |
echo -e "\033[0m" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment