When working on a rails app I like to open all of my files through the command line like so

CD my_app
gedit app/views/user/show.HTML.erb

Is there a way that I could shorten this so that I could just write something like

gedit  user_views/show.HTML.erb


I would like the console to stay in the main directory, I just don't like having to type out app/controller/user_controler.rb every time I want to open the user controller. I know that I could just open the file with my mouse, but I feel like moving from keyboard to mouse breaks my focus a little bit. When I can just tap away at the keyboard it seems like I have a more smooth workflow.

  • yeah I figured that, but since it had a little bit to do with ruby on rails I thought a programmer might have had the same problem. – Spencer Cooley Jun 20 '11 at 21:31
  • well, since it was moved perhaps consider accepting an answer on this or one of your other questions here on superuser. – matchew Jun 26 '11 at 17:28

Perhaps create a symbolic link from the main dir.

ln -s app/views/user/ user_views

will create a symbolic link in your main/working dir that will update the files in app/views/user. so doing an ls -l will show something like:

user_views -> app/views/user/

this way you could just go

$ gedit user_views/show.html.erb

also you could consider just setting a var


$ VIEWS='app/views/user/'

which would allow you to go

$ gedit $VIEWS/show.html.erb

you could consider putting this in your bash profile so it does not have to be re set each session.

more on symblic links

more on the bash profile and setting an environment variable.


On my walk home I wondered why someone would want a symbolic link to just jump one dir?


in this case the views dir. Are you aware of what tab will do?

I remember it took me a few months to learn this handy trick.

Type something like the following and hit tab

$ gedit a

hit tab, and it will likely complete app leaving you with

$ gedit app/

type v and hit tab again, likely you will get

$gedit app/views/

hit tab twice to list all possible choices. This works on utilities as well as dir and files.


$ ged

and hitting tab will complete gedit. This should speed you up a bit.

| improve this answer | |
  • I think symlinking works as long as your project doesn't reside too many levels deep in the filesystem. Otherwise, you might have to drill down through many levels before getting to the link, defeating the purpose. – phasetwenty Jun 20 '11 at 23:02
  • @phasetwenty, I agree. I also feel like symlinking to skip one dir is silly. If it was many dirs down or up and down I would argue strongly for symlinking. I edited my answer, and wonder if this may just be a case of not knowing what the [:tab:] key does. – matchew Jun 20 '11 at 23:10
  • ln is the better solution imo. – Vinicius Kamakura Jun 21 '11 at 0:14

Don't know if this helps, but there's a very rarely used shell variable called CDPATH. CDPATH is very much like the PATH variable for commands. When you do a cd, it searches the CDPATH for directories that match your CDPATH.

For example:


If I did:

cd jiff/source

The CD command would look for a ./jiff/source, then a /usr/local/jiff/source directory, then a $HONE/projects/jiff/source directory. If there's a $HOME/projects/jiff/source directory, the directory will change to there.

This won't solve your problem where you can simply type in a partial path, and have your command execute, but you could say add myapp/app/view to your CDPATH environment variable and do this:

$ cd user
$ gedit show.html.erb

The other thing you can do is alias the gedit command to _gedit, and then write a quick shell script to take the "file name", search for a directory tree that matches what you put, and then edit the file. This is something that Kornshell users do to get the equivalent of the PS1=\u@\h:\w PS prompt that you BASH users have. Add something like this to your .bashrc file:

alias _gedit=gedit

function gedit {
    fileName=$(basename $0)
    dirName=$(dirname $0)
    for directory in app/controller my_app/app/view
       if [[ -d "$directory/$dirName" ]]

Now, if you typed gedit user_controler.rb, and there's a file app/controler/user_controler.rb, it'll edit app/controller/user_controler.rb

| improve this answer | |

Take a look at Efficiently Navigating Directories on Unix which contains some useful Bash functions and aliases.

| improve this answer | |

Have you considered using shell variables?

user@localhost $ USERVIEWS='app/views/user/'
user@localhost $ gedit $USERVIEWS/show.html.erb
| improve this answer | |

If you have unique filenames, you can just do

gedit $(find -name show.html.erb)

The find will default to searching the current directory, and $() is equivalent to backticks, except that backticks are a deprecated shell feature in most modern shells. ;)

You could, of course, shorten that even more with a shell script along the lines of

gedit $( find -name "$1" )

And you could replace -name with -iname to save you the hassle of using the shift key if you have upper-case filenames.

I'm not sure how gedit behaves with multiple arguments (in case you don't have completely unique filenames), but with vim it'll go through the files one at a time. So you'd just ":q" until you got to the one you wanted. I'd expect gedit to open multiple tabs if you had multiple names. But I don't use graphical editors for the same reason you don't want to use the mouse to open the file. ;)

| improve this answer | |

Have you considered GMate? It's a selection of plugins for Gedit that make Rails development (amongst other things) significantly easier by making it look like Textmate. It solves your problem with the Fuzzy Open plugin. You open your project directory in Gedit (I think using the File Browser Pane plugin) and then press ctrl-shift-o to activate FuzzyOpen. Next, start typing some of the letters of the file you want, and FuzzyOpen matches these against files and directories in your project. For example, if you started typing:


it would find all files whose path has those letters in that order, e.g.


That same series of letters might also find things like:

Vendor/ImaplUgin/Stuff/SHOWmetHEmoney.rb etc.
| improve this answer | |

I had a related need, to jump to directories far away. I wrote a script which relies on the directory name to be more or less unique, to work:

# usage: pcd NAME
# checks, whether the first locate-match is a directory, and jumps into it, if it is.
# If not, the first match is displayed. pcd: perhaps-cd. :)
function pcd 
    folder=$(locate $1 | egrep "$1$" | head -n 1)
    # echo $folder
    if [[ -d $folder ]]
        echo $folder
        cd $folder
    echo "No directory "$folder

I sourced it from .bashrc to use the function.

If locate doesn't find too many files to edit, the shell could display 30 or 40 matches as a numbered list, and prompt you to enter a number from 0 to 30, 40, to open that file, or you could use zenity to display the matches, and let you select them.

The locate program relies on regular running of updatedb. It will not work for fresh new files from today, but most editors have a list of recently opened files - don't they?

The file-open-dialog can be modified to contain often used directories - pull these directories to the left, favorite-list.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.