Skip to content

Commit

Permalink
.xopen() accept an alternate command= with which to open the file
Browse files Browse the repository at this point in the history
e.g. Path('/tmp/file.ext').xopen('emacsclient')
  • Loading branch information
tgbugs committed Jun 21, 2020
1 parent 608d54e commit 0d0a0ae
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions augpathlib/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1275,19 +1275,25 @@ def _bind_flavours(cls, pos_helpers=tuple(), win_helpers=tuple()):
class XopenWindowsHelper(XopenHelper):
_command = 'start'

def xopen(self):
""" open file using start """
process = subprocess.Popen([self._command, self],
def xopen(self, command=None):
""" open file using start or `command' if provided """
if command is None or not isinstance(command, str):
command = self._command

process = subprocess.Popen([command, self],
stdout=subprocess.DEVNULL,
stderr=subprocess.STDOUT)


class XopenPosixHelper(XopenHelper):
_command = 'open' if sys.platform == 'darwin' else 'xdg-open'

def xopen(self):
""" open file using xdg-open """
process = subprocess.Popen([self._command, self.as_posix()],
def xopen(self, command=None):
""" open file using xdg-open or `command' if provided """
if command is None or not isinstance(command, str):
command = self._command

process = subprocess.Popen([command, self.as_posix()],
stdout=subprocess.DEVNULL,
stderr=subprocess.STDOUT)

Expand Down

0 comments on commit 0d0a0ae

Please sign in to comment.