Overloading a built-in command no longer causes infinite recursion, built-in commands are not lost when overloaded, and multiple commands can be overloaded in the same way. Using an alias to overload a command is still dangerous.
This commit is contained in:
parent
bc70bad1c7
commit
36676e05ef
1 changed files with 8 additions and 4 deletions
12
shell.py
12
shell.py
|
@ -20,7 +20,7 @@
|
|||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
# MA 02110-1301, USA.
|
||||
#
|
||||
# Ver. 0.1.0032
|
||||
# Ver. 0.1.0033
|
||||
|
||||
|
||||
import types as _types
|
||||
|
@ -193,6 +193,7 @@ conventionally called args or argv"""
|
|||
b = self.getBatch(ret[0])
|
||||
if b:
|
||||
ret = b + ret
|
||||
ret[0] = _re.sub(r'\A\$\((\w+)\)', r'\1', ret[0])
|
||||
return ret
|
||||
|
||||
# Default functions
|
||||
|
@ -207,14 +208,15 @@ conventionally called args or argv"""
|
|||
|
||||
def defineBatch(self, args):
|
||||
"""Define a batch file."""
|
||||
if len(args) != 1:
|
||||
raise ValueError('def takes only one argument')
|
||||
if len(args) < 1:
|
||||
raise ValueError('def takes at least one argument')
|
||||
ret = []
|
||||
command = input(self.ps2)
|
||||
while command != 'end':
|
||||
ret.append(command)
|
||||
command = input(self.ps2)
|
||||
self.registerBatch(args[0], ret)
|
||||
for i in args:
|
||||
self.registerBatch(i, ret)
|
||||
|
||||
def batch(self, args):
|
||||
"""Run commands in batch mode
|
||||
|
@ -243,6 +245,8 @@ $>=0 - $>=n is the nth and later arguments"""
|
|||
newLine = newLine.replace(m.group(), ' '.join(args[num:]))
|
||||
else:
|
||||
newLine = newLine.replace(m.group(), args[int(n)])
|
||||
newLine = _re.sub(r'\A({0})'.format(args[0]), r'$(\1)', newLine)
|
||||
#print(newLine)
|
||||
self.handleCommand(self.scanLine(newLine))
|
||||
|
||||
# Beyond this point are functions that are called within the main loop.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue