Last active
January 24, 2019 21:27
-
-
Save shelbyKiraM/94012572633064e0f18cdd9f36c0247b to your computer and use it in GitHub Desktop.
ZSH function overwriting the shell built-in `cp`, using `rsync` with a progress bar.
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
function cp() { | |
if [ -f "$1" ];then | |
SIZE="$(stat -f '%z' "$1")" | |
if [ -e "$2" ];then | |
echo "File exists. Overwrite (Y/n)? " | |
read todo | |
if [ "$todo" = "y" ] || [ "$todo" = "Y" ] || [ "$todo" = "Yes" ] \ | |
|| [ "$todo" = "yes" ] || [ "$todo" = "" ];then | |
echo "Overwriting $2 with $1" | |
else | |
return | |
fi | |
fi | |
pv -s $SIZE "$1" > "$2" | |
elif [ -d "$1" ];then | |
if [ ! -e "$2" ];then | |
type="Copying" | |
elif [ -d "$2" ];then | |
read todo?"File exists. Merge (Mm) or Overwrite [Oo]? " | |
if [ "$todo" = "M" ] || [ "$todo" = "m" ];then | |
echo "Merging $1 to $2" | |
elif [ "$todo" = "O" ] || [ "$todo" = "o" ];then | |
echo "Overwriting $2 with $1" | |
rm "$2" | |
else | |
echo "Please choose M or O" | |
return | |
fi | |
fi | |
rsync -ahvPu "$1" "$2" | |
elif [ $1 != '' ];then | |
echo "Something went wrong. Please use \`cpp $1 $2\`" | |
else | |
echo 'Usage: cp input output' | |
return | |
fi | |
say 'done' | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
One issue, it doesn't allow wildcard copying? Yeah, it just deals with $1 and $2... Idk how to implement all that. Probably gonna be a loop…