mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-25 20:33:08 +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
|
end
|
||||||
|
|
||||||
function realpath -d "return an absolute path without symlinks"
|
function realpath -d "return an absolute path without symlinks"
|
||||||
if test -z "$argv"
|
set -l options 'h/help' 'q/quiet' 'V-version' 's/strip' 'N-no-symlinks' 'z/zero'
|
||||||
printf "usage: %s%s%s %sfile%s …\n" (set_color -o) $_ (set_color normal) (set_color -u) (set_color normal)
|
set options $options 'e/canonicalize-existing' 'm/canonicalize-missing' 'L/logical' 'P/physical'
|
||||||
echo " resolves files as absolute paths without symlinks"
|
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
|
return 1
|
||||||
end
|
end
|
||||||
|
|
||||||
# Loop over arguments - allow our realpath to work on more than one path per invocation
|
for path in $argv
|
||||||
# like gnu/bsd realpath.
|
builtin realpath $path
|
||||||
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
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue