Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Adding a prefix to certain filename completions



[Aside:  Is it possible for you to convince your mail client not to send
text labeled us-ascii when it contains multi-byte characters (I think
they must be Unicode apostrophes?)  It makes it quite difficult to read.
I've manually edited them back to ' in the excerpt.]

On Jul 7,  4:02am, Nikolai Weibull wrote:
} Subject: Re: Adding a prefix to certain filename completions
}
} There's a problem with the +<n> option, though. I couldn't figure out
} a proper way of escaping the + that is the options name (just using \+
} doesn't work).

The + is not the option's name.  The name is whatever comes *after* the
initial - or + that introduces the option.  In fact, in this case +<n>
is not really an option at all; really it's a non-option argument that
happens to be allowed to be mixed in among the options.

The most effective way to handle it is to rewrite _my_files:

    _my_files () {
      case $PREFIX in
	(+) _message -e 'start at given line (default: end of file)' ;;
	(+<1->) _message -e 'line number' ;;
      esac
      case $PREFIX in
	(+*) _files -P './' $* ;;
	(*) _files $* ;;
      esac
    }

Another way is to pretend that the number is the option name:

    arguments=(
      ...
      +{1..9}-'[start at given line (default: end of file)]::line number: '
      ...
    )

I prefer the behavior of the modified _my_files (which, by the way,
should probably be renamed _vim_files if this is going to be added to
the stock completions).



Messages sorted by: Reverse Date, Date, Thread, Author