具有“恢复会话”功能的终端仿真器,类似 Mac Terminal

具有“恢复会话”功能的终端仿真器,类似 Mac Terminal

Mac 终端能够恢复之前的会话。我刚刚重启了 MacBook,当终端打开时,我之前的所有命令都显示在显示屏和所有选项卡中,就好像它从未关闭过一样。只有一小段关于恢复日期的提示。

是否有具有类似功能的 Ubuntu 终端模拟器?

答案1

tmux系统重启后恢复环境。

tmux-resurrect保存 tmux 环境中的所有细节,以便在系统重启后(或在您愿意时)完全恢复。无需配置。您应该感觉从未退出过 tmux。

它甚至(可选)恢复 vim 和 neovim 会话

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

答案2

存在比tmux+更现代的多选项卡终端仿真器tmux-resurrect,其中包括会话/工作区管理(以及保存和恢复功能):

  1. 具有 GPU 渲染功能的现代产品Wez Terminal,内置工作区WezTerm 会话管理器插入。
  2. 一个较老的Terminator,有布局用于会话管理和保存上次会话布局插入。

答案3

保持终端会话持久性的一个好方法是在服务器上运行“screen”会话。“screen”会话会在该服务器上为您提供多个窗口,您可以在其中登录到其他计算机或任何其他设备。您可以在服务器上运行多个“screen”会话。您可以断开连接并重新连接到所需的会话。“screen”是老式的命令行键盘,但值得学习和试用,以了解其工作原理。维基百科screen很好地描述了“GNU Screen 是一个终端多路复用器,...允许用户在单个终端窗口内访问多个单独的登录会话,...即使用户断开连接,远程进程仍会继续运行。”它有几个很大的优点:

  • 易于安装,可在任何 unix(或 cygwin)上运行,无需图形(除了终端文本图形)
  • 提供持久的窗口终端会话(只要服务器没有重新启动)

* 屏幕快速启动 *

阅读全文:gnu.org 屏幕用户手册

  • screen- 运行屏幕以简单地创建新会话

  • screen -ls- 列出正在运行的屏幕会话

  • screen -r 20229.pts-2.bangor- 重新连接到会话

* 屏幕 ESCAPE 字符默认为Ctrl-a*除非某个疯狂的循环程序在 .screenrc 中更改了它,例如,对于不重视进程后台控制的人来说,可以使用“escape ^Zz”。Ctrl-a如果要在屏幕上运行,则要真正进入终端(转到行首),只需执行Ctrl-a Ctrl-a

  • ESCAPE c - 创建新的屏幕窗口

  • ESCAPE 0(或 1 2 3 4 5 6 7 8 9)- 切换到窗口 0(或 1 2 . . )

  • ESCAPE p 或 ESCAPE n - 切换到上一个或下一个窗口

  • ESCAPE "-窗口列表

  • ESCAPE h – 显示屏幕帮助:

                                           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.]

例如重新连接到会话:

$ screen -ls 屏幕上有:24560.pts-6.mabrowka (分离) 20229.pts-2.mabrowka (附加) /var/run/screen/S-garmon 中的 2 个套接字。

$ 屏幕-r 20229.pts-2.mabrowska

命令行帮助:

> $ 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.

以下是一个示例 .screenrc 文件:

$ 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

这不完全是所提问题的答案。

但这实际上就是您要找的答案!>;-)

screen非常有用。

玩得开心!

詹姆士。

相关内容