Opening the current Finder directory in iTerm2(peterdowns.com)
peterdowns.com
Opening the current Finder directory in iTerm2
http://peterdowns.com/posts/open-iterm-finder-service.html
12 comments
The terminal app built into OS X (newer versions, at least) lets you drag a folder to its icon to open a new terminal at that path.
It looks like iTerm2 almost does it — if you drag a directory to its icon it tries to execute it (which fails).
EDIT: actually, it looks like iTerm master supports this too: https://github.com/gnachman/iTerm2/blob/194678de81100cb17dad...
…but it doesn’t work for directories with spaces and other special characters. Looks like a bug.
EDIT 2: Pull request sent: https://github.com/gnachman/iTerm2/pull/78
It looks like iTerm2 almost does it — if you drag a directory to its icon it tries to execute it (which fails).
EDIT: actually, it looks like iTerm master supports this too: https://github.com/gnachman/iTerm2/blob/194678de81100cb17dad...
…but it doesn’t work for directories with spaces and other special characters. Looks like a bug.
EDIT 2: Pull request sent: https://github.com/gnachman/iTerm2/pull/78
Very cool. Thanks for sending in the pull request, I'd love to be able to do that instead of using this Finder service (which is a little hack-y).
I use a droplet in the Finder window for that. It's called Open iTerm here.app and I have no idea where I've found it. Google gives quite a bunch of results, though.
Before that, I've used another similar droplet called Open Terminal here.app.
In iTerm I use
I also have a little bash function to `cd` into the topmost Finder window:
Before that, I've used another similar droplet called Open Terminal here.app.
In iTerm I use
$ open .
to open the current directory in a Finder window.I also have a little bash function to `cd` into the topmost Finder window:
cdf () {
CURRFOLDERPATH=$( /usr/bin/osascript <<" EOT"
tell application "Finder"
try
set currFolder to (folder of the front window as alias)
on error
set currFolder to (path to desktop folder as alias)
end try
POSIX path of currFolder
end tell
EOT
)
echo "cd to \"$CURRFOLDERPATH\""
cd "$CURRFOLDERPATH"
}I put an icon on the finder window so I just click it and get a terminal open to the directory.
http://maururu.net/2007/enhanced-open-terminal-here-for-leop...
http://maururu.net/2007/enhanced-open-terminal-here-for-leop...
If you want do this with Terminal.app instead, there is a setting for this.
Open the keyboard preferences, go to the "Keyboard Shortcuts" tab, click "Services" in the left panel and in the right panel under "Files and Folders", there is an option for "New Terminal at Folder".
Then you can right click on a folder and launch a terminal.
Visual: http://osxdaily.com/2011/12/07/open-a-selected-finder-folder...
Open the keyboard preferences, go to the "Keyboard Shortcuts" tab, click "Services" in the left panel and in the right panel under "Files and Folders", there is an option for "New Terminal at Folder".
Then you can right click on a folder and launch a terminal.
Visual: http://osxdaily.com/2011/12/07/open-a-selected-finder-folder...
I achieved something similar in bash, in a terminal-agnostic way a while back. I have this script saved at ~/cdf.scpt : https://gist.github.com/2037421
Then my .bash_profile contains the line:
Then my .bash_profile contains the line:
alias cdf='cd "`osascript ~/cdf.scpt`"'
Now if I type "cdf" in a terminal window, it will automatically cd to the directory of the front-most Finder window.I use Alfred (http://www.alfredapp.com/), which gives you a keyboard shortcut (opt-cmd-\) that gives you the ability to open a terminal at the currently selected Finder item.
This is another good Alfred extension that does basically the same thing but with an AppleScript: https://github.com/pcal/alfred-terminal-here
I found this years ago on a forum cant seem to find the link but I'm pretty sure its out there and has been posted here before
https://gist.github.com/2037827
https://gist.github.com/2037827
Wouldn't this be best as a contextual menu extension? Right-click and select open-in-iTerm.
Is anyone still coding those? There was such a huge ecosystem of them forever ago for OS8/9, but I don't see them anymore.
Is anyone still coding those? There was such a huge ecosystem of them forever ago for OS8/9, but I don't see them anymore.
This is as close as I could get.
You can also just write "open ." in an iTerm window
Whilst this is the opposite of what the post is suggesting, it's a useful thing to know.
If you use Nautilus (e.g. Ubuntu), "nautilus ." works. I guess "explorer ." would work in Windows.
If you use Nautilus (e.g. Ubuntu), "nautilus ." works. I guess "explorer ." would work in Windows.
Won’t that open the CWD (in that terminal) in a new Finder window?
That was my initial thought, but he's describing the reverse: browse to a folder in Finder, then open a terminal with the path set to that directory.
That's the reverse of that the author is trying to do, which is open a terminal window, when he has a Finder window open.
the link to "solarized" just links to iterm2's website...
Thanks for pointing this out — fixed.
[deleted]
It adds a button to the toolbar to Finder windows. Click that to open a terminal on the directory shown in the window.
There are other similar toolbar add ons available, which I've used and were happy with, such as cdto: http://code.google.com/p/cdto/
I use Go2Shell now because it is on the App Store, so that I don't have to worry about checking for updates.