envkernel.sh: support sourcing from symlink (!1766)

Use readlink -f to resolve all symlinks in the envkernel.sh path.

Example:
$ ln -s ~/code/pmbootstrap/helpers/envkernel.sh ~/.local/bin
$ cd ~/code/linux
$ source ~/.local/bin/envkernel.sh

Please note that "source envkernel.sh" will only work with bash, as we
can use its ${BASH_SOURCE[0]} variable. For other shells, I would
recommend to set up an alias instead, e.g. for .zshrc:

alias envkernel="source ~/code/pmbootstrap/helpers/envkernel.sh"
This commit is contained in:
Oliver Smith 2019-03-09 21:20:25 +01:00
parent c3d0f421e1
commit 393e44c4cc
No known key found for this signature in database
GPG Key ID: 5AE7F5513E0885CB
1 changed files with 2 additions and 2 deletions

View File

@ -42,9 +42,9 @@ export_pmbootstrap_dir() {
# See also: <https://stackoverflow.com/a/29835459>
# shellcheck disable=SC2039
if [ -n "${BASH_SOURCE[0]}" ]; then
script_dir="$(dirname "${BASH_SOURCE[0]}")"
script_dir="$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")"
else
script_dir="$(dirname "$1")"
script_dir="$(dirname "$(readlink -f "$1")")"
fi
# Fail with debug information