# exec command or change context
if subcmd.is_command: # exec command
cls = subcmd.get_class()
- if subcmd.path == 'history_load':
+ if subcmd.path == 'history_run':
instance = cls(dict(cmd_parser.arguments), self.cmd_tree)
else:
instance = cls(dict(cmd_parser.arguments))
(num1, num2) = (num1.strip(), num2.strip())
try:
num1 = (-int(num1[1:])) if num1.startswith('-') else int(num1)
- if num1 > 0:
- num1 -= 1
except ValueError as e:
raiseCLIError(e, 'Invalid id %s' % num1)
if sep:
try:
num2 = (-int(num2[1:])) if num2.startswith('-') else int(num2)
+ num2 += 1 if num2 > 0 else 0
except ValueError as e:
raiseCLIError(e, 'Invalid id %s' % num2)
else:
for cmd_id in num_list:
try:
- print(ret[int(cmd_id)][:-1])
+ cur_id = int(cmd_id)
+ if cur_id:
+ print(ret[cur_id - (1 if cur_id > 0 else 0)][:-1])
except IndexError as e2:
raiseCLIError(e2, 'Command id out of 1-%s range' % len(ret))
@command(history_cmds)
-class history_load(_init_history):
+class history_run(_init_history):
"""Run previously executed command(s)"""
_cmd_tree = None
def main(self, *command_ids):
super(self.__class__, self).main()
cmd_list = self._get_cmd_ids(command_ids)
+ print('RANGE: %s' % cmd_list)
for cmd_id in cmd_list:
r = self.history.retrieve(cmd_id)
try:
print('< %s >' % r[:-1])
except (TypeError, KeyError):
- return
+ continue
if self._cmd_tree:
r = r[len('kamaki '):-1] if r.startswith('kamaki ') else r[:-1]
self._run_from_line(r)
def retrieve(self, cmd_id):
"""
- :param cmd_id: (int) the id of the command to retrieve
+ :param cmd_id: (int) the id of the command to retrieve can be positive
+ or negative, zero values are ignored
:returns: (str) the stored command record without the id
"""
cmd_id = int(cmd_id)
+ if not cmd_id:
+ return None
with open(self.filepath) as f:
try:
- return f.readlines()[cmd_id - 1]
+ lala = f.readlines()
+ return lala[cmd_id - (1 if cmd_id > 0 else 0)]
except IndexError:
return None