38 lines
806 B
Text
38 lines
806 B
Text
# Eryn Wells <eryn@erynwells.me>
|
|
|
|
prepend_to_path() {
|
|
local should_export_path=1
|
|
local should_be_verbose=0
|
|
|
|
while getopts "ve" opt; do
|
|
case $opt in
|
|
"e") should_export_path=1;;
|
|
"+e") should_export_path=0;;
|
|
"v") should_be_verbose=1;;
|
|
*) ;;
|
|
esac
|
|
done
|
|
|
|
local result=1
|
|
local path_to_add=$@[$OPTIND]
|
|
|
|
if [[ -d "$path_to_add" ]]; then
|
|
if (( $should_be_verbose )); then
|
|
echo "Prepending $path_to_add to \$path"
|
|
fi
|
|
path=("$path_to_add" $path)
|
|
else
|
|
if (( $should_be_verbose )); then
|
|
echo "$path_to_add doesn't exist"
|
|
fi
|
|
result=0
|
|
fi
|
|
|
|
if (( $should_export_path )); then
|
|
export path
|
|
fi
|
|
|
|
return $result
|
|
}
|
|
|
|
prepend_to_path "$@"
|