Fix cp plugin completion and refactor (#5427)
* cp plugin: change cpv to function so that completion works
* cp plugin: show numbers in units of 1024 (K,M,G,T)
Use `-h` level (3): output numbers in units of 1024.
See the manpage of rsync for more information.
* cp plugin: add a README file
* cp plugin: recurse directories
* cp plugin: remove `--` to separate files from options
This has some undesired effects, like having `cpv --help` be a file
not found error.
Use `--` yourself if you need it (which you generally don't):
```zsh
cpv -- -some-file-with-hyphens.txt /tmp
```
Added this same info to the README.
Diff
1diff --git a/plugins/cp/README.md b/plugins/cp/README.md
2new file mode 100644
3index 0000000000000000000000000000000000000000..e8a9b6ccc8130bd0223ab8fec381b6baa24f91df
4--- /dev/null
5+++ b/plugins/cp/README.md
6@@ -0,0 +1,32 @@
7+# cp plugin
8+
9+This plugin defines a `cpv` function that uses `rsync` so that you
10+get the features and security of this command.
11+
12+To enable, add `cp` to your `plugins` array in your zshrc file:
13+
14+```zsh
15+plugins=(... cp)
16+```
17+
18+## Description
19+
20+The enabled options for rsync are:
21+
22+- `-p`: preserves permissions.
23+
24+- `-o`: preserves owner.
25+
26+* `-g`: preserves group.
27+
28+* `-b`: make a backup of the original file instead of overwriting it, if it exists.
29+
30+* `-r`: recurse directories.
31+
32+* `-hhh`: outputs numbers in human-readable format, in units of 1024 (K, M, G, T).
33+
34+* `--backup-dir=/tmp/rsync`: move backup copies to "/tmp/rsync".
35+
36+* `-e /dev/null`: only work on local files (disable remote shells).
37+
38+* `--progress`: display progress.
39diff --git a/plugins/cp/cp.plugin.zsh b/plugins/cp/cp.plugin.zsh
40index 7355a99902792ba5875256322da3997b3e348760..fe6ea87a860b1d1b251d64a5b2f8816f8b027bc5 100644
41--- a/plugins/cp/cp.plugin.zsh
42+++ b/plugins/cp/cp.plugin.zsh
43@@ -1,14 +1,4 @@
44-#Show progress while file is copying
45-
46-# Rsync options are:
47-# -p - preserve permissions
48-# -o - preserve owner
49-# -g - preserve group
50-# -h - output in human-readable format
51-# --progress - display progress
52-# -b - instead of just overwriting an existing file, save the original
53-# --backup-dir=/tmp/rsync - move backup copies to "/tmp/rsync"
54-# -e /dev/null - only work on local files
55-# -- - everything after this is an argument, even if it looks like an option
56-
57-alias cpv="rsync -poghb --backup-dir=/tmp/rsync -e /dev/null --progress --"
58+cpv() {
59+ rsync -pogbr -hhh --backup-dir=/tmp/rsync -e /dev/null --progress "$@"
60+}
61+compdef _files cpv