zsh-workers
 help / color / mirror / code / Atom feed
* rm(1) completion definition
@ 2008-09-30 21:03 Nikolai Weibull
  2008-10-01  9:38 ` Oliver Kiddle
  0 siblings, 1 reply; 4+ messages in thread
From: Nikolai Weibull @ 2008-09-30 21:03 UTC (permalink / raw)
  To: Zsh Workers

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

Two notes:

1.  It seems that my trick to disable --force and --recursive on
non-GNU systems doesn't work.  Does the specifications have to match
exactly?  A prefix match like the one I was hoping for would be nice,
or is there some other way to achieve the same effect?

2.  I'm not sure if the zstyle thing is correct, but it's definitely
what you want it to do.  Is there a better way to achieve the same
effect?

Thanks (and enjoy)!

[-- Attachment #2: _rm --]
[-- Type: application/octet-stream, Size: 1308 bytes --]

#compdef rm

local -a opts args ignore
args=(
  '(-f --force)'{-f,--force}'[ignore nonexistent files, never prompt]'
  '(-I --interactive)-i[prompt before every removal]'
  '(-r -R --recursive)'{-r,-R,--recursive}'[remove directories and their contents recursively]'
  '*:file:_files'
)
if _pick_variant gnu=GNU unix --version; then
  opts+=(-S)
  args+=(
    '(-i --interactive)-I[prompt when removing many files]'
    '(-i -I)--interactive=-[prompt under given condition (defaulting to always)]::when:((once\:"prompt when removing many files"
                                                                                         always\:"prompt before every removal"))'
    '--one-file-system[stay within filesystems of files given as arguments]'
    '(                   --preserve-root)--no-preserve-root[do not treat / specially]'
    '(--no-preserve-root                )--preserve-root[do not remove / (default)]'
    '(-v --verbose)'{-v,--verbose}'[explain what is being done]'
    '(- *)--help[display help message and exit]'
    '(- *)--version[output version information and exit]'
  )
else
  args+=(
    '!--force'
    '!--recursive'
  )
fi

zstyle -s ':completion:$curcontext:files' ignore-line ignore || \
  zstyle ':completion:$curcontext:files' ignore-line yes

_arguments $opts \
  $args

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: rm(1) completion definition
  2008-09-30 21:03 rm(1) completion definition Nikolai Weibull
@ 2008-10-01  9:38 ` Oliver Kiddle
  2008-10-01 13:21   ` Nikolai Weibull
  0 siblings, 1 reply; 4+ messages in thread
From: Oliver Kiddle @ 2008-10-01  9:38 UTC (permalink / raw)
  To: Nikolai Weibull; +Cc: Zsh Workers

Nikolai Weibull wrote:
> 1.  It seems that my trick to disable --force and --recursive on
> non-GNU systems doesn't work.  Does the specifications have to match

This is better done as:
  args=( ${args:#*--(force|recursive)\[*} )

The ! syntax is intended for a different purpose: where you have an
option that may appear earlier on the command-line and you don't want to
complete it but _arguments needs to know what it's exclusion lists and
arguments are.

> 2.  I'm not sure if the zstyle thing is correct, but it's definitely
> what you want it to do.  Is there a better way to achieve the same
> effect?

The problem with the zstyle stuff is that you've used single quotes so
$curcontext is not expanded. Personally, I think it is fundamentally
wrong to ever define zstyles in completion functions. They are meant
for user-customisation and can sometimes get in the way of
customisations. The very specific context for them can make them hard
to override.

At some point in the past, there was a problem with ignore-line that
meant that if you tried to do something like:
  rm foo dir/foo
It wouldn't complete foo in the subdirectory. I can't reproduce this now
so perhaps it was a bit more subtle or perhaps it got fixed.

The right way to do this would be to work out exactly what can't be
completed and build up a suitable glob pattern to pass to _files with
-g.

One other point: I really hope that running rm --version can't possibly
actually result in a file or files being removed on some system. I'm a
bit uneasy about it. Perhaps you should try using rm --help instead
because there's no `r' in help.

Oliver


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: rm(1) completion definition
  2008-10-01  9:38 ` Oliver Kiddle
@ 2008-10-01 13:21   ` Nikolai Weibull
  2008-10-08  9:29     ` Nikolai Weibull
  0 siblings, 1 reply; 4+ messages in thread
From: Nikolai Weibull @ 2008-10-01 13:21 UTC (permalink / raw)
  To: Oliver Kiddle; +Cc: Zsh Workers

On Wed, Oct 1, 2008 at 11:38, Oliver Kiddle <okiddle@yahoo.co.uk> wrote:

> Nikolai Weibull wrote:

>> 1.  It seems that my trick to disable --force and --recursive on
>> non-GNU systems doesn't work.

> This is better done as:
>  args=( ${args:#*--(force|recursive)\[*} )

Thanks, will change to that.

>> 2.  I'm not sure if the zstyle thing is correct, but it's definitely
>> what you want it to do.  Is there a better way to achieve the same
>> effect?
>
> The problem with the zstyle stuff is that you've used single quotes so
> $curcontext is not expanded.

Duh.  Forgot to change that.

> The right way to do this would be to work out exactly what can't be
> completed and build up a suitable glob pattern to pass to _files with
> -g.

Ugh.  That sounds complicated.

> One other point: I really hope that running rm --version can't possibly
> actually result in a file or files being removed on some system. I'm a
> bit uneasy about it. Perhaps you should try using rm --help instead
> because there's no `r' in help.

OK, sounds reasonable.

Thank you for your pointers


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: rm(1) completion definition
  2008-10-01 13:21   ` Nikolai Weibull
@ 2008-10-08  9:29     ` Nikolai Weibull
  0 siblings, 0 replies; 4+ messages in thread
From: Nikolai Weibull @ 2008-10-08  9:29 UTC (permalink / raw)
  To: Oliver Kiddle; +Cc: Zsh Workers

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

On Wed, Oct 1, 2008 at 15:21, Nikolai Weibull <now@bitwi.se> wrote:

> On Wed, Oct 1, 2008 at 11:38, Oliver Kiddle <okiddle@yahoo.co.uk> wrote:

>> Nikolai Weibull wrote:

>>> 1.  It seems that my trick to disable --force and --recursive on
>>> non-GNU systems doesn't work.

>> This is better done as:
>>  args=( ${args:#*--(force|recursive)\[*} )

> Thanks, will change to that.

Done.

>> The right way to do this would be to work out exactly what can't be
>> completed and build up a suitable glob pattern to pass to _files with
>> -g.
>
> Ugh.  That sounds complicated.

Done.

>> One other point: I really hope that running rm --version can't possibly
>> actually result in a file or files being removed on some system. I'm a
>> bit uneasy about it. Perhaps you should try using rm --help instead
>> because there's no `r' in help.

> OK, sounds reasonable.

Done.

How about including it now?

[-- Attachment #2: _rm --]
[-- Type: application/octet-stream, Size: 1414 bytes --]

#compdef rm

declare -a opts args
args=(
  '(-f --force)'{-f,--force}'[ignore nonexistent files, never prompt]'
  '(-I --interactive)-i[prompt before every removal]'
  '(-r -R --recursive)'{-r,-R,--recursive}'[remove directories and their contents recursively]'
  '*:files:->file'
)
if _pick_variant gnu=gnu unix --help; then
  opts+=(-S)
  args+=(
    '(-i --interactive)-I[prompt when removing many files]'
    '(-i -I)--interactive=-[prompt under given condition (defaulting to always)]::when:((once\:"prompt when removing many files"
                                                                                         always\:"prompt before every removal"))'
    '--one-file-system[stay within filesystems of files given as arguments]'
    '(                   --preserve-root)--no-preserve-root[do not treat / specially]'
    '(--no-preserve-root                )--preserve-root[do not remove / (default)]'
    '(-v --verbose)'{-v,--verbose}'[explain what is being done]'
    '(- *)--help[display help message and exit]'
    '(- *)--version[output version information and exit]'
  )
else
  args=(${args:#*--(force|recursive)\[*})
fi

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

_arguments -C $opts \
  $args && ret=0

case $state in
  (file)
    declare -a ignored
    ignored=(${line//(#m)[\[\]()\\*?#<>~\^]/\\$MATCH})
    _path_files -F ignored && ret=0
    ;;
esac

return $ret

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2008-10-08  9:30 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-09-30 21:03 rm(1) completion definition Nikolai Weibull
2008-10-01  9:38 ` Oliver Kiddle
2008-10-01 13:21   ` Nikolai Weibull
2008-10-08  9:29     ` 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).