How to make bash tab-completion work like windows' cmd.exe?
Asked Answered
D

1

12

Say I have a folder with files in it with names like this:

  • log_1.log
  • log_2.log
  • log_2.gz

And I want to perform some operation, let's say move, on log_2.gz.

In Windows cmd.exe, I am used to performing these steps:

  1. Type move (and nothing else)
  2. tabtabtab to traverse the tab-complete options until I get to log_2.gz
  3. Type destination

But in bash shell (within iTerm2 on Mac OS X 10.8.3), I have to do something like this:

  1. Type mv l
  2. tab which takes me to log_ and makes an annoying beep sound
  3. Type 2
  4. tab which takes me to log_2. and makes an annoying beep sound
  5. Type g
  6. tab which takes me to log_2.gz and is satisfyingly silent
  7. Type destination

As you can see, bash requires many more steps even when you know the destination filename, but imagine a scenario where you are not really certain what exactly is in the filename (maybe the ls was too long). I often find myself in this scenario after a few tab + typing and am forced to abandon the command, run ls again, copy the filename, maybe even run a pwd to concatenate with the folder, and then resume where I left off. This is very annoying.

Daladier answered 29/5, 2013 at 5:4 Comment(3)
If you had 50 files in your folder you'd be hitting tab on average 25 times, but with bash's partial completion you're going to be hitting the tab key a lot less on average. Your case above is skewed to the minority of cases where find the file using cmd.exe tab is quicker.Rojas
I disagree with your assumption of which cases are minority.Daladier
Try zsh, with the menucomplete (I think) optionManteau
Q
13

You can add the following in your .inputrc (if you don't have one, then create it) file. Once added, either source the file or logout and log back in.

set show-all-if-ambiguous on
set completion-ignore-case on
TAB: menu-complete
Quantic answered 29/5, 2013 at 5:28 Comment(5)
Nice! I realized a new scenario: In windows when I type cd <kbd>tab</kbd> it will only cycle thru directories, so it's smart about file-types. Any tips on this?Daladier
This link should be a good source. gnu.org/software/bash/manual/html_node/…Quantic
I love this--the new scenario I'd like is to skip the .hidden files. I have way too many of those. But if I know at least the first character of the file I'm interested in, I know I won't be tabbing more than 7 times before trying another way! Thanks!Dancy
The show-all-if-ambiguous option can be useful, but deviates from what Windows does.Intermission
NOTE: if you create ~/.inputrc, be sure to $include /etc/inputrc at the top, otherwise the user's copy will just override the system one.Intermission

© 2022 - 2024 — McMap. All rights reserved.