zsh-users
 help / color / mirror / code / Atom feed
* Improving spelling correction prompt to generate aliases for future use
@ 2007-10-21  3:39 Gwern Branwen
  2007-10-21 18:04 ` Peter Stephenson
  0 siblings, 1 reply; 4+ messages in thread
From: Gwern Branwen @ 2007-10-21  3:39 UTC (permalink / raw)
  To: zsh-users

[-- Attachment #1: Type: text/plain, Size: 1742 bytes --]

'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.

--
gwern
digicash RRF bemd Beach HRT GSM Blowpipe INR Zen AC

[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2007-10-21 22:59 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-10-21  3:39 Improving spelling correction prompt to generate aliases for future use Gwern Branwen
2007-10-21 18:04 ` Peter Stephenson
2007-10-21 21:45   ` Bart Schaefer
2007-10-21 22:22     ` Gwern Branwen

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).