Commit c829cbc4 authored by Keegi's avatar Keegi

Proper alias support (no tab completion yet)

parent 41c4f604
# Sample .pronsolerc file - copy this into your home directory # Sample .pronsolerc file - copy this into your home directory
!self.do_alias = lambda aarg,self=self: setattr(self,"do_"+aarg.split()[0],lambda arg,self=self,a=aarg.split(None,1)[1]:self.onecmd(" ".join((a,arg))))
alias up move Z 10 alias up move Z 10
alias loud !self.loud = 1 alias loud !self.loud = 1
alias quiet !self.loud = 0 alias quiet !self.loud = 0
alias home_all G28
...@@ -39,6 +39,7 @@ class pronsole(cmd.Cmd): ...@@ -39,6 +39,7 @@ class pronsole(cmd.Cmd):
self.bedtemps={"pla":"60","abs":"110","off":"0"} self.bedtemps={"pla":"60","abs":"110","off":"0"}
self.percentdone=0 self.percentdone=0
self.tempreadings="" self.tempreadings=""
self.aliases=[]
def scanserial(self): def scanserial(self):
"""scan for available ports. return a list of device names.""" """scan for available ports. return a list of device names."""
...@@ -69,6 +70,47 @@ class pronsole(cmd.Cmd): ...@@ -69,6 +70,47 @@ class pronsole(cmd.Cmd):
def help_gcodes(self): def help_gcodes(self):
print "Gcodes are passed through to the printer as they are" print "Gcodes are passed through to the printer as they are"
def do_alias(self,l):
if l == "":
# list aliases
if len(self.aliases):
self.print_topics("Aliases, to display type: alias <name>",self.aliases,15,80)
else:
print "No aliases defined, to define see: help alias"
return
alias_l = l.split(None,1)
alias_name = alias_l[0]
if len(alias_l) < 2:
# display alias
if alias_name in self.aliases:
print self.__dict__["do_"+alias_name].func_doc
else:
print "Alias '"+alias_name+"' is not defined"
return
alias_name,alias_def = alias_l
if alias_def.lower() == "/d":
# delete alias
if alias_name in self.aliases:
delattr(self,"do_"+alias_name)
self.aliases.remove(alias_name)
print "Alias '"+alias_name+"' removed"
return
else:
print "Alias '"+alias_name+"' is not defined"
return
# (re)define an alias
func = lambda args,self=self,alias_def=alias_def: self.onecmd(" ".join((alias_def,args)))
func.func_doc = "Alias '"+alias_name+"' stands for '"+alias_def+"'"
setattr(self,"do_"+alias_name,func)
if alias_name not in self.aliases:
self.aliases.append(alias_name)
def help_alias(self):
print "Create/modify/view aliases: alias <name> [<command>]"
print "if <command> is not specified, displays the alias definition"
print "without arguments, displays list of all defined aliases"
print "To remove an alias: alias <name> /d"
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