Skip to content

Commit

Permalink
[open-] fix opening a dir with an filetype extension
Browse files Browse the repository at this point in the history
  • Loading branch information
midichef authored and anjakefala committed Nov 13, 2024
1 parent f9f435c commit 1463789
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
13 changes: 8 additions & 5 deletions visidata/_open.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ def guess_extension(vd, path):
def openPath(vd, p, filetype=None, create=False):
'''Call ``open_<filetype>(p)`` or ``openurl_<p.scheme>(p, filetype)``. Return constructed but unloaded sheet of appropriate type.
If True, *create* will return a new, blank **Sheet** if file does not exist.'''
# allow user to assign a filetype to a pathname: options.set('filetype', 'csv', '-')
filetype = filetype or vd.options.getonly('filetype', str(p), None) #1710
filetype = filetype or vd.options.getonly('filetype', 'global', None)

if p.scheme and not p.has_fp():
schemes = p.scheme.split('+')
openfuncname = 'openurl_' + schemes[-1]
Expand All @@ -94,8 +98,10 @@ def openPath(vd, p, filetype=None, create=False):
if not p.exists() and not create:
return None

if not filetype:
filetype = p.ext or vd.options.filetype
# assign filetype from extension, but only for files, not directories
if not p.is_dir(): #2547
filetype = filetype or p.ext
filetype = filetype or vd.options.filetype

filetype = filetype.lower()

Expand Down Expand Up @@ -147,9 +153,6 @@ def openSource(vd, p, filetype=None, create=False, **kwargs):
if isinstance(p, BaseSheet):
return p

filetype = filetype or vd.options.getonly('filetype', str(p), '') #1710
filetype = filetype or vd.options.getonly('filetype', 'global', '')

vs = None
if isinstance(p, str):
if '://' in p:
Expand Down
2 changes: 1 addition & 1 deletion visidata/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
@VisiData.api
def guess_dir(vd, p):
if p.is_dir():
return dict(filetype='dir')
return dict(filetype='dir', _likelihood=10)


@VisiData.lazy_property
Expand Down

0 comments on commit 1463789

Please sign in to comment.