zsh-workers
 help / color / mirror / code / Atom feed
From: Nikolai Weibull <now@bitwi.se>
To: Peter Stephenson <p.w.stephenson@ntlworld.com>
Cc: Zsh Workers <zsh-workers@zsh.org>
Subject: Re: Suggestion for Completion/Unix/Command/_ln
Date: Sat, 20 Aug 2011 09:38:08 +0200	[thread overview]
Message-ID: <CADdV=MtB+DYHjbX1XLQ-7YPzOa67i=kx9M1G5BYvrxke91JbEg@mail.gmail.com> (raw)
In-Reply-To: <20110819212323.6df1a054@pws-pc.ntlworld.com>

[-- Attachment #1: Type: text/plain, Size: 563 bytes --]

On Fri, Aug 19, 2011 at 22:23, Peter Stephenson
<p.w.stephenson@ntlworld.com> wrote:
> On Fri, 19 Aug 2011 13:05:08 +0200
> Nikolai Weibull <now@bitwi.se> wrote:
>> I have, however, not been able to get _pick_variant to work for
>> zle/files.  Can someone please suggest a way to handle it?
>
> if [[ -n $builtins[ln] ]]; then ...
>
> should be good enough to test if ln is being provided by a builtin
> (possibly not yet loaded).

OK, thanks!  I changed it to (( ${+builtins[ln]} )), as I like that
pattern better.

Here’s an updated version.

[-- Attachment #2: _ln --]
[-- Type: application/octet-stream, Size: 3028 bytes --]

#compdef ln gln

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

local -a args
args=(
  '-f[remove existing destination files]'
  '-s[create symbolic links instead of hard links]')

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+=(
    '-F[remove existing destination directories]'
    {-h,-n}'[do not dereference destination]'
    '-i[prompt before removing destination files]'
    '-v[print name of each linked file]')
fi

_arguments -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

  reply	other threads:[~2011-08-20  7:38 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-08-19 11:05 Nikolai Weibull
2011-08-19 20:23 ` Peter Stephenson
2011-08-20  7:38   ` Nikolai Weibull [this message]
2011-08-20  7:45     ` Nikolai Weibull

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CADdV=MtB+DYHjbX1XLQ-7YPzOa67i=kx9M1G5BYvrxke91JbEg@mail.gmail.com' \
    --to=now@bitwi.se \
    --cc=p.w.stephenson@ntlworld.com \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).