From ae16a9a61c2b65388ecf41d85fb659c827e76fcc Mon Sep 17 00:00:00 2001 From: Rob Austein Date: Mon, 8 Mar 2010 16:42:14 +0000 Subject: Tweak completion to behave as a bash user would expect. svn path=/rpkid/rpki/cli.py; revision=3042 --- rpkid/rpki/cli.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'rpkid') diff --git a/rpkid/rpki/cli.py b/rpkid/rpki/cli.py index d5a0ca71..2443e1b3 100644 --- a/rpkid/rpki/cli.py +++ b/rpkid/rpki/cli.py @@ -18,7 +18,7 @@ OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. """ -import cmd, glob +import cmd, glob, os.path try: import readline @@ -61,7 +61,20 @@ class Cmd(cmd.Cmd): cmd.Cmd.emptyline(self) def filename_complete(self, text, line, begidx, endidx): - return glob.glob(text + "*") + result = glob.glob(text + "*") + if len(result) == 1: + path = result.pop() + if os.path.isdir(path) or (os.path.islink(path) and os.path.isdir(os.path.join(path, "."))): + result.append(path + os.path.sep) + else: + result.append(path + " ") + return result + + def completenames(self, *args): + result = set(cmd.Cmd.completenames(self, *args)) + if len(result) == 1: + result.add(result.pop() + " ") + return list(result) if have_readline: -- cgit v1.2.3