Skip to content

Commit

Permalink
Use "builtin type" to locate "mcfly"
Browse files Browse the repository at this point in the history
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] cantino#216
[2] cantino#292
[3] cantino#430 (comment)
  • Loading branch information
akinomyoga committed Jul 21, 2024
1 parent 6ff499f commit 0c0e0b5
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions mcfly.bash
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0c0e0b5

Please sign in to comment.