-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinsert.sh
executable file
·70 lines (65 loc) · 1.21 KB
/
insert.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
#!/bin/bash
#{{{
red=1
green=148
blue=147
function color {
if [ -n "$1" ]; then
echo -e -n "\033[38;5;$1m"
else
echo -e -n "\033[39m"
fi
}
function message {
color $green
echo $@
color
}
function error {
color $red
echo $@
color
}
#}}}
#Usage:
if [[ $1 == help ]]; then
color $blue
echo "Použitie: $0 <xx-dir1> <xx-dir2> .. <xx-dirn>"
echo
echo "Vyrobí priečinky a poposúva tie s kolidujúcim číslom."
echo
color
exit
fi
function plusone {
val=`echo $1 + 1 | bc`
if [[ "$val" == ? ]]; then
val=0$val
fi
echo $val
}
for arg in $@; do
dir=`dirname $arg`/
file=`basename $arg`
num=${file%%-*}
list=''
while true; do
if [ -z "`find $dir -name $num-*`" ]; then
break
fi
list="$num $list"
num=`plusone $num`
done
for x in $list; do
y=`plusone $x`
if [ ! -z "`find $dir -name $x-*`" ]; then
for from in $dir$x-*; do
from=`basename $from`
to=$y-${from#*-}
message "Rename: $from -> $to"
mv $dir$from $dir$to
done
fi
done
mkdir $arg
done