diff options
-rw-r--r-- | ChangeLog | 3 | ||||
-rw-r--r-- | Completion/Builtins/_aliases | 18 | ||||
-rwxr-xr-x | Completion/Core/_expand_alias | 48 | ||||
-rw-r--r-- | Doc/Zsh/compsys.yo | 52 |
4 files changed, 117 insertions, 4 deletions
diff --git a/ChangeLog b/ChangeLog index 3f50de897..33e877f85 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ 2001-03-05 Sven Wischnowsky <wischnow@zsh.org> + * 13566: Completion/Builtins/_aliases, Completion/Core/_expand_alias, + Doc/Zsh/compsys.yo: new _expand_aliases to, well, expand aliases + * 13565: Src/Zle/compmatch.c, Src/Zle/compresult.c, Test/54compmatch.ztst: fix for matching control, try harder to merge separately completed parts to avoid losing user-typed diff --git a/Completion/Builtins/_aliases b/Completion/Builtins/_aliases index 07e5dc5cb..db8e31678 100644 --- a/Completion/Builtins/_aliases +++ b/Completion/Builtins/_aliases @@ -1,7 +1,17 @@ #compdef alias unalias -local expl +local expl sel args opts -_alternative \ - 'aliases:regular alias:compadd -k aliases' \ - 'global-aliases:global alias:compadd -k galiases' +zparseopts -E -D s:=sel + +[[ -z $sel ]] && sel=rg + +opts=( "$@" ) + +args=() +[[ $sel = *r* ]] && args=( $args 'aliases:regular alias:compadd -k aliases' ) +[[ $sel = *g* ]] && args=( $args 'global-aliases:global alias:compadd -k galiases' ) +[[ $sel = *R* ]] && args=( $args 'disabled-aliases:disabled regular alias:compadd -k dis_aliases' ) +[[ $sel = *G* ]] && args=( $args 'disabled-global-aliases:disabled global alias:compadd -k dis_galiases' ) + +_alternative -O opts $args diff --git a/Completion/Core/_expand_alias b/Completion/Core/_expand_alias new file mode 100755 index 000000000..3809a834f --- /dev/null +++ b/Completion/Core/_expand_alias @@ -0,0 +1,48 @@ +#compdef -K _expand_alias complete-word \C-xa + +local word expl tmp pre sel what + +setopt localoptions ${_comp_options[@]} + +if [[ -n $funcstack[2] ]]; then + if [[ "$funcstack[2]" = _prefix ]]; then + word="$IPREFIX$PREFIX$SUFFIX" + else + word="$IPREFIX$PREFIX$SUFFIX$ISUFFIX" + fi + pre=() +else + local curcontext="$curcontext" + + if [[ -z "$curcontext" ]]; then + curcontext="expand-alias-word:::" + else + curcontext="expand-alias-word:${curcontext#*:}" + fi + + word="$IPREFIX$PREFIX$SUFFIX$ISUFFIX" + pre=(_main_complete - aliases) +fi + +zstyle -s ":completion:${curcontext}:" regular tmp || tmp=yes +case $tmp in +always) sel=r;; +yes|1|true|on) [[ CURRENT -eq 1 ]] && sel=r;; +esac +zstyle -T ":completion:${curcontext}:" global && sel="g$sel" +zstyle -t ":completion:${curcontext}:" disabled && sel="${sel}${(U)sel}" + +tmp= +[[ $sel = *r* ]] && tmp=$aliases[$word] +[[ -z $tmp && $sel = *g* ]] && tmp=$galiases[$word] +[[ -z $tmp && $sel = *R* ]] && tmp=$dis_aliases[$word] +[[ -z $tmp && $sel = *G* ]] && tmp=$dis_galiases[$word] + +if [[ -n $tmp ]]; then + $pre _wanted aliases expl alias compadd -UQ ${(Q)tmp%%[[:blank:]]##} +elif (( $#pre )) && zstyle -t ":completion:${curcontext}:" complete; then + $pre _aliases -s "$sel" -S '' +else + return 1 +fi + diff --git a/Doc/Zsh/compsys.yo b/Doc/Zsh/compsys.yo index d3f86b203..de6c9e73e 100644 --- a/Doc/Zsh/compsys.yo +++ b/Doc/Zsh/compsys.yo @@ -958,6 +958,13 @@ process IDs in the following lines. If the line does not contain `tt(PID)', the first numbers in each of the other lines are taken as the process IDs to complete. ) +kindex(complete, completion style) +item(tt(complete))( +This is used by the tt(_expand_alias) function when invoked as a +bindable command. If it set to `true' and the word on the command +line is not the name of an alias, matching alias names will be +completed. +) kindex(completer, completion style) item(tt(completer))( The strings given as the value of this style provide the names of the @@ -1000,6 +1007,12 @@ This style is used by the tt(_list) completer function to decide if insertion of matches should be delayed unconditionally. The default is `true'. ) +kindex(disabled, completion style) +item(tt(disabled))( +If this is set to `true', the tt(_expand_alias) completer and bindable +command will try to expand disabled aliases, too. The default is +`tt(false)'. +) kindex(disable-stat, completion style) item(tt(disable-stat))( This is used with an empty tag by the function completing for the @@ -1184,6 +1197,11 @@ it is set to `true' (the default), globbing will be attempted on the words resulting from substitution (see the tt(substitute) style) or the original string from the line. ) +kindex(global, completion style) +item(tt(global))( +If this is set to `true' (the default), the tt(_expand_alias) +completer and bindable command will try to expand global aliases. +) kindex(group-name, completion style) item(tt(group-name))( The completion system can put different types of matches in different @@ -1720,6 +1738,15 @@ setting the completer field in the context name to tt(correct-)var(num) or tt(approximate-)var(num), where var(num) is the number of errors that were accepted. ) +kindex(regular, completion style) +item(tt(regular))( +This style is used by the tt(_expand_alias) completer and bindable +command. If is set to `true' (the default) regular alias will be +expanded only in command position. If it is set to `false', regular +aliases will never be expanded and if it is set to the string +`tt(always)', regular aliases will be expanded even if not in command +position. +) kindex(packageset, completion style) item(tt(packageset))( This style is used when completing arguments of the Debian `tt(dpkg)' @@ -2389,6 +2416,17 @@ When tt(_expand) is called as a function, the different modes may be selected with options. The tt(-s) to tt(substitute), tt(-g) to tt(glob) and tt(-o) to tt(subst-globs-only). ) +findex(_expand_alias) +item(tt(_expand_alias))( +If the word the cursor is on is an alias, it is expanded and no other +completers are called. Which types of aliases are to be expanded can +be controlled with the tt(regular), tt(global) and tt(disabled) +styles. + +This function is also a bindable command, see +ifzman(the section `Bindable Commands' below)\ +ifnzman(noderef(Bindable Commands)). +) findex(_history) item(tt(_history))( Complete words from the shell's command history. This completer @@ -2561,6 +2599,20 @@ completions as possible choices. This stores the string `tt(correct-word)' in the var(function) field of the context name and then calls the tt(_correct) completer. ) +findex(_expand_alias (^Xa)) +item(tt(_expand_alias (^Xa)))( +This function can be used as a completer and as a bindable command. +It expands the word the cursor on if it is an alias. The types of +aliases used can be controlled with the tt(regular), tt(global) and +tt(disabled) styles. + +When used as a bindable command there is one additional feature that +can be selected by setting the tt(complete) style to `true'. In this +case, if the word isn't the name of an alias, tt(_expand_alias) tries +to complete the word to an full alias name without expanding it (but +leaving the cursor directly after the completed word so that invoking +tt(_expand_alias) once more will expand the now-complete alias name). +) findex(_expand_word (^Xe)) item(tt(_expand_word (^Xe)))( Performs expansion on the current word: equivalent to the standard |