-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdirify
41 lines (37 loc) · 854 Bytes
/
dirify
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
#! /bin/bash
#
# Scan current directory for the new entries and add them to the database as
# "new"
#
#
# First, move each non-directory file in a directory by its own.
#
find . -type f -maxdepth 1 | while read ;do
f="$REPLY"
t=$(echo "$f" | tr ' ' '-')
echo "$f" '->' "$t"
mv "$f" _t
mkdir "$t"
mv _t "$t/$f"
done
#
# Then, fix all the names, replacing spaces with '-'.
#
find . -maxdepth 1 | while read ;do
f="$REPLY"
t=$(echo "$f" | tr ' ' '-')
if [ "x$f" != "x$t" ] ;then
echo "$f" '->' "$t"
mv "$f" "$t"
fi
done
#
# Finally, add missing entries to the data-base.
#
find . -maxdepth 1 | while read ;do
f=$(basename "$REPLY")
if [ "$f" = "." ] ;then continue; fi
grep -F " $f/" ../db >/dev/null && continue
echo "new $f/" >> ../db
echo "new $f/"
done