Skip to content
Snippets Groups Projects
Commit 49a7f3ae authored by Brandon Rodriguez's avatar Brandon Rodriguez
Browse files

Add normalize function

parent b8504904
Branches
No related merge requests found
...@@ -34,6 +34,7 @@ Various references used in project. ...@@ -34,6 +34,7 @@ Various references used in project.
#### Getting Directory of Calling Script #### Getting Directory of Calling Script
<https://stackoverflow.com/a/59916> <https://stackoverflow.com/a/59916>
<https://stackoverflow.com/a/246128>
#### Get Absolute Directory #### Get Absolute Directory
<https://stackoverflow.com/a/21188136> <https://stackoverflow.com/a/21188136>
......
...@@ -20,6 +20,12 @@ For example, if both `utils.sh` and the calling script are in the same directory ...@@ -20,6 +20,12 @@ For example, if both `utils.sh` and the calling script are in the same directory
At this point, you should have full functionality of the `utils.sh` file. At this point, you should have full functionality of the `utils.sh` file.
### Terminal Current Directory
On importing this script, it will automatically change the terminal to the location of the script's directory. This is
to keep relative path handling the same, regardless of calling location.
Terminal location resets on script end.
## References ## References
See `documents/references.md`. See `documents/references.md`.
...@@ -29,6 +29,20 @@ return_value="" ...@@ -29,6 +29,20 @@ return_value=""
#region Directory Functions #region Directory Functions
###
# Normalizes the location of the terminal to directory of utils.sh file.
#
# The point is so that the execution of a script will handle the same, regardless of terminal directory location at
# script start. Ex: User can start script at either their home folder, or project root, (or any other directory) and
# relative directory handling will still function the same in either case.
#
# Automatically called on script import.
##
function normalize_terminal () {
cd "$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
}
### ###
# Gets absolute path of passed location. # Gets absolute path of passed location.
## ##
...@@ -242,3 +256,7 @@ function display_text_colors () { ...@@ -242,3 +256,7 @@ function display_text_colors () {
echo -e " ${text_white}White${text_reset}" echo -e " ${text_white}White${text_reset}"
echo "" echo ""
} }
# Functions to call on script import.
normalize_terminal
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment