mirror of https://github.com/bpkg/bpkg
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
35 lines
587 B
Bash
35 lines
587 B
Bash
#!/usr/bin/env bash
|
|
|
|
function bpkg_realpath () {
|
|
local target="$1"
|
|
|
|
if [ -n "$(which realpath 2>/dev/null)" ]; then
|
|
realpath "$@"
|
|
return $?
|
|
fi
|
|
|
|
if test -d "$target"; then
|
|
cd "$target" || return $?
|
|
pwd
|
|
elif test -f "$target"; then
|
|
# file
|
|
if [[ $target = /* ]]; then
|
|
echo "$target"
|
|
elif [[ $target == */* ]]; then
|
|
cd "${1%/*}" || return $?
|
|
echo "$(pwd)/${1##*/}"
|
|
else
|
|
echo "$(pwd)/$target"
|
|
fi
|
|
fi
|
|
|
|
return 0
|
|
}
|
|
|
|
if [[ ${BASH_SOURCE[0]} != "$0" ]]; then
|
|
export -f bpkg_realpath
|
|
else
|
|
bpkg_realpath "$@"
|
|
exit $?
|
|
fi
|