tabs.rostertab: Use Path for file completion.
This commit is contained in:
parent
150feda3f0
commit
1707b14691
1 changed files with 10 additions and 9 deletions
|
@ -15,6 +15,7 @@ import os
|
||||||
import ssl
|
import ssl
|
||||||
from os import getenv, path
|
from os import getenv, path
|
||||||
from functools import partial
|
from functools import partial
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
from poezio import common
|
from poezio import common
|
||||||
from poezio import windows
|
from poezio import windows
|
||||||
|
@ -612,27 +613,27 @@ class RosterInfoTab(Tab):
|
||||||
home = os.getenv('HOME') or '/'
|
home = os.getenv('HOME') or '/'
|
||||||
return Completion(
|
return Completion(
|
||||||
the_input.new_completion, [home, '/tmp'], n, quotify=True)
|
the_input.new_completion, [home, '/tmp'], n, quotify=True)
|
||||||
path_ = args[n]
|
path_ = Path(args[n])
|
||||||
if path.isdir(path_):
|
if path_.is_dir():
|
||||||
dir_ = path_
|
dir_ = path_
|
||||||
base = ''
|
base = ''
|
||||||
else:
|
else:
|
||||||
dir_ = path.dirname(path_)
|
dir_ = path_.parent
|
||||||
base = path.basename(path_)
|
base = path_.name
|
||||||
try:
|
try:
|
||||||
names = os.listdir(dir_)
|
names = list(dir_.iterdir())
|
||||||
except OSError:
|
except OSError:
|
||||||
names = []
|
names = []
|
||||||
names_filtered = [name for name in names if name.startswith(base)]
|
names_filtered = [name for name in names if str(name).startswith(base)]
|
||||||
if names_filtered:
|
if names_filtered:
|
||||||
names = names_filtered
|
names = names_filtered
|
||||||
if not names:
|
if not names:
|
||||||
names = [path_]
|
names = [path_]
|
||||||
end_list = []
|
end_list = []
|
||||||
for name in names:
|
for name in names:
|
||||||
value = os.path.join(dir_, name)
|
if not str(name).startswith('.'):
|
||||||
if not name.startswith('.'):
|
value = dir_ / name
|
||||||
end_list.append(value)
|
end_list.append(str(value))
|
||||||
|
|
||||||
return Completion(
|
return Completion(
|
||||||
the_input.new_completion, end_list, n, quotify=True)
|
the_input.new_completion, end_list, n, quotify=True)
|
||||||
|
|
Loading…
Reference in a new issue