Windows Command Prompt (cmd) behaviour emulation in Linux terminal (Bash)

cmd / Terminal

Update 2008-03-25 @ 00:32: This post was originally titled "Emulate Command Prompt (cmd) tab auto-completion behaviour in Linux terminal (Bash)" (originally posted on 2008-03-20 @ 23:45), and have since been updated to cover more grounds.

Being a long time Windows command prompt (cmd) user, there are 2 things that the Linux terminal really annoyed me – tab auto-completion and case-sensitivity.

For instance, if you have "file-1.txt", "file-2.txt" and you do "fi[tab]", you’d get "file-", instead of "file-1.txt". And if you try doing something like "ls -l File*" you wouldn’t get anything returned…

Luckily, you can change the above behaviour by editing 2 files.

Tab-completion:

In order to get the windows command prompt’s tab-completion behaviour, you can edit / adding the following to "/etc/inputrc" (or "~/.inputrc"):

# Tab
TAB: menu-complete
# Shift-Tab (reverse menu-complete)
"e[Z": "e--t"

# Ignores the case of the letter
set completion-ignore-case on

According to the blog entry where I got this from, the "–" part of the Shift-TAB entry acts as an argument to the menu-complete function. In this case, it takes the previous entry of menu-complete.

Also, to enhance the terminal, you can also make the following amendments:

# The old style auto-complete (now mapped to Ctrl+space) - so you can still use it...
Control-SPACE: complete

# Automatically show everything instead of you having to press Ctrl+Space (as configured here) twice...
set show-all-if-ambiguous on
set show-all-if-unmodified on

# Display a "/" at the end for symlinked directories
set mark-symlinked-directories on

# Shut the bell up...
set bell-style none

Case-insensitive expansion ("globbing"):

If you want "ls -ld File*" to also display "file-1.txt", "file-2.txt", as well as "FiLe.txt" and "FILE.txt", you can add the following to "/etc/bash.bashrc":

# Disable case sensitive expansion - for command like "ls ld a*" to list "A_file"
# Note for things like "ls -ld a_file.txt", we still need to force it to glob by "ls -ld [a]_file.txt"
shopt -s nocaseglob

However, as mentioned in the comments, listing a complete filename is still sensitive – you’d have to force it to glob by doing "ls -ld [a]_file.txt".

If you know of any other useful modifications, drop me a comment!

Advertisements
Posted in Tips. 2 Comments »

2 Responses to “Windows Command Prompt (cmd) behaviour emulation in Linux terminal (Bash)”

  1. Unknown Says:

    Thanks for the post.
     
    Have you ever tried your Shift-Tab solution in the Bash in Cygwin?
     
    It doesn’t seem to work as it sees Shift-Tab just as a regular Tab. I did get it to work in Bash/Cygwin by mapping a different keystroke — I mapped Ctrl-Y to reverse menu complete. But, Shift-Tab would be way better.

  2. Kok-Yan Says:

    Unfortunately I’ve never used Cygwin…  I’ve only tried this on my Xubuntu install.Could it be that Cygwin doesn’t recognize shift-ed control character, as described here?


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: