fix using external realpath command

Fixes #3489
This commit is contained in:
Kurtis Rader 2016-11-13 13:34:19 -08:00
parent 5284a133b0
commit 209a2576cd

View file

@ -1,23 +1,27 @@
# Provide a minimalist realpath implementation to help deal with platforms that may not provide it # Provide a minimalist realpath implementation to help deal with platforms that may not provide it
# as a command. If a realpath command is available simply pass all arguments thru to it. If not # as a command. If an external realpath or grealpath command is available simply pass all arguments
# fallback to alternative solutions. # thru to it. If not fallback to our builtin.
# The following is slightly subtle. The first time `realpath` is invoked by autoloading this script # The following is slightly subtle. We have to define a realpath function even if there is an
# will be read. If we see that there is an external realpath command we just return. That will cause # external command by that name. That's because if we don't the parser will select our builtin.
# fish to run the external command. Or, if there is a grealpath, we alias it. # However, we only want our builtin if there is no external realpath command.
# On the other hand, if an external command isn't found we provide a function that will facilitate
# fallback behavion through our builtin.
if not command -s realpath >/dev/null if command -s realpath >/dev/null
# If there is a HomeBrew installed version of GNU realpath named grealpath use that. function realpath -w realpath -d "print the resolved path [command realpath]"
if command -s grealpath >/dev/null command realpath $argv
function realpath -w grealpath -d "print the resolved path [grealpath]"
grealpath $argv
end end
exit 0 exit 0
end end
function realpath -d "return an absolute path without symlinks" # If there is a HomeBrew installed version of GNU realpath named grealpath use that.
if command -s grealpath >/dev/null
function realpath -w grealpath -d "print the resolved path [command grealpath]"
command grealpath $argv
end
exit 0
end
function realpath -d "return an absolute path without symlinks"
if test -z "$argv" if test -z "$argv"
printf "usage: %s%s%s %sfile%s …\n" (set_color -o) $_ (set_color normal) (set_color -u) (set_color normal) printf "usage: %s%s%s %sfile%s …\n" (set_color -o) $_ (set_color normal) (set_color -u) (set_color normal)
echo " resolves files as absolute paths without symlinks" echo " resolves files as absolute paths without symlinks"
@ -46,5 +50,4 @@ if not command -s realpath >/dev/null
builtin realpath $arg builtin realpath $arg
end end
end end
end
end end