summaryrefslogtreecommitdiff
path: root/Completion/Base
diff options
context:
space:
mode:
Diffstat (limited to 'Completion/Base')
-rw-r--r--Completion/Base/Completer/_expand2
-rw-r--r--Completion/Base/Completer/_external_pwds39
-rw-r--r--Completion/Base/Completer/_history7
-rw-r--r--Completion/Base/Core/_main_complete38
-rw-r--r--Completion/Base/Utility/_arguments2
-rw-r--r--Completion/Base/Utility/_call_program4
-rw-r--r--Completion/Base/Utility/_describe35
-rw-r--r--Completion/Base/Utility/_sequence22
-rw-r--r--Completion/Base/Utility/_store_cache11
-rw-r--r--Completion/Base/Widget/_complete_debug2
10 files changed, 119 insertions, 43 deletions
diff --git a/Completion/Base/Completer/_expand b/Completion/Base/Completer/_expand
index e52144cb7..3c76e1328 100644
--- a/Completion/Base/Completer/_expand
+++ b/Completion/Base/Completer/_expand
@@ -87,7 +87,7 @@ if [[ "$force" = *s* ]] ||
setopt aliases
eval 'exp=( ${${(e)exp//\\[
-]/ }//(#b)([
+]/ }//(#b)([ \\
])/\\$match[1]} )' 2>/dev/null
setopt NO_aliases
else
diff --git a/Completion/Base/Completer/_external_pwds b/Completion/Base/Completer/_external_pwds
new file mode 100644
index 000000000..4ad50f02b
--- /dev/null
+++ b/Completion/Base/Completer/_external_pwds
@@ -0,0 +1,39 @@
+#autoload
+
+# Completes current directories of other zsh processes
+# this is intended to be used via _generic bound to a
+# different key. Note that pattern matching is enabled.
+
+local -a expl
+local -au dirs
+
+# undo work _main_complete did to remove the tilde
+PREFIX="$IPREFIX$PREFIX"
+IPREFIX=
+SUFFIX="$SUFFIX$ISUFFIX"
+ISUFFIX=
+
+[[ -o magicequalsubst ]] && compset -P '*='
+
+case $OSTYPE in
+ solaris*)
+ dirs=(
+ ${(M)${${(f)"$(pgrep -U $UID -x zsh|xargs pwdx 2>/dev/null)"}:#$$:*}%%/*}
+ )
+ ;;
+ linux*)
+ dirs=( /proc/${^$(pidof zsh):#$$}/cwd(N:A) )
+ dirs=( $^dirs(N^@) )
+ ;;
+ *)
+ if (( $+commands[lsof] )); then
+ dirs=( ${${${(M)${(f)"$(lsof -a -u $EUID -c zsh -p \^$$ -d cwd -F n -w
+ 2>/dev/null)"}:#n*}#?}%% \(*} )
+ fi
+ ;;
+esac
+dirs=( ${(D)dirs} )
+
+compstate[pattern_match]='*'
+_wanted directories expl 'current directory from other shell' \
+ compadd -M "r:|/=* r:|=*" -f -a dirs
diff --git a/Completion/Base/Completer/_history b/Completion/Base/Completer/_history
index 63878ac1c..cd69ca17b 100644
--- a/Completion/Base/Completer/_history
+++ b/Completion/Base/Completer/_history
@@ -51,9 +51,14 @@ ISUFFIX=
# We skip the first element of historywords so the current word doesn't
# interfere with the completion
+local -a hslice
while [[ $compstate[nmatches] -eq 0 && beg -lt max ]]; do
+ if [[ -n $compstate[quote] ]]
+ then hslice=( ${(Q)historywords[beg,beg+slice]} )
+ else hslice=( ${historywords[beg,beg+slice]} )
+ fi
_wanted "$opt" history-words expl 'history word' \
- compadd -Q -a 'historywords[beg,beg+slice]'
+ compadd -Q -a hslice
(( beg+=slice ))
done
diff --git a/Completion/Base/Core/_main_complete b/Completion/Base/Core/_main_complete
index e881ea6a1..977ab49ee 100644
--- a/Completion/Base/Core/_main_complete
+++ b/Completion/Base/Core/_main_complete
@@ -43,6 +43,8 @@ local -a precommands
typeset -U _lastdescr _comp_ignore _comp_colors
+{
+
[[ -z "$curcontext" ]] && curcontext=:::
zstyle -s ":completion:${curcontext}:" insert-tab tmp || tmp=yes
@@ -66,6 +68,16 @@ if [[ "$compstate[insert]" = tab* ]]; then
compstate[insert]="${compstate[insert]//tab /}"
fi
+# Second attempt at GLOB_COMPLETE
+
+if [[ "$compstate[pattern_match]" = "*" &&
+ "$_lastcomp[unambiguous]" = "$PREFIX" &&
+ -n "$_lastcomp[unambiguous_cursor]" ]]; then
+ integer upos="$_lastcomp[unambiguous_cursor]"
+ SUFFIX="$PREFIX[upos,-1]$SUFFIX"
+ PREFIX="$PREFIX[1,upos-1]"
+fi
+
# Special completion contexts after `~' and `='.
if [[ -z "$compstate[quote]" ]]; then
@@ -128,8 +140,11 @@ _completer_num=1
# We assume localtraps to be in effect here ...
integer SECONDS=0
-trap 'zle -M "Killed by signal in ${funcstack[0]} after ${SECONDS}s";
- zle -R; return 130' INT QUIT
+TRAPINT TRAPQUIT() {
+ zle -M "Killed by signal in ${funcstack[2]} after ${SECONDS}s";
+ zle -R
+ return 130
+}
# Call the pre-functions.
@@ -346,17 +361,20 @@ fi
( "$_comp_force_list" = ?* && nm -ge _comp_force_list ) ]] &&
compstate[list]="${compstate[list]//messages} force"
-if [[ "$compstate[old_list]" = keep ]]; then
- if [[ $_saved_colors_set = 1 ]]; then
- ZLS_COLORS="$_saved_colors"
+} always {
+ # Stuff we always do to clean up.
+ if [[ "$compstate[old_list]" = keep ]]; then
+ if [[ $_saved_colors_set = 1 ]]; then
+ ZLS_COLORS="$_saved_colors"
+ else
+ unset ZLS_COLORS
+ fi
+ elif (( $#_comp_colors )); then
+ ZLS_COLORS="${(j.:.)_comp_colors}"
else
unset ZLS_COLORS
fi
-elif (( $#_comp_colors )); then
- ZLS_COLORS="${(j.:.)_comp_colors}"
-else
- unset ZLS_COLORS
-fi
+}
# Now call the post-functions.
diff --git a/Completion/Base/Utility/_arguments b/Completion/Base/Utility/_arguments
index d70c44259..1f35e8d43 100644
--- a/Completion/Base/Utility/_arguments
+++ b/Completion/Base/Utility/_arguments
@@ -26,7 +26,7 @@ if (( long )); then
if (( ! ${(P)+name} )); then
local iopts sopts pattern tmpo dir cur cache
- typeset -U lopts
+ typeset -Ua lopts
cache=()
diff --git a/Completion/Base/Utility/_call_program b/Completion/Base/Utility/_call_program
index b65764827..010e09476 100644
--- a/Completion/Base/Utility/_call_program
+++ b/Completion/Base/Utility/_call_program
@@ -2,8 +2,8 @@
local tmp err_fd=-1
-if (( ${debug_fd:--1} > 2 ))
-then exec {err_fd}>&2 # debug_fd is saved stderr, 2 is log file
+if (( ${debug_fd:--1} > 2 )) || [[ ! -t 2 ]]
+then exec {err_fd}>&2 # debug_fd is saved stderr, 2 is trace or redirect
else exec {err_fd}>/dev/null
fi
diff --git a/Completion/Base/Utility/_describe b/Completion/Base/Utility/_describe
index 1a9f52f5d..ab7200517 100644
--- a/Completion/Base/Utility/_describe
+++ b/Completion/Base/Utility/_describe
@@ -6,23 +6,28 @@ local _opt _expl _tmpm _tmpd _mlen _noprefix
local _type=values _descr _ret=1 _showd _nm _hide _args _grp _sep
local csl="$compstate[list]" csl2
local _oargv _argv _new _strs _mats _opts _i _try=0
+local OPTIND OPTARG
+local -a _jvx12
# Get the option.
-if [[ "$1" = -o ]]; then
- _type=options
- shift
-elif [[ "$1" = -O ]]; then
- _type=options
- _noprefix=1
- shift
-elif [[ "$1" = -t ]]; then
- _type="$2"
- shift 2
-elif [[ "$1" = -t* ]]; then
- _type="${1[3,-1]}"
- shift
-fi
+while getopts "oOt:12JVx" _opt; do
+ case $_opt in
+ (o)
+ _type=options;;
+ (O)
+ _type=options
+ _noprefix=1
+ ;;
+ (t)
+ _type="$OPTARG"
+ ;;
+ (1|2|J|V|x)
+ _jvx12+=(-$_opt)
+ esac
+done
+shift $(( OPTIND - 1 ))
+unset _opt
[[ "$_type$_noprefix" = options && ! -prefix [-+]* ]] && \
zstyle -T ":completion:${curcontext}:options" prefix-needed &&
@@ -53,7 +58,7 @@ fi
_tags "$_type"
while _tags; do
- while _next_label "$_type" _expl "$_descr"; do
+ while _next_label $_jvx12 "$_type" _expl "$_descr"; do
if (( $#_grp )); then
diff --git a/Completion/Base/Utility/_sequence b/Completion/Base/Utility/_sequence
index 391e5f78f..f52955f46 100644
--- a/Completion/Base/Utility/_sequence
+++ b/Completion/Base/Utility/_sequence
@@ -7,11 +7,11 @@
# -s sep : specify separator [defaults to comma]
# -d : duplicate values allowed
-local curcontext="$curcontext" nm="$compstate[nmatches]" pre nosep minus
+local curcontext="$curcontext" nm="$compstate[nmatches]" pre qsep nosep minus
local -a sep num pref suf end uniq dedup
zparseopts -D -a opts s:=sep n:=num p:=pref i:=pref P:=pref I:=suf S:=suf q=suf r:=suf R:=suf C:=cont d=uniq M: J: X: x:
-(( $#cont )) && curcontext="$curcontext%:*}:$cont[2]"
+(( $#cont )) && curcontext="${curcontext%:*}:$cont[2]"
(( $#sep )) || sep[2]=,
if (( $+suf[(r)-S] )); then
@@ -19,20 +19,20 @@ if (( $+suf[(r)-S] )); then
(( $#end )) && compset -S ${end}\* && suf=() && nosep=1
fi
+qsep="${sep[2]}"
+compquote -p qsep
if (( ! $#uniq )); then
(( $+pref[(r)-P] )) && pre="${(q)pref[pref[(i)-P]+1]}"
- typeset -T unique="${PREFIX#$pre}" uniq $sep[2]
- dedup=( ${(q)uniq[1,-2]} )
- unique="${SUFFIX}"
- dedup+=( ${(q)uniq[2,-1]} )
+ dedup=( "${(@)${(@ps.$qsep.)PREFIX#$pre}[1,-2]}" "${(@)${(@ps.$qsep.)SUFFIX}[2,-1]}" )
+ [[ -n $compstate[quoting] ]] || dedup=( ${(Q)dedup} )
fi
-if (( ! $#num )) || (( num[2] > 1 )) && ! compset -P $(( num[2] - 1 )) \*$sep[2]; then
- (( nosep )) || suf=( -S $sep[2] -r "$end[1]${sep[2][1]} \t\n\-" )
- compset -S ${sep[2]}\* && suf=()
- compset -P \*$sep[2] && pref=()
-else
+if (( $#num )) && compset -P $(( num[2] - 1 )) \*${(q)qsep}; then
pref=()
+else
+ (( ! nosep && (!$#num || num[2] > 1) )) && suf=( -S ${qsep} -r "$end[1]${(q)qsep[1]} \t\n\-" )
+ compset -S ${(q)qsep}\* && suf=()
+ compset -P \*${(q)qsep} && pref=()
fi
(( minus = argv[(ib:2:)-] ))
diff --git a/Completion/Base/Utility/_store_cache b/Completion/Base/Utility/_store_cache
index 86e72e9a9..8feaee6f7 100644
--- a/Completion/Base/Utility/_store_cache
+++ b/Completion/Base/Utility/_store_cache
@@ -46,8 +46,15 @@ if zstyle -t ":completion:${curcontext}:" use-cache; then
for var; do
case ${(Pt)var} in
(*readonly*) ;;
- (*(association|array)*) print -r "$var=( ${(kv@Pqq)^^var} )";;
- (*) print -r "$var=${(Pqq)^^var}";;
+ (*(association|array)*)
+ # Dump the array as a here-document to reduce parsing overhead
+ # when reloading the cache with "source" from _retrieve_cache
+ print -r "$var=( "'"${(zQ)$(<<\EO:'"$var"
+ print -r "${(kv@Pqq)^^var}"
+ print -r "EO:$var"
+ print -r ')}" )'
+ ;;
+ (*) print -r "$var=${(Pqq)^^var}";;
esac
done >! "$_cache_dir/$_cache_ident"
else
diff --git a/Completion/Base/Widget/_complete_debug b/Completion/Base/Widget/_complete_debug
index 604486376..85a0f372a 100644
--- a/Completion/Base/Widget/_complete_debug
+++ b/Completion/Base/Widget/_complete_debug
@@ -9,6 +9,8 @@ local pager w="${(qq)words}"
integer debug_fd=-1
{
if [[ -t 2 ]]; then
+ zmodload -F zsh/files b:zf_ln 2>/dev/null &&
+ zf_ln -fn =(<<<'') $tmp &&
exec {debug_fd}>&2 2>| $tmp
fi