From: Chris Koeritz Date: Sat, 4 Nov 2017 22:50:16 +0000 (-0400) Subject: a couple new functions X-Git-Tag: 2.140.90~85 X-Git-Url: https://feistymeow.org/gitweb/?a=commitdiff_plain;h=5bbafe28063091112a788e76f79395d0142917b3;p=feisty_meow.git a couple new functions --- diff --git a/scripts/core/functions.sh b/scripts/core/functions.sh index 6f02ae26..fbdf0ac8 100644 --- a/scripts/core/functions.sh +++ b/scripts/core/functions.sh @@ -2,6 +2,10 @@ # This defines some general, useful functions. +#hmmm: starting to get a bit beefy in here. perhaps there is a good way to refactor the functions into more specific folders, if they aren't really totally general purpose? + +############## + # test whether we've been here before or not. skip_all= type function_sentinel &>/dev/null @@ -698,6 +702,41 @@ return 0 ############## + # count the number of sub-directories in a directory and echo the result. + function count_directories() + { + local appsdir="$1"; shift + numdirs="$(find "$appsdir" -mindepth 1 -maxdepth 1 -type d | wc -l)" + echo $numdirs + } + + # takes a string and capitalizes just the first character. any capital letters in the remainder of + # the string are made lower case. the processed string is returned by an echo. + function capitalize_first_char() + { + local to_dromedary="$1"; shift + to_dromedary="$(tr '[:lower:]' '[:upper:]' <<< ${to_dromedary:0:1})$(tr '[:upper:]' '[:lower:]' <<< ${to_dromedary:1})" + echo "$to_dromedary" + } + + # given a source path and a target path, this will make a symbolic link from + # the source to the destination, but only if the source actually exists. + function make_safe_link() + { + local src="$1"; shift + local target="$1"; shift + + if [ -d "$src" ]; then + ln -s "$src" "$target" + check_result "Creating symlink from '$src' to '$target'" + fi + echo "Created symlink from '$src' to '$target'." + } + + ############## + + # NOTE: no more function definitions are allowed after this point. + function function_sentinel() { return 0;