mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-25 12:23:09 +00:00
update realpath
to use argparse
This commit is contained in:
parent
3e6c57d5d3
commit
51bbecc419
1 changed files with 19 additions and 24 deletions
|
@ -22,32 +22,27 @@ if command -sq grealpath
|
|||
end
|
||||
|
||||
function realpath -d "return an absolute path without symlinks"
|
||||
if test -z "$argv"
|
||||
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"
|
||||
set -l options 'h/help' 'q/quiet' 'V-version' 's/strip' 'N-no-symlinks' 'z/zero'
|
||||
set options $options 'e/canonicalize-existing' 'm/canonicalize-missing' 'L/logical' 'P/physical'
|
||||
set options $options 'R-relative-to=' 'B-relative-base='
|
||||
argparse -n realpath --min-args=1 $options -- $argv
|
||||
or return
|
||||
|
||||
if set -q _flag_help
|
||||
__fish_print_help realpath
|
||||
return 0
|
||||
end
|
||||
|
||||
# We don't implement any of the other flags so if any are set it's an error.
|
||||
if string match -q '_flag_*' -- (set -l)
|
||||
set flags (set -l | string replace --filter _flag_ '')
|
||||
printf (_ "%s: These flags are not allowed by fish realpath: '%s'") realpath "$flags" >&2
|
||||
echo >&2
|
||||
__fish_print_help realpath
|
||||
return 1
|
||||
end
|
||||
|
||||
# Loop over arguments - allow our realpath to work on more than one path per invocation
|
||||
# like gnu/bsd realpath.
|
||||
for arg in $argv
|
||||
switch $arg
|
||||
# These - no can do our realpath
|
||||
case -s --strip --no-symlinks -z --zero --relative-base\* --relative-to\*
|
||||
__fish_print_help realpath
|
||||
return 2
|
||||
|
||||
case -h --help --version
|
||||
__fish_print_help realpath
|
||||
return 0
|
||||
|
||||
# Handle commands called with these arguments by dropping the arguments to protect
|
||||
# realpath from them. There are no sure things here.
|
||||
case -e --canonicalize-existing --physical -P -q --quiet -m --canonicalize-missing
|
||||
continue
|
||||
|
||||
case "*"
|
||||
builtin realpath $arg
|
||||
end
|
||||
for path in $argv
|
||||
builtin realpath $path
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue