parent
2953f52068
commit
09123ab192
|
@ -84,8 +84,7 @@ class PipeBuffer(Buffer):
|
||||||
self._lock.release()
|
self._lock.release()
|
||||||
if efd:
|
if efd:
|
||||||
raise Exception, "exception is ready: %s" % repr(efd)
|
raise Exception, "exception is ready: %s" % repr(efd)
|
||||||
except OSError, e:
|
except (OSError, TypeError):
|
||||||
# read error means we're done
|
|
||||||
pass
|
pass
|
||||||
os.close(fd)
|
os.close(fd)
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import glob, os, pwd
|
import glob, os, pwd, sets
|
||||||
import method, util
|
import method, util
|
||||||
|
|
||||||
def find_common_string(candidates):
|
def find_common_string(candidates):
|
||||||
|
@ -78,7 +78,7 @@ class CommandCompleter(Completer):
|
||||||
def get_candidates(self, s, w=None):
|
def get_candidates(self, s, w=None):
|
||||||
path = os.getenv('PATH')
|
path = os.getenv('PATH')
|
||||||
path_dirs = path.split(':')
|
path_dirs = path.split(':')
|
||||||
candidates = []
|
candidates = sets.Set()
|
||||||
for d in path_dirs:
|
for d in path_dirs:
|
||||||
if (not os.path.isdir(d) or not os.access(d, os.R_OK)):
|
if (not os.path.isdir(d) or not os.access(d, os.R_OK)):
|
||||||
continue
|
continue
|
||||||
|
@ -88,8 +88,8 @@ class CommandCompleter(Completer):
|
||||||
elif not p.startswith(s):
|
elif not p.startswith(s):
|
||||||
continue
|
continue
|
||||||
else:
|
else:
|
||||||
candidates.append(p)
|
candidates.add(p)
|
||||||
return candidates
|
return sorted(candidates)
|
||||||
|
|
||||||
class ShellCompleter(Completer):
|
class ShellCompleter(Completer):
|
||||||
def __init__(self, application):
|
def __init__(self, application):
|
||||||
|
|
|
@ -6,6 +6,13 @@ from point import Point
|
||||||
from method import Method
|
from method import Method
|
||||||
from subprocess import Popen, PIPE, STDOUT
|
from subprocess import Popen, PIPE, STDOUT
|
||||||
|
|
||||||
|
class ShellMiniGrammar(Grammar):
|
||||||
|
rules = [
|
||||||
|
PatternRule('word', r'(?:(?:\\.|[^\n\\\'" ])+|"(?:\\.|[^\\\"])*"|\'(?:\\.|[^\\\'])*\')+'),
|
||||||
|
PatternRule('spaces', r' +'),
|
||||||
|
PatternRule('eol', r'\n'),
|
||||||
|
]
|
||||||
|
|
||||||
class ShellExec(Method):
|
class ShellExec(Method):
|
||||||
def _execute(self, w, **vargs):
|
def _execute(self, w, **vargs):
|
||||||
a = w.application
|
a = w.application
|
||||||
|
@ -76,27 +83,17 @@ class ShellTab(Method):
|
||||||
if curr_t is None:
|
if curr_t is None:
|
||||||
return
|
return
|
||||||
|
|
||||||
if(i == 0) and '/' not in curr_t.string:
|
s1 = curr_t.string
|
||||||
# we are completing a command
|
if(curr_i == 0) and '/' not in s1:
|
||||||
candidates = []
|
completer = method.DATATYPES['command']
|
||||||
else:
|
else:
|
||||||
# we are completing a path
|
completer = method.DATATYPES['path']
|
||||||
cwd = os.getcwd()
|
|
||||||
if not cwd.endswith('/'):
|
|
||||||
cwd += '/'
|
|
||||||
path = cwd + curr_t.string
|
|
||||||
(d, name) = os.path.split(path)
|
|
||||||
names = []
|
|
||||||
for x in os.listdir(d):
|
|
||||||
if os.path.isdir(os.path.join(d, x)):
|
|
||||||
names.append(x + '/')
|
|
||||||
else:
|
|
||||||
names.append(x)
|
|
||||||
candidates = [x for x in names if x.startswith(name)]
|
|
||||||
|
|
||||||
s = completer.find_common_string(candidates)[len(name):]
|
s2, exists, complete = completer.tab_string(s1, w)
|
||||||
w.insert_string_at_cursor(s)
|
w.delete(Point(curr_t.x, curr_t.y), Point(curr_t.end_x(), curr_t.y))
|
||||||
mode.mini.use_completion_window(a, name, candidates)
|
w.insert_string_at_cursor(s2)
|
||||||
|
candidates = completer.get_candidates(s1, w)
|
||||||
|
mode.mini.use_completion_window(a, s2, candidates)
|
||||||
|
|
||||||
class ShellBaseMethod(Method):
|
class ShellBaseMethod(Method):
|
||||||
subcls = Method
|
subcls = Method
|
||||||
|
|
Loading…
Reference in New Issue