-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlinkffile
executable file
·84 lines (76 loc) · 1.92 KB
/
linkffile
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
#!/bin/bash
# 08.01.02
# Usage: linkffile <dir> <file>
# Reads <file> until the first space of each line, and recursively links files from <dir> with matching filenames to the current dir. Asks if ambiguous.
if [ ! -d "$1" ]
then
echo "Can't find the dir $1"
exit
fi
if [ ! -f "$2" ]
then
echo "Can't find the file $2"
exit
fi
sorszam=`cat $2 | awk 'BEGIN { a = 0 } { a++ } END { print(a); }'`
for i in `seq 1 $sorszam`;
do
target=""
# If path is full and valid then link it right away
fline=`sed "${i}q;d" "$2"`
if [ -f "$fline" ]
then
target=$fline
# Otherwise let's find it
else
awkmondta=`cat $2 | awk '((NR == sor) && ($1 !~ /^\*/)) {
print($1)
}' sor=$i`
if [ "$awkmondta" != "" ]; then
findutasitas="$(find $1 -name \*$awkmondta\*)"
#echo "findu: $findutasitas"
sorsz=`echo "$findutasitas" | awk 'BEGIN { a = 0 } { a++ } END { print(a); }'`
if [ "$sorsz" = "1" ]; then
target="$findutasitas"
fi
if [ "$sorsz" = "0" ]; then
echo "Couldn't find $awkmondta"
echo ""
fi
if [ $sorsz -gt 1 ]; then
melyik=0
# while [ $melyik -lt 1 ] || [ $melyik -gt $sorsz ]; do
while [[ !($melyik -ge 1 && $melyik -le $sorsz) ]]; do
echo "For $awkmondta, found several of:"
echo "$findutasitas" | awk '{ print(NR". "$0) }'
echo "Which one should we use? (x: none)"
read melyik
if [ "$melyik" == "x" ]
then
break
elif [ $melyik -le $sorsz ] && [ $melyik -ge 1 ]
then
target=`echo "$findutasitas" | awk '(NR == melyikis) {print($1)}' melyikis=$melyik`
else
echo "I don't like your answer."
fi
echo ""
done
fi
fi
fi
# Check if we have a link/file already under that name
if [ "$target" != "" ]
then
localfn=$(basename $target)
while [ -e "$localfn" ]
do
veg=${localfn##*.}
elej=${localfn%.*}
localfn="$elej-.$veg"
done
# Now do the link
# echo "$target --> $localfn"
ln -sv "$target" "$localfn"
fi
done