9b201c5cfb240fb5eaf5c0fa4d6f9ab2e55cf3bc
[feisty_meow.git] / scripts / files / spacem.sh
1 #!/bin/bash
2
3 function spacem_out()
4 {
5   while [ $# -gt 0 ]; do
6     arg="$1"; shift
7 echo "arg is '$arg'"
8     if [ ! -f "$arg" -a ! -d "$arg" ]; then
9       echo "=> did not find a file or directory named '$arg'."
10       continue
11     fi
12
13     # we capture the output of the character replacement operation for reporting.
14     # this is done first since some filenames cannot be properly renamed in perl (e.g. if they
15     # have pipe characters apparently).
16     intermediate_name="$(bash "$FEISTY_MEOW_SCRIPTS/files/replace_spaces_with_underscores.sh" "$arg")"
17     local saw_intermediate_result=0
18     if [ -z "$intermediate_name" ]; then
19 echo no new intermed name reported
20       # make sure we report something, if there are no further name changes.
21       intermediate_name="'$arg'"
22     else 
23       # now zap the first part of the name off (since original name is not needed).
24       intermediate_name="$(echo $intermediate_name | sed -e 's/.*=> //')"
25       saw_intermediate_result=1
26     fi
27
28     # here we rename the file to be lower case.
29     actual_file="$(echo $intermediate_name | sed -e "s/'\([^']*\)'/\1/")"
30 echo actual file computed: $actual_file
31     final_name="$(perl "$FEISTY_MEOW_SCRIPTS/files/renlower.pl" "$actual_file")"
32     local saw_final_result=0
33 echo temp final name is: $final_name
34     if [ -z "$final_name" ]; then
35       final_name="$intermediate_name"
36     else
37       final_name="$(echo $final_name | sed -e 's/.*=> //' )"
38       saw_final_result=1
39     fi
40 echo intermed result=$saw_intermediate_result 
41 echo intermed name=$intermediate_name
42 echo final result=$saw_final_result 
43 echo final name=$final_name
44
45     if [[ $saw_intermediate_result != 0 || $saw_final_result != 0 ]]; then
46       # printout the combined operation results.
47       echo "'$arg' => $final_name"
48     fi
49   done
50 }
51
52 # this block should execute when the script is actually run, rather
53 # than when it is just being sourced.
54 if [[ $0 =~ .*spacem\.sh.* ]]; then
55 echo inside exec block for spacem
56   source "$FEISTY_MEOW_SCRIPTS/core/launch_feisty_meow.sh"
57   exit_on_error "sourcing the feisty meow environment"
58   spacem_out "${@}"
59   exit_on_error "running spacem_out on a list: ${@}"
60 fi
61