Refactored utility basename and extension utilities
Minor cleanup to the method names used for less typing.
This commit is contained in:
@@ -136,7 +136,7 @@ export -f install_program
|
|||||||
# Parameters: $1 (required) - Repository URL, $2 (required) - Install path, $3 (optional) - Git clone options.
|
# Parameters: $1 (required) - Repository URL, $2 (required) - Install path, $3 (optional) - Git clone options.
|
||||||
install_git_app() {
|
install_git_app() {
|
||||||
local repository_url="$1"
|
local repository_url="$1"
|
||||||
local app_name=$(get_file_name "$2")
|
local app_name=$(get_basename "$2")
|
||||||
local install_path="$2"
|
local install_path="$2"
|
||||||
local options="--quiet"
|
local options="--quiet"
|
||||||
|
|
||||||
@@ -175,7 +175,7 @@ export -f install_git_project
|
|||||||
# Parameters: $1 (required) - URL, $2 (required) - Install path.
|
# Parameters: $1 (required) - URL, $2 (required) - Install path.
|
||||||
install_file() {
|
install_file() {
|
||||||
local file_url="$1"
|
local file_url="$1"
|
||||||
local file_name=$(get_file_name "$1")
|
local file_name=$(get_basename "$1")
|
||||||
local install_path="$2"
|
local install_path="$2"
|
||||||
|
|
||||||
if [[ ! -e "$install_path" ]]; then
|
if [[ ! -e "$install_path" ]]; then
|
||||||
@@ -206,7 +206,7 @@ export -f download_file
|
|||||||
# Parameters: $1 (required) - Application source path, $2 (required) - Application name.
|
# Parameters: $1 (required) - Application source path, $2 (required) - Application name.
|
||||||
install_app() {
|
install_app() {
|
||||||
local install_root=$(get_install_root "$2")
|
local install_root=$(get_install_root "$2")
|
||||||
local file_extension=$(get_file_extension "$2")
|
local file_extension=$(get_extension "$2")
|
||||||
|
|
||||||
printf "Installing: $install_root/$2...\n"
|
printf "Installing: $install_root/$2...\n"
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,19 @@
|
|||||||
|
|
||||||
# Defines general utility functions.
|
# Defines general utility functions.
|
||||||
|
|
||||||
|
# Caffeinate machine.
|
||||||
|
caffeinate_machine() {
|
||||||
|
local pid=$(pgrep -x caffeinate)
|
||||||
|
|
||||||
|
if [[ -n "$pid" ]]; then
|
||||||
|
printf "Machine is already caffeinated!\n"
|
||||||
|
else
|
||||||
|
caffeinate -s -u -d -i -t 3153600000 > /dev/null &
|
||||||
|
printf "Machine caffeinated.\n"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
export -f caffeinate_machine
|
||||||
|
|
||||||
# Answers the full install path (including file name) for file name.
|
# Answers the full install path (including file name) for file name.
|
||||||
# Parameters: $1 (required) - The file name.
|
# Parameters: $1 (required) - The file name.
|
||||||
get_install_path() {
|
get_install_path() {
|
||||||
@@ -17,24 +30,11 @@ clean_work_path() {
|
|||||||
}
|
}
|
||||||
export -f clean_work_path
|
export -f clean_work_path
|
||||||
|
|
||||||
# Caffeinate machine.
|
|
||||||
caffeinate_machine() {
|
|
||||||
local pid=$(pgrep -x caffeinate)
|
|
||||||
|
|
||||||
if [[ -n "$pid" ]]; then
|
|
||||||
printf "Whoa, tweaker, machine is already caffeinated!\n"
|
|
||||||
else
|
|
||||||
caffeinate -s -u -d -i -t 3153600000 > /dev/null &
|
|
||||||
printf "Machine caffeinated.\n"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
export -f caffeinate_machine
|
|
||||||
|
|
||||||
# Answers the root install path for file name.
|
# Answers the root install path for file name.
|
||||||
# Parameters: $1 (required) - The file name.
|
# Parameters: $1 (required) - The file name.
|
||||||
get_install_root() {
|
get_install_root() {
|
||||||
local file_name="$1"
|
local file_name="$1"
|
||||||
local file_extension=$(get_file_extension "$file_name")
|
local file_extension=$(get_extension "$file_name")
|
||||||
|
|
||||||
# Dynamically build the install path based on file extension.
|
# Dynamically build the install path based on file extension.
|
||||||
case $file_extension in
|
case $file_extension in
|
||||||
@@ -52,10 +52,17 @@ get_install_root() {
|
|||||||
}
|
}
|
||||||
export -f get_install_root
|
export -f get_install_root
|
||||||
|
|
||||||
|
# Answers the file or directory basename.
|
||||||
|
# Parameters: $1 (required) - The file path.
|
||||||
|
get_basename() {
|
||||||
|
printf "${1##*/}" # Answers file or directory name.
|
||||||
|
}
|
||||||
|
export -f get_basename
|
||||||
|
|
||||||
# Answers the file extension.
|
# Answers the file extension.
|
||||||
# Parameters: $1 (required) - The file name.
|
# Parameters: $1 (required) - The file name.
|
||||||
get_file_extension() {
|
get_extension() {
|
||||||
local name=$(get_file_name "$1")
|
local name=$(get_basename "$1")
|
||||||
local extension="${1##*.}" # Excludes dot.
|
local extension="${1##*.}" # Excludes dot.
|
||||||
|
|
||||||
if [[ "$name" == "$extension" ]]; then
|
if [[ "$name" == "$extension" ]]; then
|
||||||
@@ -64,11 +71,4 @@ get_file_extension() {
|
|||||||
printf "$extension"
|
printf "$extension"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
export -f get_file_extension
|
export -f get_extension
|
||||||
|
|
||||||
# Answers the file name.
|
|
||||||
# Parameters: $1 (required) - The file path.
|
|
||||||
get_file_name() {
|
|
||||||
printf "${1##*/}" # Answers file or directory name.
|
|
||||||
}
|
|
||||||
export -f get_file_name
|
|
||||||
|
|||||||
Reference in New Issue
Block a user