fork/fish-shell
git clone https://git.julia.blue/fork/fish-shell
d835c5252
master
1# localization: skip(uses-apropos) 2 3# Provide a minimalist realpath implementation to help deal with platforms that may not provide it 4# as a command. If an external realpath or grealpath command is available simply pass all arguments 5# thru to it. If not fallback to our builtin. 6 7# The following is slightly subtle. We have to define a realpath function even if there is an 8# external command by that name. That's because if we don't the parser will select our builtin. 9# However, we only want our builtin if there is no external realpath command. 10 11if command -sq realpath 12function realpath 13command realpath$argv 14end 15exit 0 16end 17 18# If there is a HomeBrew installed version of GNU realpath named grealpath use that. 19if command -sq grealpath 20function realpath 21command grealpath$argv 22end 23exit 0 24end 25 26function realpath -d"return an absolute path without symlinks" 27set -l options h/help q/quiet V-version s/no-symlinks N-strip z/zero 28set -a options e/canonicalize-existing m/canonicalize-missing L/logical P/physical 29set -a options'R-relative-to=' 'B-relative-base=' 30argparse -n realpath$options --$argv 31or return 32 33if set -q _flag_help 34__fish_print_help realpath 35return 0 36end 37 38set -l supported_flags 39if set -el _flag_no_symlinks 40set -el _flag_s 41set -a supported_flags --no-symlinks 42end 43 44# We don't implement any of the other flags so if any are set it's an error. 45if string match -q'_flag_*' --( set -l) 46set -l flags( set -l| string replace --filter --regex'_flag_\w+\s*' '' | sort -u) 47printf "realpath: These flags are not allowed by fish realpath: '%s'" " $flags " >&2 48echo >&2 49__fish_print_help realpath 50return 1 51end 52 53if not set -q argv[ 1 ] 54printf "realpath: Expected at least %d args, got only %d\n" 1 0 >&2 55return 1 56end 57 58for pathin $argv 59builtin realpath$supported_flags $path 60end 61end