summary refs log tree commit diff
path: root/Completion/Unix/Command/_ln
blob: c903fee02ea33c6eb3b45ad484c3daadaba65978 (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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#compdef ln gln zf_ln

local curcontext="$curcontext" state line ret=1
local -A opt_args

local -a args bsd
args=(
  '-f[remove existing destination files]'
  '-s[create symbolic links instead of hard links]'
)
bsd=(
  '-F[remove existing destination directories]'
  {-h,-n}'[do not dereference destination]'
  '-i[prompt before removing destination files]'
  '-v[print name of each linked file]'
)

local -a opts

local variant
_pick_variant -r variant gnu=gnu unix --help
if [[ $variant == gnu ]]; then
  opts=(-S)
  args=(
    '(-b --backup)-b[create a backup of each existing destination file]' \
    '(-b --backup)--backup=[create a backup of each existing destination file]::method:((
        none\:"never create backups"
        off\:"never create backups"
        numbered\:"create numbered backup"
        t\:"create numbered backup"
        existing\:"same as numbered if numbered backups exist, otherwise same as simple"
        nil\:"same as numbered if numbered backups exist, otherwise same as simple"
        simple\:"always create simple backups"
        never\:"always create simple backups"))'
    '(-d -F --directory)'{-d,-F,--directory}'[allow the superuser to attempt to hard link directories]'
    '(-f --force)'{-f,--force}'[remove existing destination files]'
    '(-i --interactive)'{-i,--interactive}'[prompt before removing destination files]'
    '(-L --logical)'{-L,--logical}'[create hard links to symbolic link references]'
    '(-n --no-dereference)'{-n,--no-dereference}'[treat destination symbolic link to a directory as if it were a normal file]'
    '(-P --physical)'{-P,--physical}'[create hard links directly to symbolic links]'
    '(-s --symbolic)'{-s,--symbolic}'[create symbolic links instead of hard links]'
    '(-S --suffix)'{-S,--suffix=}'[override default backup suffix]:suffix'
    '(-t --target-directory)'{-t,--target-directory=}'[specify directory in which to create the links]: :_directories'
    '(-T --no-target-directory)'{-T,--no-target-directory}'[treat destination as a normal file]'
    '(-v --verbose)'{-v,--verbose}'[print name of each linked file]'
    '--help[display usage information and exit]'
    '--version[display version information and exit]')
elif (( ${+builtins[ln]} )); then
  args+=(
    '-d[attempt to hard link directories]'
    {-h,-n}'[do not dereference destination]'
    '-i[prompt before removing destination files]')
elif [[ $OSTYPE == darwin* ]]; then
  args+=( $bsd )
elif [[ $OSTYPE == freebsd* ]]; then
  args+=( $bsd
    '(-L)-P[create hard links directly to symbolic links]'
    '(-P)-L[create hard links to symbolic link references]'
    "-w[warn if source of a symbolic link doesn't currently exist]"
  )
fi

_arguments -C -s $opts \
  $args \
  ':link target:_files' \
  '*:: :->files' && ret=0

case $state in
  (files)
    if [[ $variant == gnu && -n ${opt_args[(I)-t|--target-directory]} ]]; then
      _wanted files expl 'link target' _files && ret=0
    else
      if (( CURRENT == 2 )); then
        local expl
        _wanted files expl 'additional link target or link name' _files && ret=0
      else
        _alternative \
          'link-targets:additional link target:_files' \
          'target-directories:target directory:_directories' && ret=0
      fi
    fi
    ;;
esac

return ret