chore(bin): tweak x-path-* scripts

This commit is contained in:
2024-07-28 15:35:50 +03:00
parent 37299f4893
commit 3413365d41
3 changed files with 47 additions and 112 deletions

View File

@@ -6,13 +6,6 @@
# 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()
@@ -20,29 +13,17 @@ msg()
[[ "$VERBOSE" -eq 1 ]] && echo "$1"
}
# Function to remove a directory from PATH
# $1 - directory to remove (string)
remove_from_path()
{
local dir=$1
if [ "$#" -ne 1 ]; then
echo "Usage: $0 <dir>"
exit 1
fi
if ! echo "$PATH" | grep -qE "(^|:)$dir($|:)"; then
msg "(?) Directory $dir is not in PATH"
exit 0
fi
dir="$1"
export PATH=$(echo -n "$PATH" | awk -v RS=: -v ORS=: "\$0 != \"$dir\"" | sed 's/:$//')
msg "(!) Directory $dir has been removed from PATH"
}
if ! echo "$PATH" | grep -qE "(^|:)$dir($|:)"; then
msg "(?) Directory $dir is not in PATH"
exit 0
fi
# Main function
main()
{
if [ "$#" -ne 1 ]; then
usage
fi
remove_from_path "$1"
}
main "$@"
export PATH=$(echo -n "$PATH" | awk -v RS=: -v ORS=: "\$0 != \"$dir\"" | sed 's/:$//')
msg "(!) Directory $dir has been removed from PATH"