From anonymous, 3 Weeks ago, written in Python.
Embed
  1. from qutebrowser.api import cmdutils
  2.  
  3. @cmdutils.register()
  4. @cmdutils.argument('tab', value=cmdutils.Value.cur_tab)
  5. @cmdutils.argument('count', value=cmdutils.Value.count)
  6. def back_or_close(tab, count=1):
  7.     """Go back or close tab, if at beginning of history."""
  8.     if tab.history.can_go_back():
  9.         try:
  10.             tab.history.back(count)
  11.         except browsertab.WebTabError as e:
  12.             raise cmdutils.CommandError(e)
  13.     else:
  14.         tab.window_close_requested.emit()
  15.