Skip to content

Instantly share code, notes, and snippets.

@alsolovyev
Created September 10, 2022 20:08
Show Gist options
  • Save alsolovyev/e0152766bade82ddf4f25304334002cf to your computer and use it in GitHub Desktop.
Save alsolovyev/e0152766bade82ddf4f25304334002cf to your computer and use it in GitHub Desktop.
Raycast script to open Vim or files in Vim
#!/usr/bin/osascript
# Dependency: requires iTerm (https://iterm2.com)
# Install via Homebrew: `brew install --cask iterm2`
# Required parameters:
# @raycast.schemaVersion 1
# @raycast.title Open Vim
# @raycast.mode compact
# Optional parameters:
# @raycast.icon images/vim.png
# @raycast.packageName Vim
# @raycast.argument1 { "type": "text", "placeholder": "file name", "optional": true }
# Documentation:
# @raycast.description Open Vim Editor
# @raycast.author Aleksey Solovyev
# @raycast.authorURL https://github.com/alsolovyev
# Handlers
on hasWindows()
if not isRunning() then return false
if windows of application "iTerm" is {} then return false
true
end hasWindows
on isProcessing()
tell application "iTerm" to tell the first window to tell current session to get is processing
end isProcessing
on isRunning()
application "iTerm" is running
end isRunning
on createNewWindow()
tell application "iTerm" to create window with default profile
end createNewWindow
on callForward()
tell application "iTerm" to activate
end callForward
# Main
on run argv
if hasWindows() then
if isProcessing() then
createNewWindow()
else
callForward()
end if
else
if isRunning() then
createNewWindow()
else
callForward()
end if
end if
repeat until hasWindows()
delay 0.01
end repeat
tell application "iTerm" to tell the first window to tell current session to write text "vim " & argv
end run
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment