pstray / rename

Rename renames the filenames supplied according to the rule specified as the first argument. The argument is a Perl expression which is expected to modify the $_ string for at least some of the filenames specified.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[feature] shell completion

Freed-Wu opened this issue · comments

commented

Can perl-rename have a shell completion like parallel? TIA!

commented

parallel also have a zsh completion: https://git.savannah.gnu.org/cgit/parallel.git/tree/src/parallel#n1646. How about it?

I don't use zsh personally, so I have no experience with completion there... Seems it would need a bit larger rewrite to handle that since it seems to need option descriptions too.

commented

I write a zsh completion script. Can rename generate it?

#compdef perl-rename

local options=(
  {-b,--backup}"[make backup before removal]"
  {-B,--prefix}"[set backup filename prefix]:suffix"
  {-f,--force}"[remove existing destinations, never prompt]"
  {-i,--interactive}"[prompt before overwrite]"
  {-l,--link-only}"[link file instead of rename]"
  {-n,--just-print,--dry-run}"[don't rename, implies --verbose]"
  {-v,--verbose}"[explain what is being done]"
  {-V,--version-control}"[override the usual version control]:method:(numbered t existing nil simple never)"
  {-Y,--basename-prefix}"[set backup filename basename prefix]:prefix"
  {-z,-S,--suffix}"[set backup filename suffix]:suffix"
  '(- : *)'--help"[display this help and exit]"
  '(- : *)'--version"[output version information and exit]"
)

_arguments -S -s $options '1:perl expr' '*:: :_files'

I'll have a look at how to best generate those lines... should be doable :)

But what are the '(- : *)'-parts before --help and --version?

commented

But what are the '(- : *)'-parts before --help and --version?

This is group. If two options are exclusive, such as

local options=(
  --bar
  '(--interactive)--nointeractive'
  '(--nointeractive)--interactive'
)
_argument $options ''

so foo --interactive <TAB> will only complete --bar, not --nointeractive.

- is a special group which stop all -*. * is a special group stop all *. : doesn't exist here which can be removed.

Another example:

local options=(
  '(- : *)--help'
)
_argument $options ':operations:(add sub)' '*::file:_files'

foo <TAB> will complete add or sub. foo add <TAB> will complete files.
foo add a.txt b.txt ... <TAB> will complete files, too. However, foo add --help <TAB> will not complete files due to *.
foo --help <TAB> will not complete add and sub due to :.

Ah, I see, that is quite useful.