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

PATCH: perforce completion problems: doesn't use supplied p4 flags



Felix Rosencrantz wrote:
> The p4 completer doesn't seem to use the p4 flags provided to do completion.
> 
> For example if I do a:  "p4 -p perforce_host2:1666 client <TAB>"
> It doesn't make use of the -p flag when trying to do completions for possible
> clients.  It uses the default.  There are other flags that should also be
> carried along when generating completions for some items like user/password.

I've made it use all of them, let me know if this causes problems.
(Hmm, it shouldn't use -x or -G, but those aren't common interactively
and you can't complete for -x anyway, and it shouldn't use -V, but you
can't complete for that either.)

> Also the completer doesn't complete the "p4 -Ztag"  flag.

I can't find any documentation for this, it's either old or only used
with a subset of commands.

Index: Completion/Unix/Command/_perforce
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Unix/Command/_perforce,v
retrieving revision 1.8
diff -u -r1.8 _perforce
--- Completion/Unix/Command/_perforce	16 Jul 2003 01:44:17 -0000	1.8
+++ Completion/Unix/Command/_perforce	19 Aug 2003 19:38:24 -0000
@@ -237,20 +237,6 @@
 	return
     fi
 
-    if (( ! ${#_perforce_cmd_list} )); then
-	(( ${+_perforce_cmd_list} )) || typeset -ga _perforce_cmd_list
-	local hline
-	# Output looks like <tab>command-name<space>description in words...
-	# Ignore blank lines and the heading line beginning `Perforce...'
-	# Just gets run once, then cached, so don't bother optimising
-	# this to a grossly unreadable parameter substitution.
-	_call_program help-commands p4 help commands | while read -A hline; do
-	    (( ${#hline} < 2 )) && continue
-	    [[ $hline[1] = (#i)perforce ]] && continue
-	    _perforce_cmd_list+=("${hline[1]}:${hline[2,-1]}")
-	done
-    fi
-
     # 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
     # for scripts and functions that emulate the behaviour of
@@ -278,6 +264,14 @@
 	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' \
@@ -305,8 +299,37 @@
 # Command and argument dispatchers
 #
 
+# Front end to _call_program to add in the global arguments
+# passed to p4.
+(( $+functions[_perforce_call_p4] )) ||
+_perforce_call_p4() {
+    local cp_tag=$1
+    shift
+    _call_program $cp_tag p4 "${_perforce_global_options[@]}" "$@"
+}
+
+
+# The list of commands is cached in _perforce_cmd_list, but we
+# only generate it via this function when we need it.
+(( $+functions[_perforce_gen_cmd_list] )) ||
+_perforce_gen_cmd_list() {
+    (( ${+_perforce_cmd_list} )) || typeset -ga _perforce_cmd_list
+    local hline
+    # Output looks like <tab>command-name<space>description in words...
+    # Ignore blank lines and the heading line beginning `Perforce...'
+    # Just gets run once, then cached, so don't bother optimising
+    # this to a grossly unreadable parameter substitution.
+    _perforce_call_p4 help-commands help commands | while read -A hline; do
+	(( ${#hline} < 2 )) && continue
+	[[ $hline[1] = (#i)perforce ]] && continue
+	_perforce_cmd_list+=("${hline[1]}:${hline[2,-1]}")
+    done
+}
+
+
 (( $+functions[_perforce_commands] )) ||
 _perforce_commands() {
+    (( ${#_perforce_cmd_list} )) || _perforce_gen_cmd_list
     _describe -t p4-commands 'Perforce command' _perforce_cmd_list
 }
 
@@ -331,7 +354,7 @@
 _perforce_branches() {
     local bline match mbegin mend
     local -a bl
-    bl=(${${${(f)"$(_call_program branches p4 branches 2>/dev/null)"}##Branch }/ /:})
+    bl=(${${${(f)"$(_perforce_call_p4 branches branches 2>/dev/null)"}##Branch }/ /:})
     [[ $#bl -eq 1 && $bl[1] = '' ]] && bl=()
     (( $#bl )) && _describe -t branches 'Perforce branch' bl
 }
@@ -351,7 +374,7 @@
 	 [[ $PREFIX = (|*[^[:digit:]])(#b)(<->) ]] && num+=$match[1]
 	 [[ $SUFFIX = (#b)(<->)* ]] && num+=$match[1]
 	 if [[ -n $num ]]; then
-	     _message -r "$(_call_program describe p4 describe $num)"
+	     _message -r "$(_perforce_call_p4 describe describe $num)"
 	     return 0
 	 fi
     elif [[ ${NUMERIC:-0} -gt 0 ]]; then
@@ -385,7 +408,7 @@
     # Limit to the 20 most recent changes by default to avoid huge
     # output.
     cl=(
-${${${${(f)"$(_call_program changes p4 changes -m ${max:-20} $cstatus \$file)"}##Change\ }//\ on\ /:}/\ by\ /\ }
+${${${${(f)"$(_perforce_call_p4 changes changes -m ${max:-20} $cstatus \$file)"}##Change\ }//\ on\ /:}/\ by\ /\ }
 "default:change not yet numbered")
     [[ $#cl -eq 1 && $cl[1] = '' ]] && cl=()
     _describe -t changes "${ctype}change" cl $comma
@@ -410,7 +433,7 @@
 	compset -P '//' && slash=(-S/ -q)
     fi
 
-    cl=(${${${(f)"$(_call_program clients p4 clients)"}##Client\ }/\ /:})
+    cl=(${${${(f)"$(_perforce_call_p4 clients clients)"}##Client\ }/\ /:})
     [[ $#cl -eq 1 && $cl[1] = '' ]] && cl=()
     _describe -t clients 'Perforce client' cl $slash
 }
@@ -421,7 +444,7 @@
     local cline match mbegin mend
     local -a cl
 
-    cl=(${${${(f)"$(_call_program counters p4 counters)"}/\ /:}/\=/current value})
+    cl=(${${${(f)"$(_perforce_call_p4 counters counters)"}/\ /:}/\=/current value})
     [[ $#cl -eq 1 && $cl[1] = '' ]] && cl=()
     _describe -t counters 'Perforce counter' cl
 }
@@ -430,7 +453,7 @@
 (( $+functions[_perforce_counter_values] )) ||
 _perforce_counter_values() {
     if [[ -n $words[CURRENT-1] ]]; then
-	 local value="$(_call_program counter p4 counter $words[CURRENT-1] 2>/dev/null)"
+	 local value="$(_perforce_call_p4 counter counter $words[CURRENT-1] 2>/dev/null)"
 	 if [[ -n $value ]]; then
 	     # No space.  This allows stuff like incarg and decarg.
 	     compstate[insert]=1
@@ -485,7 +508,7 @@
     local dline match mbegin mend max
     local -a dl
 
-    dl=(${${${(f)"$(_call_program depots p4 depots)"}##Depot\ }/\ /:})
+    dl=(${${${(f)"$(_perforce_call_p4 depots depots)"}##Depot\ }/\ /:})
     [[ $#dl -eq 1 && $dl[1] = '' ]] && dl=()
     _describe -t depots 'depot name' dl
 }
@@ -533,7 +556,7 @@
     local -a files
 
     compset -P '*/'
-    files=(${${${(f)"$(_call_program integrated p4 integrated \"\$pfx\*\$\{\(Q\)SUFFIX\}\" 2>/dev/null)"}%\#*}##*/})
+    files=(${${${(f)"$(_perforce_call_p4 integrated integrated \"\$pfx\*\$\{\(Q\)SUFFIX\}\" 2>/dev/null)"}%\#*}##*/})
     [[ $#files -eq 1 && $files[1] = '' ]] && files=()
     compadd "$@" -a files
 }
@@ -545,7 +568,7 @@
     local -a files
 
     compset -P '*/'
-    files=(${${${(f)"$(_call_program opened p4 opened \"\$pfx\*\$\{\(Q\)SUFFIX\}\" 2>/dev/null)"}%\#*}##*/})
+    files=(${${${(f)"$(_perforce_call_p4 opened opened \"\$pfx\*\$\{\(Q\)SUFFIX\}\" 2>/dev/null)"}%\#*}##*/})
     [[ $#files -eq 1 && $files[1] = '' ]] && files=()
     compadd "$@" -a files
 }
@@ -557,7 +580,7 @@
     local -a files
 
     compset -P '*/'
-    files=(${${${(f)"$(_call_program resolved p4 resolved \"\$pfx\*\$\{\(Q\)SUFFIX\}\" 2>/dev/null)"}%\#*}##*/})
+    files=(${${${(f)"$(_perfroce_call_p4 resolved resolved \"\$pfx\*\$\{\(Q\)SUFFIX\}\" 2>/dev/null)"}%\#*}##*/})
     [[ $#files -eq 1 && $files[1] = '' ]] && files=()
     compadd "$@" -a files
 }
@@ -578,7 +601,7 @@
     local -a files
 
     compset -P '*/'
-    files=(${"${(f)$(_call_program dirs p4 dirs \"\$pfx\*\$\{\(Q\)SUFFIX\}\" 2>/dev/null)}"##*/})
+    files=(${"${(f)$(_perforce_call_p4 dirs dirs \"\$pfx\*\$\{\(Q\)SUFFIX\}\" 2>/dev/null)}"##*/})
     [[ $#files -eq 1 && $files[1] = '' ]] && files=()
     compadd "$@" -S / -q -a files
 }
@@ -590,7 +613,7 @@
     local -a files
 
     compset -P '*/'
-    files=(${${${(f)"$(_call_program files p4 files \"\$pfx\*\$\{\(Q\)SUFFIX\}\" 2>/dev/null)"}%\#*}##*/})
+    files=(${${${(f)"$(_perforce_call_p4 files files \"\$pfx\*\$\{\(Q\)SUFFIX\}\" 2>/dev/null)"}%\#*}##*/})
     [[ $#files -eq 1 && $files[1] = '' ]] && files=()
     compadd "$@" -R _perforce_file_suffix -a files
 }
@@ -619,7 +642,7 @@
 	typeset -gA _perforce_client_list
 	local -a tmplist
 	local tmpelt
-	tmplist=(${${${(f)"$(_call_program clients p4 clients)"}##Client\ }%%\ *})
+	tmplist=(${${${(f)"$(_perforce_call_p4 clients clients)"}##Client\ }%%\ *})
 	[[ $#tmplist -eq 1 && $tmplist[1] = '' ]] && tmplist=()
 	for tmpelt in $tmplist; do
 	    _perforce_client_list[$tmpelt]=1
@@ -641,7 +664,7 @@
     else
 	# We need to look at the View stanza of the client record
 	# to see what directories exist in the client view.
-	_call_program client "p4 client -o $client" 2>/dev/null | while read line; do
+	_perforce_call_p4 client "client -o $client" 2>/dev/null | while read line; do
 	    case $line in
 		([[:blank:]]##) type=
 			        ;;
@@ -785,7 +808,7 @@
 	pfx="$match[1]"
 	pfx=${(e)~pfx}
 	omitpats=(
-	    ${${${${(f)"$(_call_program files p4 files \"\$pfx\*\$\{\(Q\)SUFFIX\}\" 2>/dev/null)"}%\#*}##*/}//(#m)[][*?()<|^~#\\]/\\$MATCH}
+	    ${${${${(f)"$(_perforce_call_p4 files files \"\$pfx\*\$\{\(Q\)SUFFIX\}\" 2>/dev/null)"}%\#*}##*/}//(#m)[][*?()<|^~#\\]/\\$MATCH}
 	)
 
 	[[ $#omitpats -eq 1 && $omitpats[1] = '' ]] && omitpats=()
@@ -859,7 +882,7 @@
 
 (( $+functions[_perforce_groups] )) ||
 _perforce_groups() {
-    _describe -t groups 'Perforce group' $(_call_program groups p4 groups)
+    _describe -t groups 'Perforce group' $(_perforce_call_p4 groups groups)
 }
 
 
@@ -884,13 +907,13 @@
 	# prefix argument.  Instead of listing possible completions,
 	# show the full description for the job which is on the line at
 	# the moment.
-	_message -r "$(_call_program jobs p4 jobs -e \"Job=\$PREFIX\$SUFFIX\" -l 2>/dev/null)"
+	_message -r "$(_perforce_call_p4 jobs jobs -e \"Job=\$PREFIX\$SUFFIX\" -l 2>/dev/null)"
 	return 0
     elif [[ ${NUMERIC:-0} -gt 0 ]]; then
 	max=$NUMERIC
     fi
 
-    _call_program jobs p4 jobs -m ${max:-20} | while read jline; do
+    _perforce_call_p4 jobs jobs -m ${max:-20} | while read jline; do
 	if [[ $jline = (#b)([^[:blank:]]##)' '[^[:blank:]]##' '(*) ]]; then
 	    jl+=("${match[1]}:${match[2]}")
 	fi
@@ -921,7 +944,7 @@
 
     # According to the manual, `p4 jobspec' requires admin privileges.
     # If this is true even of `p4 jobspec -o', we are a bit screwed.
-    _call_program jobspec p4 jobspec -o 2>/dev/null | while read line; do
+    _perforce_call_p4 jobspec jobspec -o 2>/dev/null | while read line; do
 	case $line in
 	    ([[:blank:]]##) type=
 			    ;;
@@ -985,7 +1008,7 @@
     # May be completing after `@'.
     compset -P '*@'
 
-    _call_program labels p4 labels | while read lline; do
+    _perforce_call_p4 labels labels | while read lline; do
 	if [[ $lline = (#b)'Label '([^[:blank:]]##)' '(*) ]]; then
 	    ll+=("${match[1]}:${match[2]}")
 	fi
@@ -1016,7 +1039,7 @@
     if [[ -z $PREFIX || $PREFIX = <-> ]]; then
 	# always allowed (same as none)
 	rl+=(0)
-	_call_program filelog 'p4 filelog $pfx' 2>/dev/null | while read rline; do
+	_perforce_call_p4 filelog 'filelog $pfx' 2>/dev/null | while read rline; do
 	    if [[ $rline = (#b)'... #'(<->)' change '(*) ]]; then
 		rl+=("${match[1]}:${match[2]}")
 	    fi
@@ -1038,7 +1061,7 @@
     local jline match mbegin mend
     local -a statuses
 
-    _call_program jobspec p4 jobspec -o | while read jline; do
+    _perforce_call_p4 jobspec jobspec -o | while read jline; do
 	if [[ $jline = (#b)Status[[:blank:]]##(*/*) ]]; then
 	    statuses=(${(s./.)match[1]})
 	    break
@@ -1058,7 +1081,7 @@
     local line match mbegin mend expl
     local -a vars
 
-    _call_program help-environment p4 help environment | while IFS= read line; do
+    _perforce_call_p4 help-environment help environment | while IFS= read line; do
 	if [[ $line = $'\t'(#b)([A-Z][A-Z0-9_]##)* ]]; then
 	   vars+=($match[1])
 	fi
@@ -1361,8 +1384,9 @@
     if (( ! ${#_perforce_help_list} )); then
 	(( ${+_perforce_help_list} )) || typeset -ga _perforce_help_list
 	# All commands have help.
+	(( ${#_perforce_cmd_list} )) || _perforce_gen_cmd_list
 	_perforce_help_list=($_perforce_cmd_list)
-	_call_program help p4 help | while read -A hline; do
+	_perforce_call_p4 help help | while read -A hline; do
 	    if [[ $hline[1] = p4 && $hline[2] = help ]]; then
 		_perforce_help_list+=("$hline[3]:${hline[4,-1]}")
 	    fi

-- 
Peter Stephenson <pws@xxxxxxxxxxxxxxxxxxxxxxxx>
Work: pws@xxxxxxx
Web: http://www.pwstephenson.fsnet.co.uk



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