From a42d697c04b746b3e01cc3d6b3dc46d1017559c2 Mon Sep 17 00:00:00 2001 From: Robert J Date: Fri, 19 May 2017 18:34:36 +0800 Subject: [PATCH] Updated On MacVim with iTerm2 (markdown) --- On-MacVim-with-iTerm2.md | 59 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 58 insertions(+), 1 deletion(-) diff --git a/On-MacVim-with-iTerm2.md b/On-MacVim-with-iTerm2.md index f3053aa..a613a6c 100644 --- a/On-MacVim-with-iTerm2.md +++ b/On-MacVim-with-iTerm2.md @@ -110,4 +110,61 @@ osascript -e \ end run' "$1" "$PWD" ``` -The `tell myterm select` may be helpful when the new window opens on a monitor which does not have the main iTerm2 window. My system, running macOS Sierra, does not automatically focus the newly opened window. \ No newline at end of file +The `tell myterm select` may be helpful when the new window opens on a monitor which does not have the main iTerm2 window. My system, running macOS Sierra, does not automatically focus the newly opened window. + +Here is JavaScript (JXA) mutation (by @chew-z): + +```javascript +#!/usr/bin/env osascript -l JavaScript +// osacompile -l JavaScript -o fzf_MacVim.scpt fzf_MacVim.js + +ObjC.import('stdlib') +function run(argv) { + 'use strict'; + const iTerm = Application('iTerm'); + const SystemEvents = Application('System Events'); + const frontmost = Application.currentApplication(); // MacVim + + iTerm.includeStandardAdditions = true; + const verbose = false; + + var args = $.NSProcessInfo.processInfo.arguments + var argv = [] + var argc = args.count + for (var i = 4; i < argc; i++) { + // skip 3-word run command at top and this file's name + // console.log($(args.objectAtIndex(i)).js) + argv.push(ObjC.unwrap(args.objectAtIndex(i))) + } + if (verbose) { console.log(argv); } // print arguments + + iTerm.activate(); + let win = iTerm.createWindowWithProfile('fzf'); + delay(0.2); + let fzf_session = win.currentSession(); + SystemEvents.keystroke('l', {using: 'control down'}); // Clear screen from artefacts + delay(0.2); + let cmd1 = "cd " + argv[1]; // cd $PWD + iTerm.write(fzf_session,{text: cmd1}); + delay(0.2); + let cmd2 = argv[0] + " && exit"; // fzf command && exit + iTerm.write(fzf_session,{text: cmd2}); + delay(0.2); + while (fzf_session.isProcessing()) { // wait until fzf finished + delay(0.2); + } + frontmost.activate(); // bring back MacVim + // $.exit(0); +} + +``` + +You could compile script above using command ``` osacompile -l JavaScript -o fzf_MacVim.scpt fzf_MacVim.js ``` + +and then put inside fzf_MacVim.sh (your g:fzf_launcher). + +``` +osascript -l JavaScript /path/to/fzf_MacVim.scpt "$1" $PWD +``` + +I recommend creating separate iTerm profile for fzf interaction. \ No newline at end of file