From 0ec3b413135b9cdbc68f5d8f24ee094224335a73 Mon Sep 17 00:00:00 2001 From: "Iury O. G. Figueiredo" Date: Sat, 26 Oct 2019 21:47:30 -0300 Subject: [PATCH] Adding filter to list just files no dirs. --- vyapp/plugins/fsniffer.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/vyapp/plugins/fsniffer.py b/vyapp/plugins/fsniffer.py index 75741b3..96a4e6b 100644 --- a/vyapp/plugins/fsniffer.py +++ b/vyapp/plugins/fsniffer.py @@ -55,13 +55,13 @@ def set_wide(cls, event): root.status.set_msg('Set wide search: %s' % FSniffer.wide) def update_pattern(self, wid): - pattern = ' '.join(self.make_cmd(wid.get())) - root.status.set_msg('Unix locate cmd: %s' % pattern) + pattern = build_regex(wid.get(), '.*') + root.status.set_msg('File pattern: %s' % pattern) def make_cmd(self, pattern): # When FSniffer.wide is False it searches in the current # Areavi instance project. - cmd = ['locate', '--limit', '50'] + cmd = ['locate', '--limit', '200'] regex = build_regex(pattern, '.*') if self.wide or not self.area.project: @@ -69,12 +69,17 @@ def make_cmd(self, pattern): else: cmd.extend(['--regexp', '%s.*%s' % ( self.area.project, regex)]) + + # Used to filter only files because locate doesn't support + # searching only for files. + cmd = '%s | %s' % (' '.join(cmd), '''while read -r file; do + [ -d "$file" ] || printf '%s\n' "$file"; done''') return cmd def run_cmd(self, pattern): cmd = self.make_cmd(pattern) child = Popen(cmd, stdout=PIPE, stderr=STDOUT, - encoding=self.area.charset) + encoding=self.area.charset, shell=True) output = child.communicate()[0] return output