From 0c0e0b52c72f47be01dad327dcd404d67d50bcdb Mon Sep 17 00:00:00 2001 From: Koichi Murase Date: Mon, 22 Jul 2024 07:20:42 +0900 Subject: [PATCH] Use "builtin type" to locate "mcfly" The command "which" is a non-POSIX external command, and technically, its existence in the system is not ensured. We here use Bash's built-in command "type", which is the most reliable. We prefix "builtin" to "type" because some users overwrite "type" with a shell function or an alias to mimic Windows' "type" command. The use of the which command was first removed in Ref. [1]. However, this was reverted after the issue in Ref. [2]. As far as a relative path is not contained in PATH, the problem reported in Ref. [2] does not seem to be reproducible in all the versions from Bash 3.0 to 5.2 and in the devel branch of Bash. However, when the path "./bin" is included in PATH, the "command -v" produces the relative path "./bin/mcfly" as reported. This seems to have been solved by using the "which command in the reporter's environment, but the behavior of the "which" command may depend on the implementation. We should explicitly resolve the relative path if the obtained MCFLY_PATH is relative. References: [1] https://github.com/cantino/mcfly/pull/216 [2] https://github.com/cantino/mcfly/issues/292 [3] https://github.com/cantino/mcfly/pull/430#discussion_r1685817139 --- mcfly.bash | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/mcfly.bash b/mcfly.bash index 0240f78..d015835 100644 --- a/mcfly.bash +++ b/mcfly.bash @@ -28,6 +28,11 @@ function mcfly_initialize { # Find the binary MCFLY_PATH=${MCFLY_PATH:-$(builtin type -P mcfly)} + if [[ $MCFLY_PATH != /* ]]; then + # When the user include a relative path in PATH, "builtin type -P" may + # produce a relative path. We convert relative paths to the absolute ones. + MCFLY_PATH=$PWD/$MCFLY_PATH + fi if [[ -z $MCFLY_PATH ]]; then echo "Cannot find the mcfly binary, please make sure that mcfly is in your path before sourcing mcfly.bash." return 1