summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Stephenson <pws@users.sourceforge.net>2003-08-20 12:03:07 +0000
committerPeter Stephenson <pws@users.sourceforge.net>2003-08-20 12:03:07 +0000
commit8bcffc6b11131d989cf92cea52aa849790f1580f (patch)
tree543f43e0554ed029f396cfa7849753d878adae5f
parentea412fbe4b639a71eea54b9daaf3b64c750ef763 (diff)
downloadzsh-8bcffc6b11131d989cf92cea52aa849790f1580f.tar.gz
zsh-8bcffc6b11131d989cf92cea52aa849790f1580f.zip
18951: Better option handling (c.f. 18948)
-rw-r--r--ChangeLog4
-rw-r--r--Completion/Unix/Command/_perforce37
2 files changed, 31 insertions, 10 deletions
diff --git a/ChangeLog b/ChangeLog
index 0f80fd7c9..ceccdd4a1 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
2003-08-20 Peter Stephenson <pws@csr.com>
+ * 18951: Completion/Unix/Command/_perforce: Improve 18948 to
+ limit options retained, also make argument to p4 -p complete
+ better.
+
* 18942: Completion/Unix/Command/_perforce: Fix autoremoval
of slashes which were stomped on by the special suffix handler.
diff --git a/Completion/Unix/Command/_perforce b/Completion/Unix/Command/_perforce
index cde4cf013..6803ad6da 100644
--- a/Completion/Unix/Command/_perforce
+++ b/Completion/Unix/Command/_perforce
@@ -251,27 +251,41 @@ _perforce() {
fi
fi
+ # Options with arguments we need to pass down when calling
+ # p4 from completers. There are no options without arguments
+ # we need to pass. (Don't pass down -L language since we
+ # parse based on English output.)
+ local argopts_pass="cCdHpPu"
+ # Other options which have arguments but we shouldn't pass down.
+ # There are some debugging options, but they tend to get used
+ # with the argument in the same word as the option, in which
+ # case they will be handled OK anyway.
+ local argopts_ignore="Lx"
+
+ # If we are at or after the command word, remember the
+ # global arguments to p4 as we will need to pass these down
+ # when generating completion lists.
+ local -a _perforce_global_options
+
# We need to try and check if we are before or after the
# subcommand, since some of the options with arguments, in particular -c,
# work differently. It didn't work if I just added '*::...' to the
# end of the arguments list, anyway.
for (( i = 2; i < CURRENT; i++ )); do
- if [[ $words[i] = -[cCdHLpPux] ]]; then
+ if [[ $words[i] = -[$argopts_pass$argopts_ignore] ]]; then
# word with following argument
+ if [[ $words[i] = -[$argopts_pass] ]]; then
+ _perforce_global_options+=(${words[i,i+1]})
+ fi
(( i++ ))
+ elif [[ $words[i] = -[$argopts_pass]* ]]; then
+ # word including argument which we want to keep
+ _perforce_global_options+=(${words[i]})
elif [[ $words[i] != -* ]]; then
break
fi
done
- # If we are at or after the command word, remember the
- # global arguments to p4 as we will need to pass these down
- # when generating completion lists.
- local -a _perforce_global_options
- if (( i <= CURRENT && i > 2 )); then
- _perforce_global_options=(${words[2,i-1]})
- fi
-
if (( i >= CURRENT )); then
_arguments -s : \
'-c+[client]:client:_perforce_clients' \
@@ -280,7 +294,7 @@ _perforce() {
'-H+[hostname]:host:_hosts' \
'-G[python output]' \
'-L+[message language]:language: ' \
- '-p+[server port]:port:_ports' \
+ '-p+[server port]:port:_perforce_hosts_ports' \
'-P+[password on server]:password: ' \
'-s[output script tags]' \
'-u+[user]:user name:_users' \
@@ -305,6 +319,9 @@ _perforce() {
_perforce_call_p4() {
local cp_tag=$1
shift
+ # This is for our own use for parsing, and we need English output,
+ # so...
+ local +x P4LANGUAGE
_call_program $cp_tag p4 "${_perforce_global_options[@]}" "$@"
}