-
Notifications
You must be signed in to change notification settings - Fork 0
/
sequence.sh
executable file
·115 lines (98 loc) · 2.12 KB
/
sequence.sh
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#!/bin/bash
#set -x
#
#
wd=$(dirname $0)
#
#
function usage {
cat<<EOF>&2
Synopsis
$0 [file]+
Description
Move one or more <file> to target (of).
Synopsis
$0 [dir]+
Description
Move one or more <dir>/* <file> to target (of).
See also
./target.sh
EOF
}
#
#
#
if [ -n "${1}" ]
then
if [ -f "${1}" ]
then
while [ 0 -lt $# ]
do
src="${1}"
shift
#
# [relocate]
#
if [ -f "${src}" ] && tgt=$(${wd}/target.sh "${src}")
then
if [ "${src}" = "${tgt}" ] || git mv -f "${src}" "${tgt}"
then
git status --porcelain "${tgt}"
else
cat<<EOF>&2
$0 error in main: moving file <${src}> to <${tgt}>.
EOF
exit 1
fi
else
cat<<EOF>&2
$0 error in main: file <${src}> in dir <${dir}>.
EOF
exit 1
fi
done
exit 0
elif [ -d "${tgt}" ]
then
while [ 0 -lt $# ]
do
dir="${1}"
shift
if [ -d "${dir}" ]
then
for src in ${tgt}/*.*
do
#
# [relocate]
#
if [ -f "${src}" ] && tgt=$(${wd}/target.sh "${src}")
then
if [ "${src}" = "${tgt}" ] || git mv -f "${src}" "${tgt}"
then
git status --porcelain "${tgt}"
else
cat<<EOF>&2
$0 error in main: moving file <${src}> to <${tgt}>.
EOF
exit 1
fi
else
cat<<EOF>&2
$0 error in main: file <${src}> in dir <${dir}>.
EOF
exit 1
fi
done
else
cat<<EOF>&2
$0 error in main: argument <${dir}> not directory.
EOF
exit 1
fi
done
exit 0
fi
else
usage
exit 1
fi