Skip to content

Instantly share code, notes, and snippets.

@meoow
Last active August 29, 2015 14:05
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 meoow/bfbaae18100920b3aa8b to your computer and use it in GitHub Desktop.
Save meoow/bfbaae18100920b3aa8b to your computer and use it in GitHub Desktop.
Simple alternative for **cp** but shows progress
cpv() {
if ! type -P pv >/dev/null;then
echo need pv >&2
return 1
fi
case $# in
0|1)
echo invalid arguments >&2
return 1
;;
2)
if [[ -f "$1" ]];then
if [[ ! -e "$2" ]] || [[ -f "$2" ]];then
pv "$1" > "$2"
elif [[ -d "$2" ]];then
pv "$1" > "$2/$(basename "$1")"
fi
elif [[ -d "$1" ]];then
if [[ ! -e "$2" ]];then
(cd "$1" || exit 1
mkdir "$2" || exit 1
tar cf - . | pv | tar xf - -C "$2")
elif [[ -d "$2" ]];then
tar cf - "$1" | pv | tar xf - -C "$2"
fi
fi
;;
*)
local args dest
args=("$@")
dest=${args[${#args[@]}-1]}
unset args[${#args[@]}-1]
if [[ -d "$dest" ]];then
tar cf - "${args[@]}" | pv | tar xf - -C "$dest"
fi
;;
esac
}
cpv "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment