How do I use the "did you mean" feature in ubuntu?
If I mistype a command in Ubuntu shell, it offers a suggestion. Often, the suggestion is right, and I wish to use it. But there is no way except to repeat the last command and make the changes yourself. Why doesn't it offer a yes/no type suggestion, where you can simply type y to accept the suggestion? Any suggestions to enable such a behaviour?
Here's what happens:
user@user:/media/tux$ git stastus
git: 'stastus' is not a git command. See 'git --help'.
Did you mean this?
status
user@user:/media/tux$
The suggestion in your example isn't provided by Ubuntu's shell, but rather is part of the help.autocorrect
feature built into Git itself.
There was discussion last year of adding an interactive "yes/no" prompt to Git, but some of the details were never decided upon so that work is still incomplete.
If you're looking for something to make this kind of suggestion for any command, you might like to try using the Z shell (zsh) instead of Bash. It offers general-purpose spelling correction for both commands and filenames, and provides an interactive prompt:
$ ehco hello > test.txt
zsh: correct 'ehco' to 'echo' [nyae]? y
$ cat tesst.txt
zsh: correct 'tesst.txt' to 'test.txt' [nyae]? y
hello
Changing shells isn't something to take lightly, though. By using any non-default shell you'll likely hit a few road bumps that will require time and effort to resolve.
The majority of Linux shells permit you to use the up-arrow key to scroll back through the list of commands you've recently typed, then you can edit it before pressing Enter to run the newly-modified line.
For Ubuntu, the default terminal shell is Bash, which supports this very effectively.
This seems to be something provided by the git command itself:
asb@asb-laptop:~$ git stastus
git: 'stastus' is not a git command. See 'git --help'.
Did you mean this?
status
asb@asb-laptop:~$ svn stastus
Unknown command: 'stastus'
Type 'svn help' for usage.
Although, Ubuntu does install command-not-found
by default. It give suggestions for miss-typed or uninstalled commands:
asb@asb-laptop:~$ foo
No command 'foo' found, did you mean:
Command 'zoo' from package 'zoo' (universe)
Command 'goo' from package 'goo' (universe)
Command 'xoo' from package 'xoo' (universe)
Command 'fio' from package 'fio' (universe)
Command 'fop' from package 'fop' (main)
Command 'fgo' from package 'fgo' (universe)
Command 'fox' from package 'objcryst-fox' (universe)
Command 'fog' from package 'ruby-fog' (universe)
foo: command not found