feat(): introduce 'bpkg-realpath'

pull/152/head
Joseph Werle 2 years ago
parent 80e3da855e
commit 1588f1edd3

@ -0,0 +1 @@
lib/realpath/realpath.sh

11
lib/env/env.sh vendored

@ -9,6 +9,15 @@ else
source "$(which bpkg-package)"
fi
if ! type -f bpkg-realpath &>/dev/null; then
echo "error: bpkg-realpath not found, aborting"
exit 1
else
# shellcheck disable=SC2230
# shellcheck source=lib/realpath/realpath.sh
source "$(which bpkg-realpath)"
fi
# Include config rc file if found
BPKG_USER_CONFIG_FILE="$HOME/.bpkgrc"
@ -37,7 +46,7 @@ export BPKG_PACKAGE_USER
export BPKG_PACKAGE_NAME="$(bpkg_package name 2>/dev/null)"
export BPKG_PACKAGE_REPO="$(bpkg_package repo 2>/dev/null)"
export BPKG_PACKAGE_PATH="$(bpkg_package_path)"
export BPKG_PACKAGE_ROOT="$(realpath "$(dirname "$BPKG_PACKAGE_PATH")")"
export BPKG_PACKAGE_ROOT="$(bpkg_realpath "$(dirname "$BPKG_PACKAGE_PATH")")"
export BPKG_PACKAGE_DEPS="$BPKG_PACKAGE_ROOT/deps"
export BPKG_PACKAGE_VERSION="$(bpkg_package version 2>/dev/null)"
export BPKG_PACKAGE_DESCRIPTION="$(bpkg_package description 2>/dev/null)"

@ -1,5 +1,14 @@
#!/usr/bin/env bash
if ! type -f bpkg-realpath &>/dev/null; then
echo "error: bpkg-realpath not found, aborting"
exit 1
else
# shellcheck disable=SC2230
# shellcheck source=lib/realpath/realpath.sh
source "$(which bpkg-realpath)"
fi
if ! type -f bpkg-utils &>/dev/null; then
echo "error: bpkg-utils not found, aborting"
exit 1
@ -211,7 +220,7 @@ bpkg_install () {
echo
for pkg in "${pkgs[@]}"; do
if test -d "$(realpath "$pkg" 2>/dev/null)"; then
if test -d "$(bpkg_realpath "$pkg" 2>/dev/null)"; then
if ! (cd "$pkg" && bpkg_getdeps); then
return 1
fi

@ -1,11 +1,20 @@
#!/usr/bin/env bash
if ! type -f bpkg-realpath &>/dev/null; then
echo "error: bpkg-realpath not found, aborting"
exit 1
else
# shellcheck disable=SC2230
# shellcheck source=lib/realpath/realpath.sh
source "$(which bpkg-realpath)"
fi
BPKG_JSON="$(which bpkg-json)"
if [ -z "$BPKG_JSON" ]; then
BPKG_JSON="$(realpath "$0/../JSON/JSON.sh")"
BPKG_JSON="$(bpkg_realpath "$0/../JSON/JSON.sh")"
else
BPKG_JSON="$(realpath "$BPKG_JSON")"
BPKG_JSON="$(bpkg_realpath "$BPKG_JSON")"
fi
## output usage

@ -0,0 +1,34 @@
#!/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

@ -1,5 +1,14 @@
#!/usr/bin/env bash
if ! type -f bpkg-realpath &>/dev/null; then
echo "error: bpkg-realpath not found, aborting"
exit 1
else
# shellcheck disable=SC2230
# shellcheck source=lib/realpath/realpath.sh
source "$(which bpkg-realpath)"
fi
if ! type -f bpkg-utils &>/dev/null; then
echo "error: bpkg-utils not found, aborting"
exit 1
@ -172,7 +181,7 @@ bpkg_run () {
if which "$name" 2>/dev/null; then
:
elif test -f "$1"; then
realpath "$1"
bpkg_realpath "$1"
elif [ -n "$1" ] && which "$1" 2>/dev/null; then
:
fi

@ -89,6 +89,7 @@ CMDS+=("suggest")
CMDS+=("term")
CMDS+=("update")
CMDS+=("utils")
CMDS+=("realpath")
make_install () {
local source

Loading…
Cancel
Save