Monday, February 6, 2006

Bash completion

You know what's funny? I "grew up" using both Linux and Windows. Unlike most people, I find Windows a whole lot easier to use, a whole lot more stable, and generally a better day-to-day OS. Linux is fun to play with, but I get so aggravated trying to do the simplest stuff some days. It's just not worth the level of aggravation! The latest thing that was bugging me has also been bugging me for years, I just never got around to seeing if there was a solution. Turns out a solution's only been around for a short while anyway...

Believe it or not, there IS a command line in Windows. Not only that, but if you've got a clue it can be quite a powerful tool. Since NT 3.1, the shell processor of choice has been cmd.exe. Command.com was available, but it was a DOS-emulation mode that lacked certain features. The most important of these to me being command line completion. See, I type really fast. I think the last test I took had me at about 85 wpm. Not bad for someone who can't touchtype. :) The problem is, I can't type as fast as I can think, so anything that helps me type faster is critical.

Now, bash has command completion, too, but it works significantly different from the cmd.exe version. With cmd.exe, if I hit tab, it cycles through my choices. So, if I want to enter "cd \program files", I'd hit "cd \P-tab" and be there. Bash works the same, unless there's more than one file or directory that begins with "p" in the root. With cmd.exe, tabbing again would cycle through the "p" filenames and then I could hit enter to execute the command. With bash, it would bitch, then if I hit tab again it'll list all of the choices and then I have to continue to type until I've pretty much narrowed it down to the file I want.

Personally, I prefer the cmd.exe way of doing things. And, it's not because "that's what you're used to". I've used both shells over the years equally enough to make an informed decision, and I find the Windows version faster and easier. Apparently I'm alone in this thinking because in searching for a way to make bash act like cmd.exe I found a lot of people bitching about how it doesn't act like bash. Just yet another example of how *nix nerds are incapable of learning something that they're not used to. It's that whole "projection of shortcomings" thing. :)

Anywho, I did find the answer here. It seems it's a simple (and poorly documented) matter of adding the following four lines to your /etc/inputrc. In my case (currently using Gentoo, that's a story for another day), I didn't need to make any other changes than the addition of these. I've split the configs from the comments since Blogger squinches the pages down.

set completion-ignore-case on
# Ignore case when doing completion

set mark-directories on
# Completed dir names have a slash appended

set visible-stats on
# List ls -F for completion

"\C-i": menu-complete
# Cycle through ambiguous completions instead of list

#set show-all-if-ambiguous on
# List possible completions instead of ringing bell

You can edit the file and test it using bind -f /etc/inputrc to activate your changes immediately.

BTW, if your command shell doesn't currently support this feature, that's because it's disabled by default. Here's a post about enabling it, with the obligatory clueless and wrong Windows bashing (enabling this feature does NOT cause anything to crash. It never has, it never will. I've enabled and used this feature on literally THOUSANDS of Windows boxes and never had a problem with it).

1 comment:

  1. I know this is very old but it is exactly what i was looking for. THANKS

    ReplyDelete