Last active
December 9, 2024 06:07
-
-
Save rf-/33fc88d3071f4254b80e to your computer and use it in GitHub Desktop.
Revisions
-
rf- revised this gist
Dec 9, 2024 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -13,7 +13,7 @@ def get_listed_buffers(nvim): # is good enough to recognize '-f' and `+11`, which is all this script really # needs right now. filenames = [ re.sub(' ', '\\ ', os.path.abspath(arg)) for arg in sys.argv[1:] if not arg[0] in ['-', '+'] ] -
rf- revised this gist
Jul 6, 2022 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -18,7 +18,7 @@ filenames = [ ] try: nvim_socket = os.environ["NVIM"] except KeyError: # If we aren't running inside a `:terminal`, just exec nvim. os.execvp('nvim', sys.argv) -
rf- revised this gist
Jan 1, 2019 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -70,4 +70,4 @@ if '-f' in sys.argv and len(new_buffers) > 0: nvim.command('argdel *') for buffer in new_buffers: nvim.command('autocmd! BufDelete,BufHidden <buffer=%d>' % buffer) nvim.command('bdelete! %d' % buffer) -
rf- revised this gist
Jan 1, 2019 . 1 changed file with 3 additions and 3 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,6 @@ #!/usr/bin/env python import pynvim, os, re, sys, time # Get a list of buffers that haven't been deleted. `nvim.buffers` includes # buffers that have had `:bdelete` called on them and aren't in the buffer @@ -23,7 +23,7 @@ except KeyError: # If we aren't running inside a `:terminal`, just exec nvim. os.execvp('nvim', sys.argv) nvim = pynvim.attach('socket', path=nvim_socket) existing_buffers = get_listed_buffers(nvim) @@ -70,4 +70,4 @@ if '-f' in sys.argv and len(new_buffers) > 0: nvim.command('argdel *') for buffer in new_buffers: nvim.command('autocmd! BufDelete,BufHidden <buffer=%d>' % buffer) nvim.command('bdelete! %d' % buffer) -
rf- revised this gist
Sep 29, 2016 . 1 changed file with 0 additions and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -22,7 +22,6 @@ try: except KeyError: # If we aren't running inside a `:terminal`, just exec nvim. os.execvp('nvim', sys.argv) nvim = neovim.attach('socket', path=nvim_socket) -
rf- revised this gist
Sep 29, 2016 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -71,4 +71,4 @@ if '-f' in sys.argv and len(new_buffers) > 0: nvim.command('argdel *') for buffer in new_buffers: nvim.command('autocmd! BufDelete,BufHidden <buffer=%d>' % buffer) nvim.command('bdelete! %d' % buffer) -
rf- revised this gist
Sep 29, 2016 . 1 changed file with 2 additions and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -22,6 +22,7 @@ try: except KeyError: # If we aren't running inside a `:terminal`, just exec nvim. os.execvp('nvim', sys.argv) sys.exit() nvim = neovim.attach('socket', path=nvim_socket) @@ -70,4 +71,4 @@ if '-f' in sys.argv and len(new_buffers) > 0: nvim.command('argdel *') for buffer in new_buffers: nvim.command('autocmd! BufDelete,BufHidden <buffer=%d>' % buffer) nvim.command('bdelete! %d' % buffer) -
rf- revised this gist
May 23, 2016 . 1 changed file with 0 additions and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -22,7 +22,6 @@ try: except KeyError: # If we aren't running inside a `:terminal`, just exec nvim. os.execvp('nvim', sys.argv) nvim = neovim.attach('socket', path=nvim_socket) -
rf- revised this gist
May 23, 2016 . 1 changed file with 2 additions and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -22,6 +22,7 @@ try: except KeyError: # If we aren't running inside a `:terminal`, just exec nvim. os.execvp('nvim', sys.argv) sys.exit() nvim = neovim.attach('socket', path=nvim_socket) @@ -56,7 +57,7 @@ if '-f' in sys.argv and len(new_buffers) > 0: stay_open = True while stay_open: nvim.next_message() # block until `rpcnotify` is called open_buffers = [window.buffer.number for window in nvim.windows] stay_open = any([buffer in open_buffers for buffer in new_buffers]) -
rf- revised this gist
Nov 18, 2015 . 1 changed file with 0 additions and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -22,7 +22,6 @@ try: except KeyError: # If we aren't running inside a `:terminal`, just exec nvim. os.execvp('nvim', sys.argv) nvim = neovim.attach('socket', path=nvim_socket) -
rf- revised this gist
Oct 13, 2015 . 1 changed file with 8 additions and 7 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,6 @@ #!/usr/bin/env python import neovim, os, re, sys, time # Get a list of buffers that haven't been deleted. `nvim.buffers` includes # buffers that have had `:bdelete` called on them and aren't in the buffer @@ -13,7 +13,8 @@ def get_listed_buffers(nvim): # is good enough to recognize '-f' and `+11`, which is all this script really # needs right now. filenames = [ re.sub(' ', '\ ', os.path.abspath(arg)) for arg in sys.argv[1:] if not arg[0] in ['-', '+'] ] try: @@ -49,10 +50,10 @@ if '-f' in sys.argv and len(new_buffers) > 0: # hides one of the buffers. channel_id = nvim.channel_id for buffer in new_buffers: nvim.command(( 'autocmd BufDelete,BufHidden <buffer=%d> ' + 'call rpcnotify(%d, "check_buffers")' ) % (buffer, channel_id)) stay_open = True while stay_open: @@ -70,4 +71,4 @@ if '-f' in sys.argv and len(new_buffers) > 0: nvim.command('argdel *') for buffer in new_buffers: nvim.command('autocmd! BufDelete,BufHidden <buffer=%d>' % buffer) nvim.command('bdelete! %d' % buffer) -
rf- revised this gist
Sep 13, 2015 . 1 changed file with 3 additions and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -12,7 +12,9 @@ def get_listed_buffers(nvim): # For now, treat all arguments that don't start with - or + as filenames. This # is good enough to recognize '-f' and `+11`, which is all this script really # needs right now. filenames = [ os.path.abspath(arg) for arg in sys.argv[1:] if not arg[0] in ['-', '+'] ] try: nvim_socket = os.environ["NVIM_LISTEN_ADDRESS"] -
rf- revised this gist
Sep 12, 2015 . 1 changed file with 30 additions and 9 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -2,17 +2,22 @@ import os, sys, neovim, time # Get a list of buffers that haven't been deleted. `nvim.buffers` includes # buffers that have had `:bdelete` called on them and aren't in the buffer # list, so we have to filter those out. def get_listed_buffers(nvim): return set(buf.number for buf in nvim.buffers \ if nvim.eval('buflisted(%d)' % buf.number)) # For now, treat all arguments that don't start with - or + as filenames. This # is good enough to recognize '-f' and `+11`, which is all this script really # needs right now. filenames = [arg for arg in sys.argv[1:] if not arg[0] in ['-', '+']] try: nvim_socket = os.environ["NVIM_LISTEN_ADDRESS"] except KeyError: # If we aren't running inside a `:terminal`, just exec nvim. os.execvp('nvim', sys.argv) sys.exit() @@ -29,7 +34,17 @@ for arg in sys.argv: if arg[0] == '+': nvim.command(arg[1:]) # The '-f' flag is a signal that we're in a situation like a `git commit` # invocation where we need to block until the user is done with the file(s). if '-f' in sys.argv and len(new_buffers) > 0: # The rule here is that the user is 'done' with the opened files when none # of them are visible onscreen. This allows for use cases like hitting `:q` # on a `git commit` tempfile. However, we can't just poll to see if they're # visible, because using `nvim.windows`, `nvim.eval()`, or `nvim.call()` # will interrupt any multi-key mappings the user may be inputting. The # solution is to set a buffer-local autocmd on each opened buffer so that # we only check for visibility immediately after the user either closes or # hides one of the buffers. channel_id = nvim.channel_id for buffer in new_buffers: nvim.command( @@ -39,12 +54,18 @@ if '-f' in sys.argv and len(new_buffers) > 0: stay_open = True while stay_open: nvim.session.next_message() # block until `rpcnotify` is called open_buffers = [window.buffer.number for window in nvim.windows] stay_open = any([buffer in open_buffers for buffer in new_buffers]) # Now that none of the opened files are visible anymore, we do a few # cleanup steps before ending the script: # * Clear the arg list, since otherwise `:next` would reopen the tempfile # or whatever. # * Clear the autocmds we added, since `bdelete` just hides the buffer and # the autocmds will still be active if the user reopens the file(s). # * Delete each of the buffers we created. nvim.command('argdel *') for buffer in new_buffers: nvim.command('autocmd! BufDelete,BufHidden <buffer=%d>' % buffer) nvim.command('bdelete! %d' % buffer) -
rf- revised this gist
Sep 12, 2015 . 1 changed file with 0 additions and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -42,7 +42,6 @@ if '-f' in sys.argv and len(new_buffers) > 0: nvim.session.next_message() open_buffers = [window.buffer.number for window in nvim.windows] stay_open = any([buffer in open_buffers for buffer in new_buffers]) if '-c' in sys.argv: nvim.command('argdel *') -
rf- revised this gist
Sep 12, 2015 . 1 changed file with 10 additions and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -29,14 +29,23 @@ for arg in sys.argv: if arg[0] == '+': nvim.command(arg[1:]) if '-f' in sys.argv and len(new_buffers) > 0: channel_id = nvim.channel_id for buffer in new_buffers: nvim.command( 'autocmd BufDelete,BufHidden <buffer=%d> ' + \ 'call rpcnotify(%d, "check_buffers")' % (buffer, channel_id) ) stay_open = True while stay_open: nvim.session.next_message() open_buffers = [window.buffer.number for window in nvim.windows] stay_open = any([buffer in open_buffers for buffer in new_buffers]) time.sleep(0.25) if '-c' in sys.argv: nvim.command('argdel *') for buffer in new_buffers: nvim.command('autocmd! BufDelete,BufHidden <buffer=%d>' % buffer) nvim.command('bdelete! %d' % buffer) -
rf- renamed this gist
Sep 12, 2015 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
rf- revised this gist
Sep 12, 2015 . 1 changed file with 14 additions and 10 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -2,6 +2,10 @@ import os, sys, neovim, time def get_listed_buffers(nvim): return set(buf.number for buf in nvim.buffers \ if nvim.eval('buflisted(%d)' % buf.number)) filenames = [ os.path.abspath(arg) for arg in sys.argv[1:] if not arg[0] in ['-', '+'] ] @@ -13,26 +17,26 @@ except KeyError: sys.exit() nvim = neovim.attach('socket', path=nvim_socket) existing_buffers = get_listed_buffers(nvim) nvim.command('split') nvim.command('args %s' % ' '.join(filenames)) new_buffers = get_listed_buffers(nvim).difference(existing_buffers) for arg in sys.argv: if arg[0] == '+': nvim.command(arg[1:]) if '-f' in sys.argv: stay_open = True while stay_open: open_buffers = [window.buffer.number for window in nvim.windows] stay_open = any([buffer in open_buffers for buffer in new_buffers]) time.sleep(0.25) if '-c' in sys.argv: nvim.command('argdel *') for buffer in new_buffers: nvim.command('bdelete! %d' % buffer) -
rf- revised this gist
Sep 11, 2015 . 1 changed file with 29 additions and 25 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -2,33 +2,37 @@ import os, sys, neovim, time filenames = [ os.path.abspath(arg) for arg in sys.argv[1:] if not arg[0] in ['-', '+'] ] try: nvim_socket = os.environ["NVIM_LISTEN_ADDRESS"] except KeyError: os.execvp('nvim', sys.argv) sys.exit() nvim = neovim.attach('socket', path=nvim_socket) nvim.command('split') nvim.command('args %s' % ' '.join(filenames)) for arg in sys.argv: if arg[0] == '+': nvim.command(arg[1:]) if '-f' in sys.argv: stay_open = True while stay_open: # FIXME: This is a dumb way of tracking this and breaks for stuff that # resolves to /private (e.g. Pry tempfiles) open_buffers = [window.buffer.name for window in nvim.windows] stay_open = any([ (filename in open_buffers) for filename in filenames ]) time.sleep(0.25) if '-c' in sys.argv: for filename in filenames: for buffer in nvim.buffers: if buffer.name == filename: nvim.command('bdelete! %d' % buffer.number) -
rf- created this gist
Sep 11, 2015 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,34 @@ #!/usr/bin/env python import os, sys, neovim, time # TODO: search through all ancestors gppid = os.popen("ps -p %d -oppid=" % os.getppid()).read().strip() gp_command = os.popen("ps -p %s -ocommand=" % gppid).read().strip() filenames = [ os.path.abspath(arg) for arg in sys.argv[1:] if not arg[0] == '-' ] if gp_command == 'nvim': # TODO: be less horrible nvim_socket = ( os.popen('lsof -p %s | grep " unix " | grep -v -- "->"' % gppid). read(). split()[-1] ) nvim = neovim.attach('socket', path=nvim_socket) for filename in filenames: nvim.command('split %s' % filename) if '-f' in sys.argv: stay_open = True while stay_open: open_buffers = [window.buffer.name for window in nvim.windows] stay_open = any([ (filename in open_buffers) for filename in filenames ]) time.sleep(0.25) else: os.execvp('nvim', sys.argv)