재부팅을 통해 OS X 터미널 세션은 어떻게 유지됩니까?


14

MacBook Pro를 구입하기 전에 열렬한 Linux 사용자이기 때문에 일반적으로 한 번에 여러 개의 터미널 탭이 열려 있습니다.

과거에는 충돌 및 재부팅으로 인해 일반적으로 워크 플로 및 대부분의 각 탭 기록이 손상되었습니다. 이 문제를 해결할 방법을 찾았지만 항상 비어있었습니다. ssh,, screen등 의 도구 조합을 활용 tmux하고 가상 사설 서버 (또는 이와 유사한)가 필요한 다양한 기술을 제외하고 .

스크립트 작성을 위해 MacBook Pro를 사용하고 CLI 도구를 사용하는 것에 대해 내가 가장 좋아하는 것 중 하나; 내 터미널 세션은 기본적으로 충돌 및 재부팅을 넘어 지속됩니다. 실제로, 나는 거의 2 년 전에 백업을 복원했으며, 처음 로그인했을 때, 나는 이전 bash에 작업했던 프로젝트를 구성하는 오래된 데스크탑과 3 개의 쉘을 받았습니다 .

OS X이 어떻게이 기능을 가능하게하는지 알고 싶습니다. 여기 아무도 어떻게 작동하는지 통찰력이 있습니까?

답변:


10

코드는 터미널 (실제로 복원 bash세션)의 일부 /etc/bashrc_Apple_Terminal를 통해 공급됩니다있는 /etc/profile및 /etc/bashrc각 bash터미널에서 실행하는 세션.

# Resume Support: Save/Restore Shell State
#
# Terminal assigns each terminal session a unique identifier and
# communicates it via the TERM_SESSION_ID environment variable so that
# programs running in a terminal can save/restore application-specific
# state when quitting and restarting Terminal with Resume enabled.
#
# The following code defines a shell save/restore mechanism. Users can
# add custom state by defining a shell_session_save_user_state function
# that writes restoration commands to the session file at exit. e.g.,
# to save a variable:
#
#   shell_session_save_user_state() { echo MY_VAR="'$MY_VAR'" >> "$SHELL_SESSION_FILE"; }
#
# During shell startup the session file is executed. Old files are
# periodically deleted.
#
# The default behavior arranges to save and restore the bash command
# history independently for each restored terminal session. It also
# merges commands into the global history for new sessions. Because
# of this it is recommended that you set HISTSIZE and HISTFILESIZE to
# larger values.
#
# You may disable this behavior and share a single history by setting
# SHELL_SESSION_HISTORY to 0. There are some common user customizations
# that arrange to share new commands among running shells by
# manipulating the history at each prompt, and they typically include
# 'shopt -s histappend'; therefore, if the histappend shell option is
# enabled, per-session history is disabled by default. You may
# explicitly enable it by setting SHELL_SESSION_HISTORY to 1.
#
# The implementation of per-session command histories in combination
# with a shared global command history is incompatible with the
# HISTTIMEFORMAT variable--the timestamps are applied inconsistently
# to different parts of the history; therefore, if HISTTIMEFORMAT is
# defined, per-session history is disabled by default.
#
# Note that this uses PROMPT_COMMAND to enable per-session history
# the first time for each new session. If you customize PROMPT_COMMAND
# be sure to include the previous value. e.g.,
#
#   PROMPT_COMMAND="${PROMPT_COMMAND:+$PROMPT_COMMAND; }your_code_here"
#
# Otherwise, the per-session history won't take effect until the first
# restore.
#
# The save/restore mechanism is disabled if the following file exists:
#
#   ~/.bash_sessions_disable

1
이 의견은 쿨 /etc/bashrc_Apple_Terminal? 나는 특히 그것을 좋아한다. # The default behavior arranges to save and restore the bash command history independently for each restored terminal session. It also # merges commands into the global history for new sessions.그것은 내가 전에 구현하려고 시도한 다른 것이지만, 아무 소용이 없다.
— 목소리

어쨌든 나는 이것을 대답으로 표시하고 싶지만이 파일을 읽었으며 ..이 효과를 일으키는 특정 코드 줄을 지적 할 수 있습니까? 의견에 언급 된 기능보다 더 많은 것으로 보입니다. 피곤한 눈일 수도 있지만, 이해가되지 않습니다.
— 목소리

@ tjt263 아직 알아낼 ​​시간을 찾지 못했습니다
— nohillside

@ tjt263 실제로 파일의 끝까지 주석부터 모든 것입니다. 기본적으로 trap세션의 끝을 잡아서 탭 / 세션 특정 파일에 기록을 저장하는 데 사용 됩니다.
— nohillside

7

내가 알 수있는 한, 그것은 각 창의 스크롤 백 버퍼에 텍스트를 저장합니다. 실제로 터미널에서 실행중인 상태를 저장하지는 않습니다. 재부팅 후 새로운 쉘을 시작합니다.

실험으로 쉘에서 변수를 정의하고 그 값을 확인하십시오.

foo=bar
echo $foo

그런 다음 재부팅하고 변수 값을 다시 확인하십시오. 더 이상 정의되지 않은 것을 볼 수 있습니다.


아휴! 그렇지 않으면 소름 끼쳤을 것입니다.
— uhoh
당사 사이트를 사용함과 동시에 당사의 쿠키 정책과 개인정보 보호정책을 읽고 이해하였음을 인정하는 것으로 간주합니다.
Licensed under cc by-sa 3.0 with attribution required.