-
-
Save florido/95ab5c1ff71f4278e3a8f715b5c23078 to your computer and use it in GitHub Desktop.
/usr/libexec/path_helper
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# | |
# Each line of the text files in /etc/paths.d are directories that | |
# should be added to the current path. The text files are read in | |
# lexical order, and the default file is /etc/paths.d/50-default. | |
# We source /etc/paths.d/50-default first, so that the default paths | |
# (/usr/bin:/bin:/usr/sbin:/sbin) appear early in the path. | |
# | |
shopt -s extglob | |
function read_path_dir () { | |
DIR="$1" | |
NEWPATH="$2" | |
SEP="" | |
IFS=$'\n' | |
if [ -d "$DIR" ]; then | |
for f in "$DIR"/* ; do | |
if [ -f "$f" ]; then | |
for p in $(< "$f") ; do | |
[[ "$NEWPATH" = *(*:)${p}*(:*) ]] && continue | |
[ ! -z "$NEWPATH" ] && SEP=":" | |
NEWPATH="${NEWPATH}${SEP}${p}" | |
done | |
fi | |
done | |
fi | |
echo $NEWPATH | |
} | |
P=`read_path_dir /etc/paths.d` | |
MP=`read_path_dir /etc/manpaths.d` | |
if [ "$1" == "-c" -o \( -z "$1" -a "${SHELL%csh}" != "$SHELL" \) ]; then | |
echo setenv PATH \"$P\"\; | |
echo setenv MANPATH \"$MP\"\; | |
exit 0 | |
elif [ "$1" == "-s" -o -z "$1" ]; then | |
echo PATH=\"$P\"\; export PATH; | |
echo MANPATH=\"$MP\"\; export MANPATH; | |
exit 0 | |
else | |
echo "usage: path_helper [-c | -s]" 1>&2 | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment