Skip to content

Instantly share code, notes, and snippets.

@wisq
Created December 8, 2011 17:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wisq/1447696 to your computer and use it in GitHub Desktop.
Save wisq/1447696 to your computer and use it in GitHub Desktop.
Run vim in a new iterm tab
#!/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