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,
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||||
# MA 02110-1301, USA.
|
# MA 02110-1301, USA.
|
||||||
#
|
#
|
||||||
# Ver. 0.1.0032
|
# Ver. 0.1.0033
|
||||||
|
|
||||||
|
|
||||||
import types as _types
|
import types as _types
|
||||||
|
@ -193,6 +193,7 @@ conventionally called args or argv"""
|
||||||
b = self.getBatch(ret[0])
|
b = self.getBatch(ret[0])
|
||||||
if b:
|
if b:
|
||||||
ret = b + ret
|
ret = b + ret
|
||||||
|
ret[0] = _re.sub(r'\A\$\((\w+)\)', r'\1', ret[0])
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
# Default functions
|
# Default functions
|
||||||
|
@ -207,14 +208,15 @@ conventionally called args or argv"""
|
||||||
|
|
||||||
def defineBatch(self, args):
|
def defineBatch(self, args):
|
||||||
"""Define a batch file."""
|
"""Define a batch file."""
|
||||||
if len(args) != 1:
|
if len(args) < 1:
|
||||||
raise ValueError('def takes only one argument')
|
raise ValueError('def takes at least one argument')
|
||||||
ret = []
|
ret = []
|
||||||
command = input(self.ps2)
|
command = input(self.ps2)
|
||||||
while command != 'end':
|
while command != 'end':
|
||||||
ret.append(command)
|
ret.append(command)
|
||||||
command = input(self.ps2)
|
command = input(self.ps2)
|
||||||
self.registerBatch(args[0], ret)
|
for i in args:
|
||||||
|
self.registerBatch(i, ret)
|
||||||
|
|
||||||
def batch(self, args):
|
def batch(self, args):
|
||||||
"""Run commands in batch mode
|
"""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:]))
|
newLine = newLine.replace(m.group(), ' '.join(args[num:]))
|
||||||
else:
|
else:
|
||||||
newLine = newLine.replace(m.group(), args[int(n)])
|
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))
|
self.handleCommand(self.scanLine(newLine))
|
||||||
|
|
||||||
# Beyond this point are functions that are called within the main loop.
|
# Beyond this point are functions that are called within the main loop.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue