7

The Mac terminal is able to restore a previous session. I just had a MacBook reboot, and when the terminal opened, all my previous commands were there in the display and all the tabs, as if it was never closed. There is only small notice of the restore date.

Is there a terminal emulator for Ubuntu with a similar feature?

dessert
  • 40,956
a06e
  • 14,233

3 Answers3

1

Restore tmux environment after system restart.

tmux-resurrect saves all the little details from your tmux environment so it can be completely restored after a system restart (or when you feel like it). No configuration is required. You should feel like you never quit tmux.

It even (optionally) restores vim and neovim sessions!

https://github.com/tmux-plugins/tmux-resurrect

Limina102
  • 296
1

There exist more modern multi-tab terminal emulators than tmux+tmux-resurrect, which include session/workspace management (together with save and restore functionality):

  1. A modern Wez Terminal with GPU rendering, built-in Workspaces and WezTerm Session Manager plugin.
  2. An older Terminator, which has layouts for session management and save_last_session_layout plugin.
luart
  • 1,020
  • 1
  • 10
  • 8
0

One good way of having terminal sessions that persist is to run a 'screen' session on server. A 'screen' session gives you multiple windows on that server where you can be logged in to other machines or whatever. You can have multiple 'screen' sessions running on server. You can disconnect and reconnect to the sessions you need. 'screen' is old-school command-line keyboard but well worth learning and playing with to learn how it works. wikipedia describes screen well "GNU Screen is a terminal multiplexer, ... allowing a user to access multiple separate login sessions inside a single terminal window, ... a remote process continues running even when the user is disconnected." It has a few big advantages:

  • easy to install, runs on any unix(or cygwin), no graphics needed (besides terminal text graphics)
  • gives persistent windowed terminal sessions (as long as server is not rebooted)

* screen quickstart *

RTFM: gnu.org Screen User's Manual

  • screen - Run screen to create a new session simply

  • screen -ls - list screen sessions running

  • screen -r 20229.pts-2.bangor - re-attach to session

The * screen ESCAPE char by default is Ctrl-a * unless some craZy looper has changed it in .screenrc e.g. "escape ^Zz" for people who don't value process backgrounding control. To get a real Ctrl-a to terminal (goto beginning of line) if running in screen then just do Ctrl-a Ctrl-a.

  • ESCAPE c - create new screen window

  • ESCAPE 0 (or 1 2 3 4 5 6 7 8 9) - switch to window 0 (or 1 2 . . )

  • ESCAPE p or ESCAPE n - switch to previous or next window

  • ESCAPE " - window list

  • ESCAPE h - shows screen help:

                                           Screen key bindings, page 1 of 1.
                                       Command key:  ^A   Literal ^A:  a

break ^B b help ? monitor M remove X version v
clear C history { } next ^@ ^N sp n removebuf = width W
colon : info i number N reset Z windows ^W w
copy ^[ [ kill K only Q screen ^C c wrap ^R r
detach ^D d lastmsg ^M m other ^Z select ' writebuf >
digraph ^V license , pow_break B silence _ xoff ^S s
displays * lockscreen ^X x pow_detach D split S xon ^Q q
fit F log H prev ^H ^P p ^? time ^T t
flow ^F f login L readbuf < title A
focus ^I meta z redisplay ^L l vbell ^G

^] paste [.] " windowlist -b

  • select -

0 select 0 1 select 1 2 select 2 3 select 3 4 select 4 5 select 5 6 select 6 7 select 7 8 select 8 9 select 9 I login on O login off ] paste . | split -v :kB: focus prev

                                        [Press Space or Return to end.]

e.g. reattaching to a session:

$ screen -ls There are screens on: 24560.pts-6.mabrowka (Detached) 20229.pts-2.mabrowka (Attached) 2 Sockets in /var/run/screen/S-garmon.

$ screen -r 20229.pts-2.mabrowska

command-line help:

> $ screen --help Use: screen [-opts] [cmd [args]]  or: screen -r
> [host.tty]
> 
> Options:
> -4            Resolve hostnames only to IPv4 addresses.
> -6            Resolve hostnames only to IPv6 addresses.
> -a            Force all capabilities into each window's termcap.
> -A -[r|R]     Adapt all windows to the new display width & height.
> -c file       Read configuration file instead of '.screenrc'.
> -d (-r)       Detach the elsewhere running screen (and reattach here).
> -dmS name     Start as daemon: Screen session in detached mode.
> -D (-r)       Detach and logout remote (and reattach here).
> -D -RR        Do whatever is needed to get a screen session.
> -e xy         Change command characters.
> -f            Flow control on, -fn = off, -fa = auto.
> -h lines      Set the size of the scrollback history buffer.
> -i            Interrupt output sooner when flow control is on.
> -l            Login mode on (update /var/run/utmp), -ln = off.
> -ls [match]   or
> -list         Do nothing, just list our SockDir [on possible matches].
> -L            Turn on output logging.
> -m            ignore $STY variable, do create a new screen session.
> -O            Choose optimal output rather than exact vt100 emulation.
> -p window     Preselect the named window if it exists.
> -q            Quiet startup. Exits with non-zero return code if unsuccessful.
> -Q            Commands will send the response to the stdout of the querying process.
> -r [session]  Reattach to a detached screen process.
> -R            Reattach if possible, otherwise start a new session.
> -s shell      Shell to execute rather than $SHELL.
> -S sockname   Name this session <pid>.sockname instead of <pid>.<tty>.<host>.
> -t title      Set title. (window's name).
> -T term       Use term as $TERM for windows, rather than "screen".
> -U            Tell screen to use UTF-8 encoding.
> -v            Print "Screen version 4.01.00devel (GNU) 2-May-06".
> -wipe [match] Do nothing, just clean up SockDir [on possible matches].
> -x            Attach to a not detached screen. (Multi display mode).
> -X            Execute <cmd> as a screen command in the specified session.

And an example .screenrc file:

$ cat .screenrc
#
# Example of a user's .screenrc file
#

# This is how one can set a reattach password:
# password ODSJQf.4IJN7E    # "1234"

# no annoying audible bell, please
vbell on

# detach on hangup
autodetach on

# don't display the copyright page
startup_message off

# emulate .logout message
pow_detach_msg "Screen session of \$LOGNAME \$:cr:\$:nl:ended."

# advertise hardstatus support to $TERMCAP
# termcapinfo  * '' 'hs:ts=\E_:fs=\E\\:ds=\E_\E\\'

# make the shell in every window a login shell
#shell -$SHELL

# autoaka testing
# shellaka '> |tcsh'
# shellaka '$ |sh'

# set every new windows hardstatus line to somenthing descriptive
# defhstatus "screen: ^En (^Et)"

defscrollback 1000

# don't kill window after the process died
# zombie "^["

################
#
# xterm tweaks
#

#xterm understands both im/ic and doesn't have a status line.
#Note: Do not specify im and ic in the real termcap/info file as
#some programs (e.g. vi) will not work anymore.
termcap  xterm hs@:cs=\E[%i%d;%dr:im=\E[4h:ei=\E[4l
terminfo xterm hs@:cs=\E[%i%p1%d;%p2%dr:im=\E[4h:ei=\E[4l

#80/132 column switching must be enabled for ^AW to work
#change init sequence to not switch width
termcapinfo  xterm Z0=\E[?3h:Z1=\E[?3l:is=\E[r\E[m\E[2J\E[H\E[?7h\E[?1;4;6l

# Make the output buffer large for (fast) xterms.
termcapinfo xterm* OL=10000

# tell screen that xterm can switch to dark background and has function
# keys.
termcapinfo xterm 'VR=\E[?5h:VN=\E[?5l'
termcapinfo xterm 'k1=\E[11~:k2=\E[12~:k3=\E[13~:k4=\E[14~'
termcapinfo xterm 'kh=\E[1~:kI=\E[2~:kD=\E[3~:kH=\E[4~:kP=\E[H:kN=\E[6~'

# special xterm hardstatus: use the window title.
termcapinfo xterm 'hs:ts=\E]2;:fs=\007:ds=\E]0;screen\007'

# our xterm has colors! (rxvt, too)
termcap  xterm 'AF=\E[3%dm:AB=\E[4%dm'
terminfo xterm 'AF=\E[3%p1%dm:AB=\E[4%p1%dm'

#terminfo xterm 'vb=\E[?5h$<200/>\E[?5l'
termcapinfo xterm 'vi=\E[?25l:ve=\E[34h\E[?25h:vs=\E[34l'

# emulate part of the 'K' charset
termcapinfo   xterm 'XC=K%,%\E(B,[\304,\\\\\326,]\334,{\344,|\366,}\374,~\337'

# xterm-52 tweaks:
# - uses background color for delete operations
# - maps F1-4 to PF1-4
# termcapinfo xterm ut
# termcapinfo xterm 'k1=\EOP:k2=\EOQ:k3=\EOR:k4=\EOS'

################
#
# wyse terminals
#

#wyse-75-42 must have flow control (xo = "terminal uses xon/xoff")
#essential to have it here, as this is a slow terminal.
termcapinfo wy75-42 xo:hs@

# New termcap sequences for cursor application mode.
termcapinfo wy* CS=\E[?1h:CE=\E[?1l:vi=\E[?25l:ve=\E[?25h:VR=\E[?5h:VN=\E[?5l:cb=\E[1K:CD=\E[1J

################
#
# other terminals
#

#make hp700 termcap/info better
termcapinfo  hp700 'Z0=\E[?3h:Z1=\E[?3l:hs:ts=\E[62"p\E[0$~\E[2$~\E[1$}:fs=\E[0}\E[61"p:ds=\E[62"p\E[1$~\E[61"p:ic@'

# Extend the vt100 desciption by some sequences.
termcap  vt100* ms:AL=\E[%dL:DL=\E[%dM:UP=\E[%dA:DO=\E[%dB:LE=\E[%dD:RI=\E[%dC
terminfo vt100* ms:AL=\E[%p1%dL:DL=\E[%p1%dM:UP=\E[%p1%dA:DO=\E[%p1%dB:LE=\E[%p1%dD:RI=\E[%p1%dC


################
#
# keybindings
#

#remove some stupid / dangerous key bindings
bind k
bind ^k
bind .
bind ^\
bind \\
#bind ^h
bind h
#make them better
bind '\\' quit
bind 'K' kill
bind 'I' login on
bind 'O' login off
bind '}' history

# Yet another hack:
# Prepend/append register [/] to the paste if ^a^] is pressed.
# This lets me have autoindent mode in vi.
register [ "\033:se noai\015a"
register ] "\033:se ai\015a"
bind ^] paste [.]

################
#
# default windows
#

# screen -t local 0
# screen -t mail 1 elm
# screen -t 40 2 rlogin faui40

# yeah, please don't re-map the screen ESCAPE char 
#  there could be wailing and gNasHing of teeth
#  anyway this is how you would do it if you were a cRaZy loOpeR:
#escape ^Zz

This is not ~quite~ eXacTly the answer to the question asked.

But it IS actually the answer you were looking for! >;-)

screen is very useful.

Have fun!

James.

gaoithe
  • 541