Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Patch: Add file types to _expand completions
- X-seq: zsh-workers 48214
- From: Marlon Richert <marlon.richert@xxxxxxxxx>
- To: Zsh hackers list <zsh-workers@xxxxxxx>
- Subject: Patch: Add file types to _expand completions
- Date: Sun, 21 Mar 2021 17:24:49 +0200
- Archived-at: <https://zsh.org/workers/48214>
- Archived-at: <http://www.zsh.org/sympa/arcsearch_id/zsh-workers/2021-03/CAHLkEDt_PBMT%2B2GjoC0JOXpm9j0P1_oqG7FWFsHt%2B8S0Ek26qg%40mail.gmail.com>
- List-id: <zsh-workers.zsh.org>
This adds file types to `_expand` completions, so they can be colored
through complist.
diff --git a/Completion/Base/Completer/_expand
b/Completion/Base/Completer/_expand
index def522a76..8e3a84f30 100644
--- a/Completion/Base/Completer/_expand
+++ b/Completion/Base/Completer/_expand
@@ -11,7 +11,7 @@ setopt localoptions nonomatch
[[ _matcher_num -gt 1 ]] && return 1
-local exp word sort expr expl subd suf=" " force opt asp tmp opre pre epre
+local exp word sort expr expl subd pref suf=" " force opt asp tmp opre pre epre
local continue=0
(( $# )) &&
@@ -214,9 +214,10 @@ else
normal=( "$normal[@]" "$i" )
fi
done
- (( $#dir )) && compadd "$expl[@]" -UQ -qS/ -a dir
- (( $#space )) && compadd "$expl[@]" -UQ -qS " " -a space
- (( $#normal )) && compadd "$expl[@]" -UQ -qS "" -a normal
+ pref="${${word:#[~/]*}:+$PWD}/"
+ (( $#dir )) && compadd "$expl[@]" -fW "$pref" -UQ -qS/ -a dir
+ (( $#space )) && compadd "$expl[@]" -fW "$pref" -UQ -qS " " -a space
+ (( $#normal )) && compadd "$expl[@]" -fW "$pref" -UQ -qS "" -a normal
fi
if _requested all-expansions; then
local disp dstr
diff --git a/Test/Y01completion.ztst b/Test/Y01completion.ztst
index f6474c4a1..463686633 100644
--- a/Test/Y01completion.ztst
+++ b/Test/Y01completion.ztst
@@ -44,6 +44,25 @@
>line: {: dir1/}{}
>line: {: dir2/}{}
+ comptest $': *\t\t\t\t\t\t\t'
+0:_expand shows file types
+>line: {: dir1/}{}
+>DESCRIPTION:{expansions}
+>DI:{dir1}
+>DI:{dir2}
+>FI:{file1}
+>FI:{file2}
+>DESCRIPTION:{all expansions}
+>NO:{dir1 dir2 file1 file2}
+>DESCRIPTION:{original}
+>NO:{*}
+>line: {: dir1/}{}
+>line: {: dir2/}{}
+>line: {: file1 }{}
+>line: {: file2 }{}
+>line: {: dir1 dir2 file1 file2 }{}
+>line: {: *}{}
+
comptesteval '_users () { compadd user1 user2 }'
comptest $': ~\t\t\t\t\t'
0:tilde
diff --git a/Test/comptest b/Test/comptest
index a36e301e0..cdb3ecc61 100644
--- a/Test/comptest
+++ b/Test/comptest
@@ -40,6 +40,7 @@ KEYTIMEOUT=1
setopt zle
autoload -U compinit
compinit -u
+zstyle ":completion:*" completer _expand _complete _ignored
zstyle ":completion:*:default" list-colors "no=<NO>" "fi=<FI>"
"di=<DI>" "ln=<LN>" "pi=<PI>" "so=<SO>" "bd=<BD>" "cd=<CD>" "ex=<EX>"
"mi=<MI>" "tc=<TC>" "sp=<SP>" "lc=<LC>" "ec=<EC>\n" "rc=<RC>"
zstyle ":completion:*" group-name ""
zstyle ":completion:*:messages" format "<MESSAGE>%d</MESSAGE>
@@ -50,9 +51,9 @@ zstyle ":completion:*:options" verbose yes
zstyle ":completion:*:values" verbose yes
setopt noalwayslastprompt listrowsfirst completeinword
zmodload zsh/complist
-expand-or-complete-with-report () {
- print -lr "<WIDGET><expand-or-complete>"
- zle expand-or-complete
+complete-word-with-report () {
+ print -lr "<WIDGET><complete-word>"
+ zle complete-word
print -lr - "<LBUFFER>$LBUFFER</LBUFFER>" "<RBUFFER>$RBUFFER</RBUFFER>"
zle clear-screen
zle -R
@@ -80,11 +81,11 @@ zle-finish () {
(( $+mark )) && print -lr "MARK: $mark"
zle accept-line
}
-zle -N expand-or-complete-with-report
+zle -N complete-word-with-report
zle -N list-choices-with-report
zle -N comp-finish
zle -N zle-finish
-bindkey "^I" expand-or-complete-with-report
+bindkey "^I" complete-word-with-report
bindkey "^D" list-choices-with-report
bindkey "^Z" comp-finish
bindkey "^X" zle-finish
Messages sorted by:
Reverse Date,
Date,
Thread,
Author