parent
36272c3f08
commit
1adb483649
|
@ -51,6 +51,7 @@ class Completer(object):
|
||||||
class FileCompleter(Completer):
|
class FileCompleter(Completer):
|
||||||
def get_candidates(self, s, w=None):
|
def get_candidates(self, s, w=None):
|
||||||
s = util.expand_tilde(s)
|
s = util.expand_tilde(s)
|
||||||
|
#raise Exception(s + '*')
|
||||||
candidates = [util.normal_path(p) for p in glob.glob(s + '*')]
|
candidates = [util.normal_path(p) for p in glob.glob(s + '*')]
|
||||||
|
|
||||||
# ignore some suffixes by default, unless the only possible completions
|
# ignore some suffixes by default, unless the only possible completions
|
||||||
|
@ -67,6 +68,7 @@ class FileCompleter(Completer):
|
||||||
|
|
||||||
if candidates2:
|
if candidates2:
|
||||||
candidates = candidates2
|
candidates = candidates2
|
||||||
|
#raise(s + "* :: " + repr(candidates))
|
||||||
return candidates
|
return candidates
|
||||||
|
|
||||||
class BufferCompleter(Completer):
|
class BufferCompleter(Completer):
|
||||||
|
@ -76,7 +78,13 @@ class BufferCompleter(Completer):
|
||||||
return candidates
|
return candidates
|
||||||
|
|
||||||
class CommandCompleter(Completer):
|
class CommandCompleter(Completer):
|
||||||
|
def __init__(self, application):
|
||||||
|
Completer.__init__(self, application)
|
||||||
|
self.fc = FileCompleter(application)
|
||||||
def get_candidates(self, s, w=None):
|
def get_candidates(self, s, w=None):
|
||||||
|
if s.startswith('~') or s.startswith('/') or s.startswith('./') or s.startswith('../'):
|
||||||
|
return self.fc.get_candidates(s)
|
||||||
|
|
||||||
path = os.getenv('PATH')
|
path = os.getenv('PATH')
|
||||||
path_dirs = path.split(':')
|
path_dirs = path.split(':')
|
||||||
candidates = set()
|
candidates = set()
|
||||||
|
|
|
@ -84,7 +84,7 @@ class Man(Exec):
|
||||||
|
|
||||||
class Pipe(Method):
|
class Pipe(Method):
|
||||||
'''Pipe the buffer's contents through the command, and display the output in a new buffer'''
|
'''Pipe the buffer's contents through the command, and display the output in a new buffer'''
|
||||||
args = [Argument('cmd', datatype="str", prompt="Command: ")]
|
args = [Argument('cmd', datatype="shell", prompt="Pipe: ")]
|
||||||
def _parse(self, w, **vargs):
|
def _parse(self, w, **vargs):
|
||||||
# return 3 things: prog name, cmd, and whether to use the shell
|
# return 3 things: prog name, cmd, and whether to use the shell
|
||||||
m = regex.shell_command.match(vargs['cmd'])
|
m = regex.shell_command.match(vargs['cmd'])
|
||||||
|
@ -139,7 +139,7 @@ class Interact(Method):
|
||||||
'''Interact with a program via a PTY'''
|
'''Interact with a program via a PTY'''
|
||||||
args = [Argument('bname', datatype="str", prompt="Buffer Name: ",
|
args = [Argument('bname', datatype="str", prompt="Buffer Name: ",
|
||||||
default=default.build_constant('*Interact*')),
|
default=default.build_constant('*Interact*')),
|
||||||
Argument('cmd', datatype="str", prompt="Command: ",
|
Argument('cmd', datatype="shell", prompt="Command: ",
|
||||||
default=default.build_constant('bash'))]
|
default=default.build_constant('bash'))]
|
||||||
def _execute(self, w, **vargs):
|
def _execute(self, w, **vargs):
|
||||||
bname = vargs['bname']
|
bname = vargs['bname']
|
||||||
|
|
6
util.py
6
util.py
|
@ -1,7 +1,8 @@
|
||||||
import os, pwd, regex
|
import os, pwd, regex
|
||||||
|
|
||||||
def normal_path(path):
|
def normal_path(path):
|
||||||
path = os.path.realpath(path)
|
#path = os.path.realpath(path)
|
||||||
|
path = os.path.normpath(path)
|
||||||
home = os.getenv('HOME')
|
home = os.getenv('HOME')
|
||||||
isdir = os.path.isdir(path)
|
isdir = os.path.isdir(path)
|
||||||
if path.startswith(home):
|
if path.startswith(home):
|
||||||
|
@ -12,6 +13,7 @@ def normal_path(path):
|
||||||
return path
|
return path
|
||||||
|
|
||||||
def expand_tilde(path):
|
def expand_tilde(path):
|
||||||
|
isd = path.endswith('/')
|
||||||
if not path.startswith('~'):
|
if not path.startswith('~'):
|
||||||
return path
|
return path
|
||||||
parts = path.split('/', 1)
|
parts = path.split('/', 1)
|
||||||
|
@ -27,7 +29,7 @@ def expand_tilde(path):
|
||||||
else:
|
else:
|
||||||
s = parts[0]
|
s = parts[0]
|
||||||
s = os.path.realpath(s)
|
s = os.path.realpath(s)
|
||||||
if os.path.isdir(s):
|
if os.path.isdir(s) and isd:
|
||||||
s += '/'
|
s += '/'
|
||||||
return s
|
return s
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue