0

I’ve just set autocd in my .bash_profile:

shopt -s autocd

Now I can just type

$ some-directory

and automatically cd into it. Now, can I somehow tell Bash that if I enter not just a directory name, but a filename:

$ some-directory/file.txt

that I want it to open that file in an editor (e.g. Vim)? I don’t know that this would be a built-in option, but I’d hope that I could do it using clever scripting.

2
  • And what should do bash if file.txt has execute permission? :)
    – uzsolt
    Oct 13, 2015 at 18:37
  • I assume that it is possible, if you accept this kind of error before every edit: bash: some-directory/file.txt: No such file or directory
    – Cyrus
    Oct 14, 2015 at 5:51

1 Answer 1

0

Use this function in .bash_profile file

a {  cd YourExactPath/$1  }

Using this like that;

a YourFileName

So it navigates to YourExactPath/YourFileName .

Dont forget linux terminal uses $0 to run command so you can NOT navigate to file just writing your file name (if you add function which has same name as your file name, this maybe works but in my opinion you don't wanna add all of filename into .bash_profile.). I used a because it is shortest way to navigate into file. (NOT:I am not an expert so maybe there is a solution to solve your issue but at least I don't know how I will do.)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .