* Suggestion for Completion/Unix/Command/_ln
@ 2011-08-19 11:05 Nikolai Weibull
2011-08-19 20:23 ` Peter Stephenson
0 siblings, 1 reply; 4+ messages in thread
From: Nikolai Weibull @ 2011-08-19 11:05 UTC (permalink / raw)
To: Zsh Workers
[-- Attachment #1: Type: text/plain, Size: 190 bytes --]
Hi!
Here’s a suggestion for Completion/Unix/Command/_ln.
I have, however, not been able to get _pick_variant to work for
zle/files. Can someone please suggest a way to handle it?
[-- Attachment #2: _ln --]
[-- Type: application/octet-stream, Size: 3135 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 zsh=zsh unix --help
case $variant in
(gnu)
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]')
;;
(zsh)
args+=(
'-d[attempt to hard link directories]'
{-h,-n}'[do not dereference destination]'
'-i[prompt before removing destination files]')
;;
(*)
case $OSTYPE in
(darwin*)
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]')
;;
esac
;;
esac
_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
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Suggestion for Completion/Unix/Command/_ln
2011-08-19 11:05 Suggestion for Completion/Unix/Command/_ln Nikolai Weibull
@ 2011-08-19 20:23 ` Peter Stephenson
2011-08-20 7:38 ` Nikolai Weibull
0 siblings, 1 reply; 4+ messages in thread
From: Peter Stephenson @ 2011-08-19 20:23 UTC (permalink / raw)
To: Zsh Workers
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).
--
Peter Stephenson <p.w.stephenson@ntlworld.com>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Suggestion for Completion/Unix/Command/_ln
2011-08-19 20:23 ` Peter Stephenson
@ 2011-08-20 7:38 ` Nikolai Weibull
2011-08-20 7:45 ` Nikolai Weibull
0 siblings, 1 reply; 4+ messages in thread
From: Nikolai Weibull @ 2011-08-20 7:38 UTC (permalink / raw)
To: Peter Stephenson; +Cc: Zsh Workers
[-- 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
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Suggestion for Completion/Unix/Command/_ln
2011-08-20 7:38 ` Nikolai Weibull
@ 2011-08-20 7:45 ` Nikolai Weibull
0 siblings, 0 replies; 4+ messages in thread
From: Nikolai Weibull @ 2011-08-20 7:45 UTC (permalink / raw)
To: Peter Stephenson; +Cc: Zsh Workers
On Sat, Aug 20, 2011 at 09:38, Nikolai Weibull <now@bitwi.se> wrote:
> 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.
(I’ve committed it to CVS. I hope that was alright.)
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2011-08-20 7:45 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-08-19 11:05 Suggestion for Completion/Unix/Command/_ln Nikolai Weibull
2011-08-19 20:23 ` Peter Stephenson
2011-08-20 7:38 ` Nikolai Weibull
2011-08-20 7:45 ` Nikolai Weibull
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).