Skip to content

Instantly share code, notes, and snippets.

@c00kiemon5ter
Created February 11, 2012 01:21
Show Gist options
  • Save c00kiemon5ter/1794917 to your computer and use it in GitHub Desktop.
Save c00kiemon5ter/1794917 to your computer and use it in GitHub Desktop.
cp wrapper with a progressbar
#!/bin/bash
current=0
completed=0
read -r total _ < <(/bin/du -bc "${@:1:${#}-1}" | tail -n1)
/bin/cp $@ &
while (( current != total )); do
read -r current _ < <(/bin/du -bc "${!#}" | tail -n1)
completed="$((current * 100 / total ))"
lines="$((completed * ($(tput cols) - 1 - 5) / 100))"
printf -- "\r%3d%% " "$completed"
for ((i=0; i<$lines; i++)); do printf -- "%s" "="; done
done
printf -- ">\n"
@c00kiemon5ter
Copy link
Author

ofcourse many problems lying around

  • no arguments to cp
  • cp is hardcoded
  • although it calculates total size to copy, multiple arguments may fail
  • if cat fails we get an infinite loop
  • etc

oeople should use stuff like pv, this was hacked for fun,
and if used it's better of with only one soure and target file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment