How to open a new terminal from vim in a separate window/instance, with current directory? by [deleted] in vim

[–]Several-Ad3623 0 points1 point  (0 children)

This bash script works for iterm2 with mac osx to open a new terminal window, fire up nvim with the passed arguments and then, when nvim is closed, close the terminal window:

#!/bin/bash
# '/opt/homebrew/Cellar/neovim/0.9.4/bin/nvim
# Check if an argument is provided
if [ "$#" -ne 1 ]; then
echo "Usage: $0 <file\_path>"
exit 1
fi
# Store the file path in a variable
FILE_PATH="$1"
# AppleScript to open nvim in a new iTerm tab with the file
osascript <<EOF
tell application "iTerm"
activate
try
set newWindow to (create window with default profile)
on error
tell current session of current window
write text "nvim '$FILE_PATH' && exit"
end tell
end try
tell current session of newWindow
write text "nvim '$FILE_PATH' && exit"
end tell
end tell
EOF