Jump to content

script to open directory in vim within iTerm


Recommended Posts

I can't seem to get the php to execute the command I'm giving it in the terminal.

 

The Problem:

1. Won't actually perform the task in iTerm

2. My plugins don't open at vim startup if I start vim like this

vim ~/path/to/directory

But will work with this

cd ~/path/to/directory; vim 

Here's what I put in php:

$dir = "{query}";

$cmd = "cd " . "$dir" . "; vim";

//echo $cmd;
//ouputs: cd path/to/proper/directory; vim;

exec("$cmd"); // doesn't even open the terminal

$dir = "{query}";

$cmd = "open -a iTerm; cd" . "$dir" . "; vim;";
// IF TERMINAL SWITCH THE ABOVE iTerm TO Terminal

//echo $cmd;
//ouputs: cd path/to/proper/directory; vim;

exec("$cmd"); // doesn't even open the terminal

Then I tried running a `terminal command` action with the following in it

query=“{query}”;
echo “${query// /\\ }" // because the ~/path/to/foo bar won't work. Needs to be ~/path/to/foo\ bar

I know that last one is not quite right.  I'm still learning bash.  I posted a question on StackOverflow here.

 

Can anybody help me please!? :)

Link to comment

exec("$cmd"); won't open a terminal window but will do it in the background.

 

The open command should, but you might need the full path $cmd = "open -a /Applications/iTerm.app"; exec($cmd);

 

You can't tell iTerm to switch to that directory from inside PHP. You need to use Applescript to send that command to iTerm once it has been opened. Actually, just do the opening and everything else in Applescript. It's easier. You can launch an Applescript from inside PHP with the bash command osascript.

 

Bash:

You have smart quotes. Bash won't like those. Why not just use: echo "{query}" if in an alfred window? If you want to open a directory in bash from the query, then just use `$query` if it has the full path in it. Otherwise, you might need to do `cd "$query"`. Note the non-smart double-quotes so that the variable will expand.

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...