From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mogw1038.ocn.ad.jp (mogw1038.ocn.ad.jp [153.149.231.44]) by dpdk.org (Postfix) with ESMTP id 1A2774C88 for ; Tue, 6 Mar 2018 11:39:45 +0100 (CET) Received: from mf-smf-ucb020c2 (mf-smf-ucb020c2.ocn.ad.jp [153.153.66.134]) by mogw1038.ocn.ad.jp (Postfix) with ESMTP id 6064D110047B; Tue, 6 Mar 2018 19:39:43 +0900 (JST) Received: from ntt.pod01.mv-mta-ucb027 ([153.149.142.101]) by mf-smf-ucb020c2 with ESMTP id tA0TeOU3OQByztA0VeCezG; Tue, 06 Mar 2018 19:39:43 +0900 Received: from smtp.ocn.ne.jp ([153.149.227.133]) by ntt.pod01.mv-mta-ucb027 with id Jafj1x0032tKTyH01afjy4; Tue, 06 Mar 2018 10:39:43 +0000 Received: from localhost.localdomain (sp1-66-103-93.msc.spmode.ne.jp [1.66.103.93]) by smtp.ocn.ne.jp (Postfix) with ESMTPA; Tue, 6 Mar 2018 19:39:43 +0900 (JST) From: ogawa.yasufumi@lab.ntt.co.jp To: ferruh.yigit@intel.com, spp@dpdk.org Cc: Yasufumi Ogawa Date: Tue, 6 Mar 2018 19:39:20 +0900 Message-Id: <20180306103929.64809-4-ogawa.yasufumi@lab.ntt.co.jp> X-Mailer: git-send-email 2.13.1 In-Reply-To: <20180306103929.64809-1-ogawa.yasufumi@lab.ntt.co.jp> References: <20180306103929.64809-1-ogawa.yasufumi@lab.ntt.co.jp> Subject: [spp] [PATCH 03/12] spp: add completion for ls command X-BeenThere: spp@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Soft Patch Panel List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 06 Mar 2018 10:39:45 -0000 From: Yasufumi Ogawa Signed-off-by: Yasufumi Ogawa --- src/spp.py | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/src/spp.py b/src/spp.py index 7b0b64f..06f5032 100755 --- a/src/spp.py +++ b/src/spp.py @@ -692,9 +692,46 @@ class Shell(cmd.Cmd, object): else: print("No such a directory.") + def ls_decorate_dir(self, filelist): + res = [] + for f in filelist: + if os.path.isdir(f): + res.append('%s/' % f) + else: + res.append(f) + return res + + def complete_ls(self, text, line, begidx, endidx): + if text == '': + tokens = line.split(' ') + target = tokens[-1] + if target == '': + completions = self.ls_decorate_dir( + os.listdir(os.getcwd())) + else: + completions = self.ls_decorate_dir( + os.listdir(target)) + else: + tokens = line.split(' ') + target = tokens[-1] + + if '/' in target: + seg = target.split('/')[-1] + target_dir = '/'.join(target.split('/')[0:-1]) + else: + seg = text + target_dir = os.getcwd() + + matched = [] + for t in os.listdir(target_dir): + if seg in t: + matched.append(t) + completions = self.ls_decorate_dir(matched) + return completions + def do_ls(self, args): if args == '' or os.path.isdir(args): - c = 'ls %s' % args + c = 'ls -F %s' % args subprocess.call(c, shell=True) else: print("No such a directory.") -- 2.13.1