-
-
Save fanzeyi/a7ae4bbc5c6bc182e9940eee96ceb4ca to your computer and use it in GitHub Desktop.
iterm2
This file contains hidden or 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
diff --git a/autoload/dispatch/iterm.vim b/autoload/dispatch/iterm.vim | |
index 7b52012..068f95f 100644 | |
--- a/autoload/dispatch/iterm.vim | |
+++ b/autoload/dispatch/iterm.vim | |
@@ -21,22 +21,23 @@ function! dispatch#iterm#handle(request) abort | |
endfunction | |
function! dispatch#iterm#spawn(command, request, activate) abort | |
- let script = dispatch#isolate([], dispatch#set_title(a:request), a:command) | |
+ let script = s:isolate(a:request.command) | |
return s:osascript( | |
\ 'if application "iTerm" is not running', | |
\ 'error', | |
\ 'end if') && s:osascript( | |
\ 'tell application "iTerm"', | |
- \ 'tell the current terminal', | |
- \ 'set oldsession to the current session', | |
- \ 'tell (make new session)', | |
+ \ 'tell current window', | |
+ \ 'set newTab to (create tab with default profile)', | |
+ \ 'tell application "MacVim"', | |
+ \ 'activate', | |
+ \ 'end tell', | |
+ \ 'tell current session', | |
\ 'set name to ' . s:escape(a:request.title), | |
- \ 'set title to ' . s:escape(a:request.command), | |
- \ 'exec command ' . s:escape(script), | |
- \ a:request.background ? 'select oldsession' : '', | |
+ \ 'set title to ' . s:escape(a:request.title), | |
+ \ 'write text ' . s:escape('fish ' . script. ' %self'), | |
+ \ 'end tell', | |
\ 'end tell', | |
- \ 'end tell', | |
- \ a:activate ? 'activate' : '', | |
\ 'end tell') | |
endfunction | |
@@ -48,7 +49,6 @@ function! dispatch#iterm#activate(pid) abort | |
\ 'error', | |
\ 'end if') && s:osascript( | |
\ 'tell application "iTerm"', | |
- \ 'activate', | |
\ 'tell the current terminal', | |
\ 'select session id "/dev/'.tty.'"', | |
\ 'end tell', | |
@@ -56,8 +56,27 @@ function! dispatch#iterm#activate(pid) abort | |
endif | |
endfunction | |
+function! s:isolate(command) | |
+ let lines = [ | |
+ \ 'cd ' . shellescape(getcwd()), | |
+ \ 'echo "' . a:command . '"', | |
+ \ a:command, | |
+ \ 'if test $status -eq 0', | |
+ \ ' kill $argv[1]', | |
+ \ ' exit', | |
+ \ 'end', | |
+ \ 'echo ''<----- press any key to continue ----->''', | |
+ \ 'read -p '''' -n 1 foo', | |
+ \ 'kill $argv[1]' | |
+ \] | |
+ let temp = tempname() | |
+ call writefile(lines, temp) | |
+ return temp | |
+endfunction | |
+ | |
function! s:osascript(...) abort | |
- call system('osascript'.join(map(copy(a:000), '" -e ".shellescape(v:val)'), '')) | |
+ let args = join(map(copy(a:000), '" -e ".shellescape(v:val)'), '') | |
+ call system('osascript'. args) | |
return !v:shell_error | |
endfunction |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment