3

I've had this problem for a while. Say in /home/me/ I have "cat3" as a directory. Now, in my Bash shell, I do "$ cat[tab]". My tab cycles through: cat, catchsegv, catman. But no "cat3". If I do "cd cat[tab]" then it immediately gives cat3. It's very annoying because sometimes I have a script "cat3/test.py" with 555 permission.

Ideally I want to type "c[tab]t[tab][enter]" to run the script. But I have to type "cat3/t[tab][enter]"...

How can I have tab consider directories & executable files inside the CWD, before it looks at stuff from /usr/bin or whatever?

Thank you for you help!

1
  • Have you considered typing ./c[tab] instead? Commented Jul 21, 2012 at 1:16

1 Answer 1

2

If cat3 is a directory, shell will not auto-complete it when you start as if you are going to execute a command in your path. a simple solution is to start with current directory symbol , i.e., '.':

$ ./c[tab] 

or, you could create a symbolic link in ~/bin to the script in cat3 and add ~/bin to your path:

export PATH=~/bin:$PATH 

if you really want to add current directory to your path, you can still do it (however, this is a really bad idea because at least it will surprise you when you want to auto-complete very frequently used commands):

export PATH=.:$PATH 
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks. "./" is easier than typing the whole thing. I'm surprised there isn't a "fix" for this... It's actually a case where I prefer not to add the dir to the PATH.
@AA: Typing cat3 wouldn't do anything, so why complete it? If you type ls cat<Tab>, then it should complete your directory's name. You could probably modify bash's completion to look for files in the local directory and prefix them with ./, but that's pretty complicated and messes with the common unix model of execute by PATH (variable) or path (absolute/relative).

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.