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

Re: VMS Style auto command-complition



On Thu, 25 Nov 2004, Ziggy wrote:

> For example - if I want to purge all the previous versions of all files
> in the directory, instead of typing 'PURGE' I can type 'PU' because
> there is no any other command that starts with PU
[...]
> %DCL-W-ABVERB, ambiguous command verb - supply more characters
> \P\

In the ambiguous case shown above, is it actually prompting you to input 
more characters, or is that just an error message?

There's a whole lot of subtlety that may be going on here -- for example, 
what happens if the command is part of a complex construct like a "while" 
loop, or is executed from a script or batch file? -- some of which it may 
not be possible to emulate without help from the OS.

However, you could try this:

----------
function conditional-accept-line {
  emulate -L zsh
  if [[ -z "$PREBUFFER" ]]
  then
    local -a words commands
    words=(${(z)BUFFER})
    if [[ $words[1] != *=* && $words[1] != [({})] ]] &&
       ! whence -w $words[1] > /dev/null
    then
      commands=(${${(f)"$(noglob whence -m ${words[1]}* 2>/dev/null)"}:#})
      case $#commands in
      (0) zle -M "no such command: $words[1]"; return 1;;
      (1) BUFFER=${BUFFER/$words[1]/$commands};;
      (*) zle -M "ambiguous: $words[1]"; return 1;;
      esac
    fi
  fi
  zle .accept-line
}

zle -N accept-line conditional-accept-line
----------

Note, however, that this disables zsh's "setopt correct" feature, because 
correction takes place only after the line has been accepted.



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