Skip to content

Instantly share code, notes, and snippets.

@oprypin
Last active March 17, 2022 22:14
Show Gist options
  • Save oprypin/1c280dac719151fb5a26b35fa2fc7b4e to your computer and use it in GitHub Desktop.
Save oprypin/1c280dac719151fb5a26b35fa2fc7b4e to your computer and use it in GitHub Desktop.
Xonsh formatter dict: last return code, duration of last command
last_duration = last_return = 0
orig_append = __xonsh_history__.append
def append(cmd):
nonlocal last_duration, last_return
last_return = cmd['rtn']
a, b = cmd['ts']
last_duration = b - a
orig_append(cmd)
__xonsh_history__.append = append
def fmt_last_duration():
nonlocal last_duration
if last_duration >= 60:
d = round(last_duration)
result = '{}:{:02}'.format(d//60, d%60)
elif last_duration >= 1:
result = '{:.1f}'.format(last_duration)
else:
return
last_duration = 0
return result
def fmt_last_return():
nonlocal last_return
if last_return:
result = str(last_return)
last_return = 0
return result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment