You are not logged in.

#1 2011-08-26 03:22:50

Enunes
Member
Registered: 2009-08-06
Posts: 11

Automatically handling interactive terminal typos

Hey,

I create this thread in the hopes to get some ideas and opinions in this problem/solution I have.

I often do some code in my Arch Linux, and while typing fast I just hate when I do a typo for example with 'make' and this happens:

[erico@hp 23:48:25 ~]$ maek
bash: maek: command not found

So my solution so far has been to add these to my .bashrc:

alias exir='exit'
alias exti='exit'
alias xeit='exit'
alias xeti='exit'
alias exi='exit'
alias xiet='exit'
alias xtie='exit'
alias txie='exit'
alias teix='exit'
alias maek='make'
alias mkae='make'
alias amek='make'
alias amke='make'
alias aemk='make'

Well, I think you get it.

I have a few issues with this though. It turns out I have to specify an alias for each character permutation of the command in question.
Also, if I ever download some program named "amke", I'd probably have some conflict with my current alias.

I've been thinking on some way to "automatize" this process.
While automating it, I could also try to make it more safe to this eventual conflict with other commands.

So first of all, is there already any solution for this?

If not, I'd like to have some opinions on a solution, and also some feedback like if you would ever use something like this and why/whynot.
I'd then go and implement it.

Solutions I can think of are to create aliases or symbolic links to the apps.
Right now I think aliases would he harder to handle.
The user should be able to control which commands are actually supposed to become "typo-safe".
A possible solution could be:

1- in a file, the user lists all the commands he/she would like to track / turn typosafe;
2- run a program which takes each of these commands, generate all the character permutations (how to make this more dynamic and adaptable to a user installing/uninstalling packages this tracks?)
3- maybe also (maybe user tunable), there could be some handling for keys close each other (the case of "exir" for "exit").
4- then maybe I could generate symbolic links for all the possible permutations **if** I added all of them to a single directory (where should I drop this directory? /usr/share/typos ? /usr/bin/typos ?) which is placed as **last** in the $PATH variable.
This way, if I install another program which is located in a more serious directory such as /usr/bin, it would have precedence.

I'm not sure if this would be easy cleanable when the user uninstalls my package.
Though I can't figure out a way to do it with aliases (because of the conflicting names thing).

What do you think?
Thanks in advance! smile

Offline

#2 2011-08-26 04:17:23

tuxg
Member
Registered: 2011-07-15
Posts: 11

Re: Automatically handling interactive terminal typos

You can use Zsh
I don't use it, but I heard that it has this function built-in wink

in .zshrc add: setopt CORRECT

Last edited by tuxg (2011-08-26 04:20:45)

Offline

#3 2011-08-26 04:31:26

brebs
Member
Registered: 2007-04-03
Posts: 3,742

Re: Automatically handling interactive terminal typos

Too dangerous and unreliable. Example off the top of my head:

What if you wanted to type "cp", but typed "rp", and it was auto-corrected to "rm"?

If you can't type 4 characters correctly, then lay off the caffeine, slow down, have a nap, and/or try a touch-typing tutor program wink

Offline

#4 2011-08-26 05:00:24

lolilolicon
Member
Registered: 2009-03-05
Posts: 1,722

Re: Automatically handling interactive terminal typos

Enunes wrote:

Also, if I ever download some program named "amke", I'd probably have some conflict with my current alias.

So, if you have the command "amke" and "make", what do you mean by the typo "maek"? wink
My opinion is this typo-auto-correction idea is unreliable, confusing, abusive, and horrible.
The solution? Practice your typing already!

P.S. The `cdspell' and `dirspell' shopts can be used for directory name corrections for BASH, which I still don't use at all. I don't want the machine to correct me! Absolutely not automatically silently!


This silver ladybug at line 28...

Offline

#5 2011-08-26 05:34:26

brebs
Member
Registered: 2007-04-03
Posts: 3,742

Re: Automatically handling interactive terminal typos

Add this to ~/.bashrc

# Show the list at first TAB, instead of beeping and waiting for a second TAB
set show-all-if-ambiguous on

# Complete things that have been typed in the wrong case
# From http://www.ukuug.org/events/linux2003/papers/bash_tips/
set completion-ignore-case on

# When listing possible file completions, put / after directory names and * after programs
set visible-stats on

Then use the tab button for auto-completion.

Last edited by brebs (2011-08-26 05:39:00)

Offline

#6 2011-08-26 14:30:48

Cyrusm
Member
From: Bozeman, MT
Registered: 2007-11-15
Posts: 1,053

Re: Automatically handling interactive terminal typos

yeah, I can understand setting aliases for a few very common typo's. I've seen this done by many people. however I feel that tab completion is probably the best solution. that and slowing down a little bit.   Personally I always try and stop/think anytime I hit the enter key. I mean, what will slow you down more? slowing down to type correctly? or fixing something you messed up by entering the wrong command?


Hofstadter's Law:
           It always takes longer than you expect, even when you take into account Hofstadter's Law.

Offline

#7 2011-08-26 19:59:15

fogobogo
Member
Registered: 2008-08-24
Posts: 83

Re: Automatically handling interactive terminal typos

Offline

#8 2011-08-26 23:06:29

Yannick_LM
Member
Registered: 2008-12-22
Posts: 142

Re: Automatically handling interactive terminal typos

I don't want the machine to correct me! Absolutely not automatically silently!

Zsh won't do it silently: rather:

mkae clean all 
zsh: correct 'mkae' to 'make' [nyae]? 

y: accept correction, (so make clean all will be executed)
n: refuse, so you'll get 'mkae: command not found)
a: abort: clean line and start again
e: edit the line and try again.


Not sure what can go wrong with this....

Offline

#9 2011-08-28 03:55:55

Enunes
Member
Registered: 2009-08-06
Posts: 11

Re: Automatically handling interactive terminal typos

Hey back and thank you for your answers so far!

What I mean for a feature is for the user to provide a list of commands to automatically generate an "alias list" like mine.
I don't want the machine to correct me silently and against my will either!
Especially for commands that can even remotely be translated to "rm" or "cp"!
Creating conflicts, like having actual programs "make" and "amke", is also probably a bad use for a feature like this and should be, at least, warned.
Generating alias typo commands for every command is, agreed, an excellent example of a horrible feature.
I guess I could have made up a better topic title though.
As for taking care/typing carefully, I suppose many developers do get a bit stressed or faster when hunting some hard-to-catch bug.
I believe that, if carefully fit to the user needs, this can be helpful.

Also, tab handling isn't quite useful for small commands or fast to type like make.
make usually won't be a system-killing or something like that if run mistakenly.

I'll check zsh and those bash features to check if they suit my needs and report back.
I look for something that can be finetuned and not for something that will warn me on typos I don't want to handle or detect.
The time taken to answer a character such as the one in Yannick_LM's post kinda defeats the purpose though.

fogobobo, that's a nice related topic, I hadn't considered algorithms for checking "distance".
I suppose that, in this case, the distance between keyboard keys (on a qwerty keyboard for instance) is more important so the algorithm needs to be adapted.

Offline

Board footer

Powered by FluxBB