美文网首页
mac中将vim添加到右键菜单

mac中将vim添加到右键菜单

作者: a_pioneer | 来源:发表于2017-05-17 09:45 被阅读0次
  1. 创建 vim.app 到应用程序目录:
image.png

vim.app 代码如下

on run {input}
    if length of input is equal to 1 then
        my openFile(input)
    else
        my justOpen()
    end if
end run


on openFile(input)
    set the_file to quoted form of POSIX path of input
    tell application "System Events"
        set the_path to POSIX path of (container of (item 1 of input))
    end tell
    
    set cwd to "cd " & the_path
    set cmd to "vim " & the_file
    my launchVim(cwd, cmd)
end openFile


on justOpen()
    set cwd to "cd"
    set cmd to "vim"
    my launchVim(cwd, cmd)
end justOpen


on launchVim(cwd, cmd)
    tell application "System Events" to set terminalIsRunning to exists application process "Terminal"
    
    tell application "Terminal"
        activate
        if terminalIsRunning is true then
            tell application "System Events" to tell process "Terminal" to keystroke "t" using command down
            do script with command cwd in selected tab of the front window
            do script with command cmd in selected tab of the front window
        else
            do script with command cwd in window 1
            do script with command cmd in window 1
        end if
    end tell
end launchVim
image.png
  1. 创建服务
image.png image.png image.png image.png

相关文章

网友评论

      本文标题:mac中将vim添加到右键菜单

      本文链接:https://www.haomeiwen.com/subject/htzrxxtx.html