Created
December 8, 2011 17:21
-
-
Save wisq/1447696 to your computer and use it in GitHub Desktop.
Run vim in a new iterm tab
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
#!/usr/bin/ruby | |
require 'tempfile' | |
APPLESCRIPT = <<EOF | |
tell application "iTerm" | |
activate | |
tell the first terminal | |
set new_session to (make new session at the end of sessions) | |
tell new_session | |
exec command $COMMAND | |
end tell | |
end tell | |
end tell | |
EOF | |
def quote(arg) | |
arg = arg.gsub('\\', '\\\\') | |
arg = arg.gsub('"', '\\"') | |
"\"#{arg}\"" | |
end | |
vim = `which vim`.chomp | |
command = [vim, *ARGV].map { |a| quote(a) }.join(' ') | |
Tempfile.open(File.basename(__FILE__)) do |fh| | |
fh.puts APPLESCRIPT.sub('$COMMAND', quote(command)) | |
fh.flush | |
system '/usr/bin/osascript', fh.path | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment