about summary refs log tree commit diff
path: root/Completion
diff options
context:
space:
mode:
authorSven Wischnowsky <wischnow@users.sourceforge.net>2001-03-05 13:18:59 +0000
committerSven Wischnowsky <wischnow@users.sourceforge.net>2001-03-05 13:18:59 +0000
commit3e6563dd039f84990060674890c9ce9b32fd68ce (patch)
treed8ad4f2cc3743764bd59e5601ba28ea4527c0c45 /Completion
parenteb41692bc56f22c7587426c4e5fa3c75ea0dfeab (diff)
downloadzsh-3e6563dd039f84990060674890c9ce9b32fd68ce.tar.gz
zsh-3e6563dd039f84990060674890c9ce9b32fd68ce.tar.xz
zsh-3e6563dd039f84990060674890c9ce9b32fd68ce.zip
new _expand_aliases to, well, expand aliases (13566)
Diffstat (limited to 'Completion')
-rw-r--r--Completion/Builtins/_aliases18
-rwxr-xr-xCompletion/Core/_expand_alias48
2 files changed, 62 insertions, 4 deletions
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
+