Last active
August 29, 2015 14:01
-
-
Save javidcf/57b19d2650a887cde3c7 to your computer and use it in GitHub Desktop.
cpbar: cp with a progress bar
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/sh | |
# cpbar: cp with a progress bar | |
MAXCOLS=80 | |
SLEEP=.5 | |
if [ "$#" -ne 2 ]; then | |
echo "Usage: $(basename $0) <SOURCE> <DEST>" >&2 | |
exit 1 | |
fi | |
SRC="$1" | |
DST="$2" | |
SIZE=$(du -s "${SRC}" | cut -f1) | |
cp -R "${SRC}" "${DST}" & | |
PID_CP=$! | |
print_progress () | |
{ | |
COPIED=$(du -s "${DST}" | cut -f1) | |
PERC=$(echo "(100 * ${COPIED}) / ${SIZE}" | bc) | |
COLS=$(tput cols) | |
COLS=$((${COLS}<${MAXCOLS}?${COLS}:${MAXCOLS})) | |
FILL=$(echo "(${COPIED} * (${COLS} - 7)) / ${SIZE}" | bc) | |
EMPTY=$(echo "${COLS} - 7 - ${FILL}" | bc) | |
echo -ne '\r' | |
echo -n '[' | |
for i in $(seq ${FILL}); do | |
echo -n '#' | |
done | |
for i in $(seq ${EMPTY}); do | |
echo -n '·' | |
done | |
echo -n ']' | |
printf ' %3d%%' ${PERC} | |
} | |
while kill -0 ${PID_CP} >/dev/null 2>&1; do | |
sleep ${SLEEP} | |
print_progress | |
done | |
echo '' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Just drop it wherever in your PATH and make it executable.