aecf3b085886017e3182a44482f3c4aad95ec28b
[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     # first we will 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       # make sure we report something, if there are no further name changes.
20       intermediate_name="'$arg'"
21     else 
22       # now zap the first part of the name off (since original name is not needed).
23       intermediate_name="$(echo "$intermediate_name" | sed -e 's/.*=> //')"
24       saw_intermediate_result=1
25     fi
26
27     # first we rename the file to be lower case.
28     actual_file="$(echo "$intermediate_name" | sed -e "s/\'\([^']*\)\'/\1/")"
29     final_name="$(perl "$FEISTY_MEOW_SCRIPTS/files/renlower.pl" "$actual_file")"
30     local saw_final_result=0
31     if [ -z "$final_name" ]; then
32       final_name="$intermediate_name"
33     else
34       final_name="$(echo "$final_name" | sed -e 's/.*=> //' )"
35       saw_final_result=1
36     fi
37 #echo intermed=$saw_intermediate_result 
38 #echo final=$saw_final_result 
39
40     if [[ $saw_intermediate_result != 0 || $saw_final_result != 0 ]]; then
41       # printout the combined operation results.
42       echo "'$arg' => $final_name"
43     fi
44   done
45 }
46
47 # this block should execute when the script is actually run, rather
48 # than when it is just being sourced.
49 if [[ $0 =~ .*spacem\.sh.* ]]; then
50   source "$FEISTY_MEOW_SCRIPTS/core/launch_feisty_meow.sh"
51   exit_on_error "sourcing the feisty meow environment"
52   spacem_out "${@}"
53   exit_on_error "running spacem_out on a list: $*"
54 fi
55