code: def get_shell_history():
      
      # try for ipython
      if 'get_ipython' in globals():
          a = list(get_ipython().history_manager.input_hist_raw)
          a.reverse()
          return a
  
      elif 'SPYDER_SHELL_ID' in _os.environ:
          try:
              p = _os.path.join(_settings.path_user, ".spyder2", "history.py")
              a = read_lines(p)
              a.reverse()
              return a
          except:
              pass
  
      # otherwise try pyshell or pycrust (requires wx)
      else:
          try:
              import wx
              for x in wx.GetTopLevelWindows():
                  if type(x) in [wx.py.shell.ShellFrame, wx.py.crust.CrustFrame]:
                      a = x.shell.GetText().split(">>>")
                      a.reverse()
                      return a
          except:
              pass
  
      return ['shell history not available']
docs: This only works with some shells.