Skip to content

Instantly share code, notes, and snippets.

@hydra35
Created January 7, 2012 04:17
Show Gist options
  • 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