Skip to content

Commit

Permalink
Add a new simple editor command.
Browse files Browse the repository at this point in the history
  • Loading branch information
markmuetz committed Nov 9, 2023
1 parent 69c6855 commit d87590e
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions remake/util.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
import sys
import importlib.util
import hashlib
Expand Down Expand Up @@ -104,3 +105,19 @@ def sysrun(cmd):
raises CalledProcessError if cmd is bad.
to access output: sysrun(cmd).stdout"""
return sp.run(cmd, check=True, shell=True, stdout=sp.PIPE, stderr=sp.PIPE, encoding='utf8')


def editor(paths, read_only=True):
"""Opens an editor and reads the requested files
read_only only works if editor is vim"""
editor = os.environ.get('EDITOR', 'vim')
if read_only:
if editor == 'vim':
ed_cmd = 'vim -R'
else:
input('Not opening in readonly mode for editor {editor}! (hit return)')
ed_cmd = EDITOR

cmd = ed_cmd + ' ' + ' '.join(str(p) for p in paths)
sp.call(cmd.split())

0 comments on commit d87590e

Please sign in to comment.