File: batch_copy.sh

package info (click to toggle)
clifm 1.26.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,816 kB
  • sloc: ansic: 64,595; sh: 3,133; python: 1,851; makefile: 567
file content (42 lines) | stat: -rwxr-xr-x 1,092 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/bin/sh

# Clifm plugin to copy file(s) into multiple destinations
# Written by L. Abramovich
# License: GPL2+

# Description: Copy files passed as arguments to files specified via
# a text editor

# Dependencies: grep, xargs, text editor

if [ -z "$1" ] || [ "$1" = "--help" ]; then
	name="${CLIFM_PLUGIN_NAME:-$(basename "$0")}"
	printf "Copy files into multiple directories at once\n"
	printf "\n\x1b[1mUSAGE\x1b[0m\n  %s FILE...\n" "$name"

	printf "\n\x1b[1mEXAMPLE\x1b[0m\n- Copy file1 and file2 into dir1 and dir2 at once\n\
    %s file1 file2\n\n  Once in the editor, enter dir1 and dir2, save, and exit.\n" "$name"
	exit 0
fi

DEST=$(mktemp "${TMPDIR:-/tmp}/clifm_bcd.XXXXXX")

printf "# Clifm - Copy files in batch\n\
# Write here destinty files/directories, one per line.\n\
# Blank and commented lines are omitted.\n\
# Just quit the editor to cancel the operation.\n" > "$DEST"

"${EDITOR-:nano}" "$DEST"

if ! grep -qv "^$\|^#" "$DEST"; then
	rm -f -- "$DEST"
	exit 0
fi

for file in "$@"; do
	grep -v "^$\|^#" "$DEST" | xargs -n1 cp -v "$file"
done

rm -f -- "$DEST"

exit 0