mac中将vim添加到右键菜单

  1. 创建 vim.app 到应用程序目录:
mac中将vim添加到右键菜单_第1张图片
image.png
mac中将vim添加到右键菜单_第2张图片

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
mac中将vim添加到右键菜单_第3张图片
image.png
  1. 创建服务
mac中将vim添加到右键菜单_第4张图片
image.png
mac中将vim添加到右键菜单_第5张图片
image.png
image.png
mac中将vim添加到右键菜单_第6张图片
image.png

你可能感兴趣的:(mac中将vim添加到右键菜单)