vim-gtfo icon indicating copy to clipboard operation
vim-gtfo copied to clipboard

Slow terminal open

Open ptzz opened this issue 8 years ago • 4 comments

On MacOS and with iTerm it takes ~1s to open terminal with gtfo, versus opening a new terminal manually with iTerm is instant. Opening Finder does not have this problem and is instant with gtfo. Not sure why, vim profiling does not show anything being slow.

ptzz avatar Aug 16 '17 09:08 ptzz

Turns out the reason is that open -a iTerm is much slower than Shell->New Tab (CMD-T) in iTerm.

ptzz avatar Aug 16 '17 12:08 ptzz

I don't use iTerm. Open to concrete ideas about how to fix it.

justinmk avatar Aug 16 '17 19:08 justinmk

An AppleScript wrapped in a bash function seems to do the trick. Something along:

open_iterm() {
    osascript &>/dev/null <<EOF
    if application "iTerm" is running then
        set isRunning to true
    else
        set isRunning to false
    end if

    tell application "iTerm"
        if isRunning then
            set newWindow to (create window with default profile)
        else
            try
                # iTerm opens a window when launched. Re-use that window.
                set newWindow to current window
            on error
                # iTerm is configured to start without any open windows?
                set newWindow to (create window with default profile)
            end try
        end if
        tell newWindow to set sesh to current session
        tell sesh to write text "cd $1"
    end tell
    activate application "iTerm"
EOF
}

A bit verbose, I did not find a better way to avoid opening two windows when iTerm is launched fresh.

It saves ~500ms on my system, when iTerm is already open.

ptzz avatar Aug 16 '17 22:08 ptzz

Funny, that's how it used to work, but there was some breaking change between macOS and/or iTerm versions, and it seemed at the time like there was no longer any need for applscript: https://github.com/justinmk/vim-gtfo/pull/26

Not opposed to restoring it in some fashion, since there is a legitimate need.

justinmk avatar Aug 16 '17 22:08 justinmk