I have a somewhat uncomfortable keyboard on my laptop, resulting in that I sometimes misspell things in Bash and when pressing Tab for an auto-completion nothing happens.

Is it possible to have Bash guess what I meant to type, by for example when wanting to change directory to Documents and then mistyping cd ocum[TAB], given no other folder beginning with "ocum" is present, Bash interprets it as cd Documents/ since it is the closest possible action to do?

Or is this idea terribly complicated to achieve?

  • Guessing is hard for computers; could you come up with some patterns you’d like it to try? For example, substituting a missing initial character. – Jeff Schaller Jan 29 '18 at 0:02
  • I think in most cases this guessing mechanism would be helpful is when actually changing directories. That is when I type sluggish and in a hurry. Following the example above, cd *ments* does what I want. But using wildcards every time kind of beats the purpose of doing things fast. – E. l4d3 Jan 29 '18 at 15:56
  • 1
    It's not terribly complicated. The Z shell, if configured to do so, can do exactly the completion described in the question. – JdeBP Jan 30 '18 at 13:23
  • zstyle ':completion:*' matcher-list 'b:=*' – thrig Feb 11 '18 at 18:35

On github there's an 11K fuzzy_bash_completion script that appears to match some of the spec:

For example:

mkdir pizza
mkdir jazz
cd zz<TAB>
# displays `pizza' and `jazz'
rm -r jazz
cd zz<TAB>
# completes the word `pizza'
| improve this answer | |
  • I tested it, and it does the job – E. l4d3 Feb 8 '18 at 23:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.