fix quotation marks
[mi.git] / mi
blobf1f33a15b69d9768f5b6e43e9dfeae23c24e2878
1 #!/bin/sh
3 # mi
5 # 28-Jan-2009 Clemens Buchacher <clemens.buchacher@infineon.com>
7 # BUGS
9 # o name conflicts
11 # If two files have the same target, or if files 'a', 'b', are renamed to
12 # 'b', 'c', respectively, in the wrong order. The file may be overwritten.
14 # o subentry conflicts
16 # If both a directory and its contained files are moved, this can have
17 # unexpected results.
20 prog=$0
22 error()
24 echo -n "$prog: error: "
25 echo $@ >&2
28 OPT=`getopt -o f -- "$@"` || exit 1
29 eval set -- "$OPT"
31 force=
32 done=
33 while test "$1" != "--"
35 case "$1" in
36 -f) force=YesPlease;;
37 *) echo "unkown option: $1"; exit 1;;
38 esac
39 shift
40 done
41 shift
43 if test -z "$1"
44 then
45 set -- *
47 orignames=`mktemp`
48 while test -n "$1"
50 echo `echo "$1" | sha1sum - | cut -f1 -d' '` "$1"
51 shift
52 done > "$orignames"
54 newnames=`mktemp`
56 echo "# This program is under development. Use at your own risk!";
57 echo "# Remove all content to abort";
58 cat "$orignames"
59 ) > $newnames
60 if ! ${EDITOR:=vi} "$newnames"
61 then
62 error "aborted"
63 exit 1
66 oldlines=`mktemp`
67 cat "$newnames" | grep -v '^\s*\(#.*\)\?$' | \
68 while read sha1 newname
70 if ! expr "$sha1" : '[0-9a-f]\{40\}$' >/dev/null
71 then
72 error "invalid hash: $sha1"
73 continue
75 oldname=`sed -n "/^$sha1\s\+/ {s/^$sha1\s\+//p; q}" "$orignames"`
76 if test -z "$oldname"
77 then
78 error "unknown hash: $sha1"
79 continue
81 if test "$oldname" != "$newname"
82 then
83 echo "\`$oldname' -> \`$newname'"
84 if test -z "$force" && test -e "$newname"
85 then
86 error "rename would overwrite existing file"
87 else
88 mv -f "$oldname" "$newname"
91 done
93 rm -f "$newnames"
94 rm -f "$orignames"