about summary refs log tree commit diff
path: root/Completion/Unix/Command/_readlink
blob: 36bd4375246cc213142eb14d9b22b52fe5ee527f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#compdef readlink greadlink

local variant ret=1
local -a context line state state_descr args copts aopts=( -A '-*' )
local -A opt_args

# We can't use groups here because it would complicate the option filtering
copts=( -e -f -m --canonicalize --canonicalize-existing --canonicalize-missing )

args=(
  '(: -)--help[display help information]'
  '(: -)--version[display version information]'
  # Delimiter options
  # (Note: GNU `readlink` won't let you use -n with multiple files)
  '(-n -z --no-newline --zero)'{-n,--no-newline}'[suppress trailing newline]'
  '(-n -z --no-newline --zero)'{-z,--zero}'[use NUL as output delimiter]'
  # Verbosity options
  '(-q -s -v --quiet --silent --verbose)'{-q,-s,--quiet,--silent}'[suppress most error messages]'
  '(-q -s -v --quiet --silent --verbose)'{-v,--verbose}'[show error messages]'
  # Canonicalisation options
  "(${(j< >)copts})"{-e,--canonicalize-existing}'[canonicalize paths (all components must exist)]'
  "(${(j< >)copts})"{-f,--canonicalize}'[canonicalize paths]'
  "(${(j< >)copts})"{-m,--canonicalize-missing}'[canonicalize paths (components may be missing)]'
)

# Filter out non-GNU options if applicable
if _pick_variant gnu='Free Soft' unix --version; then
  aopts=( )
else
  case $OSTYPE in
    darwin*)          args=( ${(@M)args:#(|*\))-[n]\[*} ) ;;
    netbsd*)          args=( ${(@M)args:#(|*\))-[fnqsv]\[*} ) ;;
    dragonfly*|*bsd*) args=( ${(@M)args:#(|*\))-[fn]\[*} ) ;;
    *) args=( ) ;;
  esac
fi

_arguments -s -S $aopts : $args '*: :->files' && ret=0

# File arguments must be symlinks unless a canonicalisation option is given
[[ $state == files ]] &&
if [[ ${opt_args[(i)(${~${(j<|>)copts}})]} ]]; then
  _files && ret=0
else
  _files -g '*(@)' && ret=0
fi

return ret