Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
PATCH: Re: Expanding interactively aliases
- X-seq: zsh-workers 13566
- From: Sven Wischnowsky <wischnow@xxxxxxxxxxxxxxxxxxxxxxx>
- To: zsh-workers@xxxxxxxxxx
- Subject: PATCH: Re: Expanding interactively aliases
- Date: Mon, 5 Mar 2001 14:17:58 +0100 (MET)
- In-reply-to: Sven Wischnowsky's message of Mon, 26 Feb 2001 13:32:05 +0100 (MET)
- Mailing-list: contact zsh-workers-help@xxxxxxxxxx; run by ezmlm
Here is the current version of _expand_alias, to be committed soon.
I've slightly changed the styles it uses:
- regular - if regular aliases are to be expanded; may be set to
`always' to have them expanded everywhere
- global - if global aliases are to be expanded
- disabled - guess what
- complete - same as before (but now the cursor is left directly
after the completed alias name so that one can
immediately call _expand_alias again to expand it)
Bye
Sven
Index: Completion/Builtins/_aliases
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Builtins/_aliases,v
retrieving revision 1.2
diff -u -r1.2 _aliases
--- Completion/Builtins/_aliases 2000/05/31 09:38:26 1.2
+++ Completion/Builtins/_aliases 2001/03/05 13:14:26
@@ -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
Index: Completion/Core/_expand_alias
===================================================================
RCS file: _expand_alias
diff -N _expand_alias
--- /dev/null Mon Dec 11 17:26:27 2000
+++ _expand_alias Mon Mar 5 05:14:26 2001
@@ -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
+
Index: Doc/Zsh/compsys.yo
===================================================================
RCS file: /cvsroot/zsh/zsh/Doc/Zsh/compsys.yo,v
retrieving revision 1.105
diff -u -r1.105 compsys.yo
--- Doc/Zsh/compsys.yo 2001/01/15 09:11:33 1.105
+++ Doc/Zsh/compsys.yo 2001/03/05 13:14:30
@@ -958,6 +958,13 @@
`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 @@
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 @@
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 @@
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 @@
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
@@ -2560,6 +2598,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)))(
--
Sven Wischnowsky wischnow@xxxxxxxxxxxxxxxxxxxxxxx
Messages sorted by:
Reverse Date,
Date,
Thread,
Author