Skip to content

Instantly share code, notes, and snippets.

@hydra35
Created January 7, 2012 04:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hydra35/1573775 to your computer and use it in GitHub Desktop.
Save hydra35/1573775 to your computer and use it in GitHub Desktop.
archlinux's basedir aware `which`
pathlookup() {
# a basedir aware 'type -P' (or which) for executables
# $1: binary to find
local path=
local -a paths=
IFS=: read -r -a paths <<< "$PATH"
for path in "${paths[@]}"; do
[[ ${path:0:1} = [.~] ]] && continue
if [[ -x $BASEDIR$path/$1 ]]; then
printf '%s' "$BASEDIR$path/$1"
return 0
fi
done
return 1
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment