zsh-users
 help / color / mirror / code / Atom feed
From: Gwern Branwen <gwern0@gmail.com>
To: zsh-users@sunsite.dk
Subject: Improving spelling correction prompt to generate aliases for future use
Date: Sat, 20 Oct 2007 23:39:59 -0400	[thread overview]
Message-ID: <20071021033959.GA4471@localhost> (raw)

[-- 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 --]

             reply	other threads:[~2007-10-21 22:57 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-10-21  3:39 Gwern Branwen [this message]
2007-10-21 18:04 ` Peter Stephenson
2007-10-21 21:45   ` Bart Schaefer
2007-10-21 22:22     ` Gwern Branwen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20071021033959.GA4471@localhost \
    --to=gwern0@gmail.com \
    --cc=zsh-users@sunsite.dk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).