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

Improving spelling correction prompt to generate aliases for future use

'lo everyone.

My desire is this: I have a function, 'typo', which is defined thusly:

 function typo () {
 	(typo_darcs "$@" &); #Subshell to insulate environment
 	alias $1=$2; } #now enable the typo for the current shell.
 function typo_darcs () {
 #So often I make little stupid typos while firing away
 #in the shell. So, I whipped up a quick shell script which
 #reads the two arguments provided, and constructs the appropriate
 #echo command to create an alias that solves that typo.
 	cd; #we need to be in a repository directory, which is ~/ since .ztypos is there
 	echo alias $1='"'$2'"' >> ~/.ztypos; #It goes typo wrong-command right-command
 	tail -n 1 ~/.ztypos & #Verify that .ztypos was written, with the right thing.
 	darcs record --compress --skip-long-comment --all --patch-name=".ztypos: alias $1="$2"" .ztypos; }

It basically makes an alias to fix a typo I've just made. This was very useful in Bash since there was no spelling correction. Now, I've only just recently switched from using Bash to using Zsh, and a little experience with spelling correction has convinced it that it would be excellent if, when I make a typo, I could get correction but also somehow have 'typo' be automatically run.

Looking into it, though, it is not very clear how to do this. I though one could perhaps modify SPROMPT to execute 'typo %R %r', but there doesn't seem to be any escape to run arbitrary shell commands. Precmd() also doesn't seem to work, since I don't see anyway for it to get access to %R, %r, or to know there is a misspelling going on at all. I asked around on #zsh, but no one seemed to really know and someone suggested emailing this list might help.

digicash RRF bemd Beach HRT GSM Blowpipe INR Zen AC

Attachment: pgpOfdZNjUrK3.pgp
Description: PGP signature

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