forked from gregorgorjanc/GorjancShell
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunc_server.sh
More file actions
80 lines (69 loc) · 1.71 KB
/
func_server.sh
File metadata and controls
80 lines (69 loc) · 1.71 KB
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
70
71
72
73
74
75
76
77
78
79
80
# server
#-------------------------------------------------------------------------------
server() {
# Set server specific aliases and functions
# $1 = server name abbreviation
# $2 = server IP address
# $3 = username
# $4 = SSH options
local optSSH="${4//-P/-p}"
local optSCP="${4//-p/-P}"
alias "ping${1}=ping ${2}"
alias "login${1}=ssh ${optSSH} ${3}@${2}"
eval "
rsyncFrom${1}() {
local i
for i in \"\$@\"; do
rsync ${3}@${2}:\$i .
done
}"
export -f "rsyncFrom${1}"
eval "
pull${1}() {
local i
for i in \"\$@\"; do
scp -r ${optSCP} ${3}@${2}:\$i .
done
}"
export -f "pull${1}"
eval "
push${1}() {
echo \"TODO: how could we add an option to push to a user-defined folder instead of ~/.\"
scp -r ${optSCP} \"\$@\" ${3}@${2}:~/.
}"
export -f "push${1}"
eval "
diff${1}() {
local DIFF=diff
if [[ \"\$1\" == --diff=* ]]; then
DIFF=\"\${1#--diff=}\"
shift
fi
local file=\$(basename \"\$1\")
scp ${optSCP} ${3}@${2}:\"\$1\" \"\${file}_from_${1}\"
local trg=\"\${2:-\$file}\"
echo \"Compare \${file}_from_${1} to \${trg} (12=default) or vice versa (21)?\"
read -r WAY
if [[ \"\$WAY\" == \"21\" ]]; then
\"\$DIFF\" \"\$trg\" \"\${file}_from_${1}\"
else
\"\$DIFF\" \"\${file}_from_${1}\" \"\$trg\"
fi
echo \"\\nRemove the copied file \${file}_from_${1} (Y/n)?\"
read -r YORN
if [[ \"\$YORN\" != \"n\" ]]; then
rm -f \"\${file}_from_${1}\"
fi
}"
export -f "diff${1}"
eval "
cwdiff${1}() {
diff${1} --diff=cwdiff \"\$@\"
}"
export -f "cwdiff${1}"
eval "
colordiff${1}() {
diff${1} --diff=colordiff \"\$@\"
}"
export -f "colordiff${1}"
}