-
Notifications
You must be signed in to change notification settings - Fork 1
/
CP
executable file
·69 lines (63 loc) · 2.82 KB
/
CP
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/usr/bin/env bash
#
# Author: Lilian Besson
# License: GPLv3
# Online: https://perso.crans.org/besson/bin/CP
# Online(2): https://bitbucket.org/lbesson/bin/src/master/CP
# Date: 29-04-2023
#
# A small wrapper around the output of the 'rsync' command, adding colors for interesting parts.
# Can be save to ~/bin/CP for example (or anywhere in your path).
#
# Perfect replacement for 'cp', notable improvement are:
# - the ability to copy to and from distant location (if it is reachable by SSH),
# - print the current file transfer (when file is sent, not continuously updated, but rsync is able to, I could improve)
# - exclude .git by default (if it exists)
# - follow your .gitignore files to exclude files untracked by your current Git folder (if it exists)
# - WARNING: this means that a well written .gitignore for LaTeX projects will NOT send the PDF!
# - it pretty prints in full ANSI colors to highlight different information of rsync!
# - optional: notify-send when copy is done! (just uncomment last line)
# - logs the command to /tmp/CP.log, in case you want to find again what you sent 3h ago
#
# More features!
# - You can use this script in your Makefile, to add rules to send files over the network easily:
#SHELL=/usr/bin/env /bin/bash
#send_zamok:
# CP ./ ${Szam}bin/
version='.5'
LANG='en'
# http://redsymbol.net/articles/unofficial-bash-strict-mode/
set -euo pipefail
GREP="grep --color=always --line-buffered"
# GREP="grep --color=always" # FIXME ?
echo -e "${reset}CP: receiving the argument(s) $u${black}${@}${reset}"
echo -e "CP: receiving the argument(s) ${@}" >> /tmp/CP.log
# Change in the next line the default options for rsync
# and change in the next lines the colors (ANSI Colors, in GREP_COLOR) for separate parts of the output
# --cvs-exclude \
# $([ -f .gitignore ] && echo '--exclude-from=.gitignore' ) \
# $(ls *.pdf &>/dev/null && echo '--include=*.pdf' ) \
(/usr/bin/rsync \
$([ -d .git ] && echo '--exclude=.git' ) \
--ipv4 \
--verbose \
--times \
--perms \
--compress \
--human-readable \
--progress \
--archive \
"$@" \
2>&1) \
| $GREP -vP "^\s*((\[|\]|\(|\))\s*)+$" \
| GREP_COLORS="mt=37" $GREP -P "^[\.\-_0-9a-zA-Z/]+$|$" \
| GREP_COLORS="mt=4;01;32" $GREP -P "^(sending|sent|total).*|$" \
| GREP_COLORS="mt=01;33" $GREP -P "[\.0-9]+.B/s|$" \
| GREP_COLORS="mt=7;01;36" $GREP -P "^[ \t]*[\.0-9]+[KMGT]?|$" \
| GREP_COLORS="mt=01;35" $GREP -P "to.check=[0-9]+/[0-9]+|$" \
| GREP_COLORS="mt=01;30" $GREP -P "xfer#[0-9]+|$" \
| GREP_COLORS="mt=01;36" $GREP -P "[0-9]:[0-9][0-9]:[0-9][0-9]|$" \
| GREP_COLORS="mt=01;35" $GREP -P "^[0-9]+%|$" \
| GREP_COLORS="mt=7;01;34" $GREP -P "100%|$"
echo -e "\n${reset}${blue}CP sent successfully the files from input command $u${black}${@}${reset}"
# notify-send "CP successfully sent the files, from input command: ${@}" || echo "Failed to send notification" >/dev/stderr