Bash – Open any .c file with Sublime Text using a terminal command

bashfile opening

The IDE that I use is Sublime Text 3.

If I want to open a file through a terminal with Sublime Text, I have to type:

subl <file>.c

I want to edit my .bashrc so that any .c file automatically opens in Sublime Text. How do I do this?

Example:

> test.c

test.c now opens in Sublime Text.

Best Answer

This won't work under normal circumstances. Only way I could think of is logging each command to a file (e.g. with script and a modified PS1 for bash to rewrite is at any command) and then parse this log file at each new line (e.g. further modify PS1) for some regex ending in .c to start sublime.

Does not sound like it would be worth the time, maybe some alias s="subl " in .bashrc would make you more happy, combined with tab completion it should be a bit easier for you already.

Related Question