Commit d2c1b08e authored by Keegi's avatar Keegi

alias tab-completion and better integration to built-in help

parent efaf64de
...@@ -91,7 +91,7 @@ class pronsole(cmd.Cmd): ...@@ -91,7 +91,7 @@ class pronsole(cmd.Cmd):
if alias_def.lower() == "/d": if alias_def.lower() == "/d":
# delete alias # delete alias
if alias_name in self.aliases.keys(): if alias_name in self.aliases.keys():
delattr(self,"do_"+alias_name) delattr(self.__class__,"do_"+alias_name)
del self.aliases[alias_name] del self.aliases[alias_name]
print "Alias '"+alias_name+"' removed" print "Alias '"+alias_name+"' removed"
return return
...@@ -99,9 +99,10 @@ class pronsole(cmd.Cmd): ...@@ -99,9 +99,10 @@ class pronsole(cmd.Cmd):
print "Alias '"+alias_name+"' is not defined" print "Alias '"+alias_name+"' is not defined"
return return
# (re)define an alias # (re)define an alias
func = lambda args,self=self,alias_def=alias_def: self.onecmd(" ".join((alias_def,args))) func = lambda self,args,alias_def=alias_def: self.onecmd(" ".join((alias_def,args)))
self.aliases[alias_name] = alias_def self.aliases[alias_name] = alias_def
setattr(self,"do_"+alias_name,func) setattr(self.__class__,"do_"+alias_name,func)
setattr(self.__class__,"help_"+alias_name,lambda self=self,alias_name=alias_name: self.subhelp_alias(alias_name))
def help_alias(self): def help_alias(self):
print "Create/modify/view aliases: alias <name> [<command>]" print "Create/modify/view aliases: alias <name> [<command>]"
...@@ -109,6 +110,17 @@ class pronsole(cmd.Cmd): ...@@ -109,6 +110,17 @@ class pronsole(cmd.Cmd):
print "without arguments, displays list of all defined aliases" print "without arguments, displays list of all defined aliases"
print "To remove an alias: alias <name> /d" print "To remove an alias: alias <name> /d"
def complete_alias(self,text,line,begidx,endidx):
if (len(line.split())==2 and line[-1] != " ") or (len(line.split())==1 and line[-1]==" "):
return [i for i in self.aliases.keys() if i.startswith(text)]
elif(len(line.split())==3 or (len(line.split())==2 and line[-1]==" ")):
return self.completenames(text)
else:
return []
def subhelp_alias(self,alias_name):
print "'"+alias_name+"' is alias for '"+self.aliases[alias_name]+"'"
def postloop(self): def postloop(self):
self.p.disconnect() self.p.disconnect()
cmd.Cmd.postloop(self) cmd.Cmd.postloop(self)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment