-
-
Save zma/38fb49fff1f1514eb1b3b0ae8340d2a5 to your computer and use it in GitHub Desktop.
Open files with iTerm vim
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- This creates a shim Application that will enable you to open files from the Finder in vim using iTerm | |
-- To use this script: | |
-- 1. Open Automator and create a new Application | |
-- 2. Add the "Run Applescript" action | |
-- 3. Paste this script into the Run Applescript section | |
-- 4. Save the application as TerminalVim.app in your Applications folder | |
-- 5. In the Finder, right click on a file and select "Open With". In that window you can set TerminalVim as a default | |
-- Improved with chaning PWD | |
-- from https://gist.github.com/cinakyn/a965c695b5d95def68ee84eb3d36befa | |
-- which is a forked version of https://gist.github.com/charlietran/43639b0f4e0a01c7c20df8f1929b76f2 | |
on run {input, parameters} | |
set paths to "" | |
set pathlast to "" | |
repeat with i from 1 to length of input | |
set cur to item i of input | |
set pathlast to quote & POSIX path of cur & quote | |
set paths to paths & " " & quote & POSIX path of cur & quote | |
end repeat | |
set cmd to "cd $(dirname " & pathlast & ") && vim -p" & paths | |
tell application "iTerm" | |
set created to false | |
if not (exists current window) then | |
create window with profile "Default" | |
set created to true | |
end if | |
tell current window | |
if not created then | |
create tab with profile "Default" | |
end if | |
tell current session | |
activate | |
write text cmd | |
end tell | |
end tell | |
end tell | |
end run |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment