Created
June 16, 2024 21:51
-
-
Save speelbarrow/0ef91e557193392352e4751ea80911b6 to your computer and use it in GitHub Desktop.
Open file in Neovide
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
# Only tested on macOS, but should work anywhere where you can specify a shell script as the program to open a file with | |
# On macOS, create an Automator app, then create a "Run Shell Script" step and run this script. | |
PID=`grep -oE "([0-9]+)\.0$" "$HOME/.neovide" | rev | cut -c3- | rev` | |
if ps -p $PID > /dev/null; then | |
command nvim --server `cat $HOME/.neovide` --remote-send "<Cmd>NeovideFocus<CR>" | |
# Remove the following line if you don't want the file to open in a new tab | |
command nvim --server `cat $HOME/.neovide` --remote-send "<Cmd>tabnew<CR>" | |
command nvim --server `cat $HOME/.neovide` --remote-send "<Cmd>lua vim.schedule_wrap(vim.cmd.e)('$1')<CR>" | |
else | |
neovide -- "$1" | |
fi |
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
-- Add this anywhere in your Neovim startup config | |
-- Otherwise the shell script won't be able to determine where the pipe to the Neovim backend is | |
-- This also comes with the caveat that the script will always open the file in the most recently started instance of Neovide | |
if vim.g.neovide then | |
local id = vim.fn.jobstart "/usr/bin/env sh" | |
if id > 0 then | |
vim.fn.chansend(id, "echo $NVIM > ~/.neovide\n") | |
vim.fn.jobwait({ id }, 1000) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment