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

Re: Improving spelling correction prompt to generate aliases for future use



On Oct 21,  7:04pm, Peter Stephenson wrote:
}
} You could "setopt promptsubst" and have typo output the prompt (as
} well as whatever else it's doing)

I don't think that'll do what Gwern is after.  He wants to feed the
results (original and suggested replacement) of spelling correction
to "typo" as command-line arguments.

E.g. he wants to do

	typo ${(%):-%R} ${(%):-%r}

but he can't because prompt substitution in parameters doesn't have
access to the SPROMPT escapes.

The following works for simple commands but not loop constructs or other
compound commands:

accept-line() {
  emulate -L zsh
  local -a words
  words=(${(z)BUFFER})
  typeset -g ACCEPTED_CMD=$words[1]
  zle .accept-line "$@"
}
zle -N accept-line

preexec() {
  emulate -L zsh
  local -a words
  words=(${(z)1})
  if [[ $words[1] != $ACCEPTED_CMD ]]
  then
    typo $ACCEPTED_CMD $words[1]
  fi
}



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