Skip to content

Instantly share code, notes, and snippets.

@gcman105
Forked from cinakyn/Vim.scpt
Last active May 25, 2020 12:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gcman105/fdd5e11a765fc624a94ac7dc9f49b63f to your computer and use it in GitHub Desktop.
Save gcman105/fdd5e11a765fc624a94ac7dc9f49b63f to your computer and use it in GitHub Desktop.
Open files with iTerm nvim
on run {input, parameters}
-- If run without input, open random file at $HOME
try
set paths to ""
repeat with i from 1 to length of input
set cur to item i of input
set paths to paths & " " & quote & POSIX path of cur & quote
end repeat
on error
set paths to (do shell script "date +%F") & "__" & (random number from 1000 to 9999) & ".md"
end try
-- Set your editor here
set myEditor to "/usr/local/bin/nvim"
set cmd to ":edit "
tell application "iTerm"
if not (exists current window) then
create window with profile "Default"
end if
tell current tab of current window
set foundSession to false
repeat with mysession in sessions
tell mysession
set the_name to get name
if the_name contains "nvim" then
select mysession
set foundSession to true
exit repeat
end if
end tell
end repeat
if not foundSession then
set cmd to myEditor & " -p "
end if
tell current session
activate
write text cmd & paths
end tell
end tell
end tell
end run
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment