+ echo "bash $FEISTY_MEOW_SCRIPTS/generator/produce_feisty_meow.sh"
+ echo
+ else
+ $wheres_nechung
+ fi
+ }
+
+ # recreates all the generated files that the feisty meow scripts use.
+ function regenerate() {
+ # do the bootstrapping process again.
+ save_terminal_title
+ echo "regenerating feisty meow script environment."
+ bash $FEISTY_MEOW_SCRIPTS/core/reconfigure_feisty_meow.sh
+ echo
+ # force a full reload by turning off sentinel variables and methods.
+ unset -v CORE_VARIABLES_LOADED FEISTY_MEOW_LOADING_DOCK USER_CUSTOMIZATIONS_LOADED
+ unalias CORE_ALIASES_LOADED &>/dev/null
+ unset -f function_sentinel
+ # reload feisty meow environment in current shell.
+ log_feisty_meow_event "reloading the feisty meow scripts for $USER in current shell."
+ source "$FEISTY_MEOW_SCRIPTS/core/launch_feisty_meow.sh"
+ # run nechung oracle to give user a new fortune.
+ nechung
+ restore_terminal_title
+ }
+
+ # merges a set of custom scripts into the feisty meow environment. can be
+ # passed a name to use as the custom scripts source folder (found on path
+ # $FEISTY_MEOW_SCRIPTS/customize/{name}), or it will try to guess the name
+ # by using the login name.
+ function recustomize()
+ {
+ local custom_user="$1"; shift
+ if [ -z "$custom_user" ]; then
+ # default to login name if there was no name provided.
+ custom_user="$(fm_username)"
+ # we do intend to use the login name here to get the login name and to ignore
+ # if the user has sudo root access; we don't want to provide a custom
+ # profile for root.
+ fi
+ # chop off any email address style formatting to leave just the name.
+ custom_user="$(echo "$custom_user" | cut -f1 -d'@')"
+
+ save_terminal_title
+
+ if [ ! -d "$FEISTY_MEOW_SCRIPTS/customize/$custom_user" ]; then
+ echo -e "the customization folder for '$custom_user' is missing:
+
+ $FEISTY_MEOW_SCRIPTS/customize/$custom_user
+
+we will skip recustomization, but these other customizations are available:
+"
+ # a little tr and sed magic to fix the carriage returns into commas.
+ local line="$(find $FEISTY_MEOW_SCRIPTS/customize -mindepth 1 -maxdepth 1 -type d -exec basename {} ';' | tr '\n' '&' | sed 's/&/, /g' | sed -e 's/, $//')"
+ # make the line feeds and carriage returns manageable with tr.
+ # convert the ampersand, our weird replacement for EOL, with a comma + space in sed.
+ # last touch with sed removes the last comma.
+ echo " $line"
+ return 1
+ fi
+
+ # recreate the feisty meow loading dock.
+ regenerate >/dev/null
+
+ # jump into the loading dock and make our custom link.
+ pushd "$FEISTY_MEOW_LOADING_DOCK" &>/dev/null
+ if [ -h custom ]; then
+ # there's an existing link, so remove it.
+ \rm custom
+ fi
+ # make sure we cleaned up the area before we re-link.
+ if [ -h custom -o -d custom -o -f custom ]; then
+ echo "
+Due to an over-abundance of caution, we are not going to remove an unexpected
+'custom' object found in the file system. This object is located in the
+feisty meow loading dock here: $(pwd)
+And here is a description of the rogue 'custom' object:
+"
+ ls -al custom
+ echo "
+If you are pretty sure that this is just a remnant of an older approach in
+feisty meow, where we copied the custom directory rather than linking it
+(and it most likely is just such a bit of cruft of that nature), then please
+remove that old remnant 'custom' item, for example by saying:
+ /bin/rm -rf \"custom\" ; popd
+Sorry for the interruption, but we want to make sure this removal wasn't
+automatic if there is even a small amount of doubt about the issue."
+ return 1
+ fi
+
+ # create the custom folder as a link to the customizations.
+ ln -s "$FEISTY_MEOW_SCRIPTS/customize/$custom_user" custom
+
+ popd &>/dev/null
+
+ # now take into account all the customizations by regenerating the feisty meow environment.
+ regenerate
+
+ restore_terminal_title
+ }
+
+ # generates a random password where the first parameter is the number of characters
+ # in the password (default 20) and the second parameter specifies whether to use
+ # special characters (1) or not (0).
+ # found function at http://legroom.net/2010/05/06/bash-random-password-generator
+ function random_password()
+ {
+ [ "$2" == "0" ] && CHAR="[:alnum:]" || CHAR="[:graph:]"
+ cat /dev/urandom | tr -cd "$CHAR" | head -c ${1:-32}
+ echo
+ }
+
+ # a wrapper for the which command that finds items on the path. some OSes
+ # do not provide which, so we want to not be spewing errors when that
+ # happens.
+ function whichable()
+ {
+ to_find="$1"; shift
+ which which &>/dev/null
+ if [ $? -ne 0 ]; then
+ # there is no which command here. we produce nothing due to this.
+ echo
+ fi
+ echo $(which $to_find)
+ }
+
+ function add_cygwin_drive_mounts() {
+ for i in c d e f g h q z ; do
+#hmmm: improve this by not adding the link if already there, or if the drive is not valid.
+ 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.
+ function replace_pattern_in_file()
+ {
+ local file="$1"; shift
+ local pattern="$1"; shift
+ local replacement="$1"; shift
+ if [ -z "$file" -o -z "$pattern" -o -z "$replacement" ]; then
+ echo "replace_pattern_in_file: needs a filename, a pattern to replace, and the"
+ echo "text to replace that pattern with."
+ return 1
+ fi
+ sed -i -e "s%$pattern%$replacement%g" "$file"
+ }
+
+ # similar to replace_pattern_in_file, but also will add the new value
+ # when the old one did not already exist in the file.
+ function replace_if_exists_or_add()
+ {
+ local file="$1"; shift
+ local phrase="$1"; shift
+ local replacement="$1"; shift
+ if [ -z "$file" -o ! -f "$file" -o -z "$phrase" -o -z "$replacement" ]; then
+ echo "replace_if_exists_or_add: needs a filename, a phrase to replace, and the"
+ echo "text to replace that phrase with."
+ return 1
+ fi
+ grep "$phrase" "$file" >/dev/null
+ # replace if the phrase is there, otherwise add it.
+ if [ $? -eq 0 ]; then
+ replace_pattern_in_file "$file" "$phrase" "$replacement"