diff options
author | Peter Stephenson <pws@users.sourceforge.net> | 2003-10-13 16:54:25 +0000 |
---|---|---|
committer | Peter Stephenson <pws@users.sourceforge.net> | 2003-10-13 16:54:25 +0000 |
commit | a190add8594baa85341215b7d689a245681ed88b (patch) | |
tree | 30785b5396de8d2c60a3622adbc125330ad13112 /Completion/Unix/Command | |
parent | 78bef99b732ade6b8d4f7784624fa5dcaed2c446 (diff) | |
download | zsh-a190add8594baa85341215b7d689a245681ed88b.tar.gz zsh-a190add8594baa85341215b7d689a245681ed88b.tar.xz zsh-a190add8594baa85341215b7d689a245681ed88b.zip |
unposted: Make _perforce easier to use with add-on commands.
Diffstat (limited to 'Completion/Unix/Command')
-rw-r--r-- | Completion/Unix/Command/_perforce | 66 |
1 files changed, 53 insertions, 13 deletions
diff --git a/Completion/Unix/Command/_perforce b/Completion/Unix/Command/_perforce index 8ec3baaaf..7d9aa48eb 100644 --- a/Completion/Unix/Command/_perforce +++ b/Completion/Unix/Command/_perforce @@ -217,6 +217,35 @@ # Perforce options, comme ca: # compdef _perforce p4reopen=p4-job-global # +# Anything more complicated should be modelled on one of the +# _perforce_cmd_* handlers below. To get this to work, the full +# set of _perforce functions must be loaded; because of the way +# autoloading works, a trick is required: call "_perforce -l" which +# causes the function to be executed, loading all the associated +# functions as a side effect, but tells _perforce to return without +# generating any completions. For example, here is the completion +# for my `p4desc' function which is an enhanced version of `p4 describe' +# (without any handling for global Perforce arguments): +# +# #compdef p4desc +# +# _perforce -l +# +# _arguments -s : \ +# '-d-[select diff option]:diff option:((b\:ignore\ blanks c\:context d\:basic\ diff n\:RCS s\:summary u\:unified w\:ignore\ all\ whitespace))' \ +# '-s[short form]' \ +# '-j[select by job]:job:_perforce_jobs' \ +# '*::change:_perforce_changes' +# +# To add handling of global options to this, see the end of the _perforce +# function below. Something like: +# +# local -a _perforce_global_options _perforce_option_dispatch +# if _perforce_global_options; then +# _arguments -s : $_perforce_option_dispatch \ +# '<other stuff>' +# fi +# # TODO # ==== # @@ -232,6 +261,12 @@ _perforce() { local p4cmd==p4 match mbegin mend integer _perforce_cmd_ind + if [[ $1 = -l ]]; then + # Run to load _perforce and associated functions but do + # nothing else. + return + fi + if [[ $service = -value-* ]]; then # Completing parameter value. # Some of these --- in particular P4PORT --- don't need @@ -269,19 +304,6 @@ _perforce() { # get confused... local -a _perforce_global_options local -a _perforce_option_dispatch - _perforce_option_dispatch=( - '-c+[client]:client:_perforce_clients' \ - '-C+[charset]:charset:_perforce_charsets' \ - '-d+[current directory]:directory:_path_files -g "*(/)"' \ - '-H+[hostname]:host:_perforce_hosts' \ - '-G[python output]' \ - '-L+[message language]:language: ' \ - '-p+[server port]:port:_perforce_hosts_ports' \ - '-P+[password on server]:password: ' \ - '-s[output script tags]' \ - '-u+[user]:user name:_perforce_users' \ - '-x+[filename or -]:file:_perforce_files_or_minus' \ - ) # If we are given a service of the form p4-cmd, treat this # as if it was after `p4 cmd'. This provides an easy way in @@ -414,6 +436,24 @@ _perforce_global_options() { # case they will be handled OK anyway. local argopts_ignore="Lx" + # The options we support in the form for _arguments. + # This is here for modularity and convenience, but note that since the + # actual dispatch takes place later, this is not local to this + # function and so must be made local in the caller. + _perforce_option_dispatch=( + '-c+[client]:client:_perforce_clients' \ + '-C+[charset]:charset:_perforce_charsets' \ + '-d+[current directory]:directory:_path_files -g "*(/)"' \ + '-H+[hostname]:host:_perforce_hosts' \ + '-G[python output]' \ + '-L+[message language]:language: ' \ + '-p+[server port]:port:_perforce_hosts_ports' \ + '-P+[password on server]:password: ' \ + '-s[output script tags]' \ + '-u+[user]:user name:_perforce_users' \ + '-x+[filename or -]:file:_perforce_files_or_minus' \ + ) + integer i # We need to try and check if we are before or after the |