Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Expanding global aliases on key press (II)



Hi,

suggested by Bart Schafer I put this into my .zshrc:
##
autoload -Uz match-words-by-style
global-alias-space()
    { emulate -LR zsh
      match-words-by-style -w shell
      local ga=$matched_words[2]
      if [[ -n $ga ]]; then
          matched_words[2]="${${galiases[$ga]}:-$ga}"
          LBUFFER="${(j::)matched_words[1,3]}"; fi
      zle .self-insert;}

zle -N global-alias-space
bindkey ' ' global-alias-space

accept-line()
    { emulate -LR zsh
      match-words-by-style -w shell
      local ga=$matched_words[2]
      if [[ -n $ga ]]; then
          matched_words[2]="${${galiases[$ga]}:-$ga}"
          LBUFFER="${(j::)matched_words[1,3]}"; fi
      zle .accept-line;}

zle -N accept-line
##

This expands global aliases when I press Enter (and space) so that for 
instance
h -dE 0 G hex M
    is expanded to 
h -dE 0 | grep hex | most

which reads nicer and makes the sense more obvious. This works fine 
EXCEPT when I type something like this

jed M<uparrow>
    which is replaced from history to
jed Makefile  (with the cursor still being after the "M")
    now when I press enter this expands to 
jed | mostakefile  (which of course is nonsense)

Is there a way to modify Bart's above function so that expansion of 
global aliases is only done when the cursor is at the end of the line 
(or not "in" a word)?


Thorsten



Messages sorted by: Reverse Date, Date, Thread, Author