mirror of
https://github.com/ivuorinen/dotfiles.git
synced 2026-02-23 07:56:27 +00:00
feat!: refactor base, config, dfm and scripts
This commit is contained in:
@@ -3,4 +3,50 @@
|
||||
# Add a directory to the front of the PATH if it exists and is not already there
|
||||
# Usage: x-path-prepend <dir>
|
||||
|
||||
export PATH="$1${PATH:+":$PATH"}"
|
||||
# Set verbosity with VERBOSE=1
|
||||
VERBOSE="${VERBOSE:-0}"
|
||||
|
||||
# Function to print usage information
|
||||
usage()
|
||||
{
|
||||
echo "Usage: $0 <dir>"
|
||||
exit 1
|
||||
}
|
||||
|
||||
# Function to print messages if VERBOSE is enabled
|
||||
# $1 - message (string)
|
||||
msg()
|
||||
{
|
||||
[[ "$VERBOSE" -eq 1 ]] && echo "$1"
|
||||
}
|
||||
|
||||
# Function to add a directory to the front of PATH
|
||||
# $1 - directory to add (string)
|
||||
prepend_to_path()
|
||||
{
|
||||
local dir=$1
|
||||
|
||||
if [ ! -d "$dir" ]; then
|
||||
msg "(?) Directory $dir does not exist"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if echo "$PATH" | grep -qE "(^|:)$dir($|:)"; then
|
||||
msg "(!) Directory $dir is already in PATH"
|
||||
else
|
||||
export PATH="$dir${PATH:+":$PATH"}"
|
||||
msg "(!) Directory $dir has been added to the front of PATH"
|
||||
fi
|
||||
}
|
||||
|
||||
# Main function
|
||||
main()
|
||||
{
|
||||
if [ "$#" -ne 1 ]; then
|
||||
usage
|
||||
fi
|
||||
|
||||
prepend_to_path "$1"
|
||||
}
|
||||
|
||||
main "$@"
|
||||
|
||||
Reference in New Issue
Block a user