-
-
Save gcman105/fdd5e11a765fc624a94ac7dc9f49b63f to your computer and use it in GitHub Desktop.
Open files with iTerm nvim
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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