Query CMake to see if it is out of date for a build.
[SquirrelJME.git] / utils-dev / rename.sh
blobb768804fa07f8795ce47cd4a3a81e421c6a12613
1 #!/bin/sh
2 # ---------------------------------------------------------------------------
3 # Multi-Phasic Applications: SquirrelJME
4 # Copyright (C) Stephanie Gawroriski <xer@multiphasicapps.net>
5 # Copyright (C) Multi-Phasic Applications <multiphasicapps.net>
6 # ---------------------------------------------------------------------------
7 # SquirrelJME is under the GNU General Public License v3, or later.
8 # See license.mkd for licensing and copyright information.
9 # ---------------------------------------------------------------------------
10 # DESCRIPTION: Renames the given files and moves them under fossil by using
11 # the given regular expression.
13 # Force C locale
14 export LC_ALL=C
16 # Directory of this script
17 __exedir="$(dirname -- "$0")"
19 # Need at least two arguments
20 if [ "$#" -lt "2" ]
21 then
22 echo "Usage: $0 (sed expression) (files...)"
23 exit 1
26 # Read the sed expression
27 __sed="$1"
28 shift
30 # Go through all the given files
31 while [ "$#" -ge "1" ]
33 # Ignore directories
34 if [ -d "$1" ]
35 then
36 continue
39 # Get the directory the file is in and its base name
40 __dir="$(dirname -- "$1")"
41 __fna="$(basename -- "$1")"
43 # No longer need the argument
44 shift
46 # Sed transform the file name
47 __tra="$(echo "$__fna" | sed "$__sed")"
49 # Only rename if the name has changed
50 if [ -n "$__tra" ] && [ "$__tra" != "$__fna" ]
51 then
52 # Source and destination
53 __src="$__dir/$__fna"
54 __dst="$__dir/$__tra"
56 # Perform the move
57 if fossil mv "$__src" "$__dst"
58 then
59 mv -v "$__src" "$__dst"
62 done