regenerate
}
+#uhhh, this does what now?
function add_cygwin_drive_mounts() {
for i in c d e f g h q z ; do
ln -s /cygdrive/$i $i
done
}
-
# takes a file to modify, and then it will replace any occurrences of the
# pattern provided as the second parameter with the text in the third
# parameter.
sed -i -e "s%$pattern%$replacement%g" "$file"
}
+ function spacem()
+ {
+#hmmm: could really use that pattern of 'iterate across all the arguments and do same thing' here.
+
+#hmmm: it actually seems like the below IS the pattern. it's pretty short, but i wish it could be shorter, like a function in itself.... ah.
+# couldn't we have a functionator deal that takes:
+# 1) a command to run, and
+# 2-n) arguments,
+# where the function just blithely runs that command on all of those arguments!?
+# yes! that does seem like the pattern being sought, much nicer than the goofy loop below,
+# although this functionator deal needs to handle when there are more than one command also,
+# or this very function couldn't be implemented...
+# maybe a two step process:
+# 1) build a list of commands to run on all arguments,
+# 2) then run through all the arguments passed in using those established commands.
+# yes again! this seems like it would meet all the needs involved and not be too irksome.
+# for the example below, this would reduce the number of lines, i think.
+# i had better stop bloviating and write this function so i can determine the number of
+# lines omitted by the new approach.
+ while [ $# -gt 0 ]; do
+ arg="$1"; shift
+ # first we rename the file to be lower case.
+ perl $FEISTY_MEOW_SCRIPTS/files/renlower.pl "$arg" &>/dev/null
+ # oops, now the name is all lower-case. we need to make the
+ # same adjustment.
+ arg2="$(echo "$arg" | tr A-Z a-z)"
+ # we definitely wanted to adjust the case first, rather than doing all
+ # the wacky stuff this script does to the filename... we will capture
+ # the output of the replace operaton for reporting.
+ final_name="$(perl "$FEISTY_MEOW_SCRIPTS/files/replace_spaces_with_underscores.sh" "$arg2")"
+ # now zap the intermediate part of the name off.
+ final_name="$(echo \"$final_name\" | sed -e 's/.*=> //')"
+ # printout the combined operation results.
+ echo "'$arg' => $final_name"
+ done
+#
+ }
+
##############
function function_sentinel() { return 0; }
--- /dev/null
+#!/bin/bash
+
+function print_instructions()
+{
+ echo -e "\n$(basename $0 .sh):\n"
+ echo -e 'this script takes two parameters, a "here" folder and a "there" folder, almost as if it were a copy command. but instead, this removes any file from under the "here" location if it cannot be found in the "there" location. so the "there" location is considered a more definitive template of what should be in "here", such that we strip out what "there" does not have.\n\n
+the most" useful way to use this script is for a "here" hierarchy that is a copy of an older version of another "there" hierarchy. the "there" hierarchy may have changed a lot, including new files, changed files, and deleted files. it is a simple operation to copy everything from "there" into "here" (such as by using the command [ cp -R "$there"/* "$here" ] ) , but it is a lot harder to determine what stuff in "here" is out of date and should be removed. that is where this script comes in; it can be run to flush out any older things in "here", rather than requiring the user to manually find all those files. ' | splitter
+ echo
+ echo "Example Usage:"
+ echo
+ echo "$(basename $0 .sh) backup_copy original_folder"
+ echo
+ echo " ==> Deletes any files in backup_copy that are not found in original_folder."
+ echo
+}
+
+if [ $# -lt 2 ]; then
+ print_instructions
+ echo "There were not enough parameters provided to the script."
+ exit 1
+fi
+
+here="$1"; shift
+there="$1"; shift
+
+if [ ! -d "$there" -o ! -d "$here" ]; then
+ print_instructions
+ echo "One of the directories specified does not exist."
+ exit 1
+fi
+
+here_temp_file="$(mktemp "$TMP/remover_list.XXXXXX")"
+there_temp_file="$(mktemp "$TMP/remover_list.XXXXXX")"
+
+# find all the files in both hierarchies.
+pushd "$here" &>/dev/null
+find "." -type f | sort >"$here_temp_file"
+popd &>/dev/null
+pushd "$there" &>/dev/null
+find "." -type f | sort >"$there_temp_file"
+popd &>/dev/null
+
+whack_list="$(mktemp "$TMP/remover_list.XXXXXX")"
+
+comm -23 "$here_temp_file" "$there_temp_file" >"$whack_list"
+
+while read line; do
+ if [ -z "$line" ]; then break; fi
+ herename="$here/$line"
+ rm -v "$herename"
+done <"$whack_list"
+
+# clean up.
+rm "$whack_list" "$here_temp_file" "$there_temp_file"
+
|| die "failed to do initial rename";
rename($intermediate_name, $new_name)
|| die "failed to do secondary rename";
+ print "'$old_name' => '$new_name'\n";
}
}
}
--- /dev/null
+#!/bin/bash
+
+# takes names given to it and replaces any spaces or other gnarly characters with underscores.
+
+#hmmm: this starts to look like a useful function that the bracket fixer could also use.
+
+if [ $# -lt 1 ]; then
+ echo "This script requires one or more file names whose names should be fixed."
+ echo "Any spaces or single-quote characters will be stripped out in a useful way."
+ exit 1
+fi
+
+while [ $# -gt 0 ]; do
+ file="$1"; shift
+ newname="$(echo "$file" | tr -s ' ' '_' | tr -d "}{)(][\\\~',:?><\"" | sed -e 's/\([0-9]\)_\./\1./g' | sed -e 's/_-_/-/' )"
+ if [ "$file" != "$newname" ]; then
+ # we've effected a name change, so let's actually do it.
+ echo "'$file' => '$newname'"
+ mv "$file" "$newname"
+ fi
+done
+
# reset the list of objects actually whacked.
local(@deleted) = ();
-# print "deleted list is @deleted\n";
# iterate over the files that we have been told to nuke.
foreach $file (@to_delete) {
$date_tool = "date";
local($datestamp) = `$date_tool +%Y-%m-%d-%H%M`;
while ($datestamp =~ /[\r\n]$/) { chop $datestamp; }
- $archive_file = $temp_subdir . "/deleted-#$number-" . $datestamp;
+ $archive_file = $temp_subdir . "/del-$number-" . $datestamp;
#print "archive_file is $archive_file; file is $file.\n";
if (-d $file) {
+++ /dev/null
-#!/bin/bash
-
-# takes names given to it and replaces any spaces or other gnarly characters with underscores.
-
-#hmmm: this starts to look like a useful function that the bracket fixer could also use.
-
-if [ $# -lt 1 ]; then
- echo "This script requires one or more file names whose names should be fixed."
- echo "Any spaces or single-quote characters will be stripped out in a useful way."
- exit 1
-fi
-
-while [ $# -gt 0 ]; do
- file="$1"; shift
- newname="$(echo "$file" | tr -s ' ' '_' | tr -d "}{)(][\\\~',:?><\"" | sed -e 's/\([0-9]\)_\./\1./g' | sed -e 's/_-_/-/' )"
- if [ "$file" != "$newname" ]; then
- # we've effected a name change, so let's actually do it.
- echo "moving '$file' => '$newname' "
- mv "$file" "$newname"
- fi
-done
-