Search code examples
bashvagrantiterm2

iTerm2 open file


iTerm2 has a nice ⌘-click to open a file in your IDE.

The problem is I'm running a web server via Vagrant, so /home/vagrant isn't really a physical directory that iTerm2 can access.

Is there a way I can either:

A.) Map /home/vagrant/ to /Sites in my .bash_profile

B.) Run it through a Find/Replace script that returns the modified path?

Any suggestions? Thanks


Solution

  • There is not way to configure it using .bash_profile... but there is a solution inside your iTerm2's preference.

    Preferences -> Profiles -> Semantic History. Change to Run command... and fill with:

    sh ~/click-handler.sh \1 /home/vagrant /Sites
    

    create ~/click-handler.sh:

    old_filepath=$1
    old_basepath=$2
    new_basepath=$3
    new_filepath="${old_filepath/$old_basepath/$new_basepath}"
    open $new_filepath
    

    Let's try!