Skip to content

Instantly share code, notes, and snippets.

@pcercuei
Created May 17, 2013 01:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pcercuei/5596309 to your computer and use it in GitHub Desktop.
Save pcercuei/5596309 to your computer and use it in GitHub Desktop.
#!/bin/sh
SOURCE=$1
DEST=$2
if [ ! -e "$SOURCE" -o ! -e "$DEST" ] ; then
echo "USAGE: dialogcp file dest"
exit 0
fi
copy_file() {
SIZE_KB=`du -k $SOURCE |cut -f1`
OFFSET=0
if [ $SIZE_KB -le 100 ] ; then
BS=1
else
BS=$(($SIZE_KB / 100))
fi
while test $OFFSET -lt $SIZE_KB ; do
dd if="$SOURCE" bs=${BS}k skip=$OFFSET count=1 2>/dev/null
OFFSET=$(($OFFSET + $BS))
PERCENT=$((100 * $OFFSET / $SIZE_KB))
echo "$PERCENT" >&2
done
}
copy_file 2>&1 > "$DEST" | dialog --gauge "Copying $SOURCE to $DEST..." 0 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment