새 셸 세션을 시작할 때마다 TMUX를 활성화하려면 어떻게해야합니까?
tmux
매번 입력하는 대신 새 세션 창에 어떻게 항상 사용할 수 있었tmux
습니까?
따라서 터미널 창이 열려 있지 않고 하나를 열면 첫 번째 세션이 어떻게 될 수 tmux
있습니까?
.bashrc
아마도 일종의 것 같 습니까?
경고 이것은 이제 우분투 로그인을 '손상'할 수 있습니다 (터미널 창을 열 수 없게 만듭니다-좋지 않습니다!). 극도의주의를 기울여 사용하고 내가 한 것과 동일한 문제가 발생할 경우 로그인 할 수있는 두 번째 관리자 계정이 컴퓨터에 있는지 확인하십시오. 자세한 내용과 다른 접근 방식은 다른 답변을 참조하십시오.
그 경고가 주어지면 가장 간단한 해결책은 tmux
호출을 .bashrc
, 예를 들어 끝에 추가하는 것입니다 .
alias g="grep"
alias ls="ls --color=auto"
# ...other stuff...
if [[ ! $TERM =~ screen ]]; then
exec tmux
fi
참고 그 exec
수단 당신이 터미널이되어 열 때 시작 bash는 프로세스를 대체 함으로써 tmux
그래서, Ctrl-B D
아마도 당신이 원하는 행동이다 (즉, 분리가 TMUX에서) 실제로 대신 원래의 bash는 프로세스를 반환하는 창을 닫습니다?
또한 if
명령문이 필요합니다 (현재 bash 창이 이미 tmux 프로세스에 있는지 감지). 그렇지 않으면 tmux를 시작할 때마다 포함 된 bash 프로세스가 자체 tmux 세션을 시작하려고 시도하여 무한한 수의 중첩 된 tmuxen을 생성합니다. 오류가 발생할 수 있습니다 (즉, 멋져 보입니다).
그러나 bash
bash를 실행하면 tmux 프로세스로 전환 될 수 있으므로 다른 프로그램이 예상하지 못한 방식으로 작동 할 수있는 매우 작은 위험이 있으므로 터미널 에뮬레이터를 시작하는 방법을 수정하는 것이 더 나을 수 있습니다. .
다음과 같은 작은 실행 가능한 쉘 스크립트 ~/bin/terminal
( ~/bin
in 과 함께 $PATH
자동으로 발견됨)를 사용합니다.
#!/bin/sh
exec gnome-terminal -e tmux
(그놈 터미널을 사용하지 않으므로을 제거해야 할 수도 있지만 exec
확실하지 않습니다.)
이제 terminal
scipt 를 실행할 때마다 tmux가있는 터미널이 있습니다. 메뉴 / 데스크톱 / 키보드 바로 가기에이를 추가하여 기본 터미널을 대체 할 수 있습니다.
(이 접근 방식을 사용하면 나중에 원하는 경우 터미널 에뮬레이터에 대한 다른 사항을보다 쉽게 사용자 지정할 수 있습니다.)
내 원래의 대답은 최근 업그레이드 후 Ubuntu14 시스템에서 작동을 멈췄습니다.
둘 중 하나 사용
[ -z "$TMUX" ] && command -v tmux > /dev/null && TERM=xterm-256color && exec tmux
또는
[ $TERM != "screen" ] && TERM=xterm-256color && exec tmux
로그인조차 할 수 없게됩니다. 컴퓨터에 두 번째 관리자 로그인이 있었기 때문에이 문제를 해결할 수있었습니다.
Ubuntu (및 osx에서도)에서 나를 위해 수정 한 것은 터미널 프로그램을 실제로 대신 tmux를 실행하도록 변경하는 것입니다.
나는 아직도 가지고있다
[ `uname -s` != Linux ] && exec tmux
내 마지막 .bashrc
줄이지 만 지금은 내 Mac OSX 시스템에만 해당됩니다.
단일 tmux 세션을 사용하려면 bash 의 경우 ~ / .bashrc 또는 zsh의 경우 ~ / .zshrc에 다음을 입력하십시오 .
tmux attach &> /dev/null
if [[ ! $TERM =~ screen ]]; then
exec tmux
fi
tmux attach
라인 이 부착 세션이있는 경우 있는지 확인하는 것입니다 아무 세션이 없었다 경우 "에 대한 경고받지 않습니다 어떤 세션을 ".
나에게는 원격 시스템에 쉘을 넣을 때마다 tmux가 시작되기를 원하며 tmux를 분리하거나 종료 할 때 연결이 자동으로 닫혀 야합니다. 잠시이 문제를 파헤친 후 다음 코드는 내가 원하는 것을 정확히 수행하며 내가 아는 한 가장 최적화 된 것으로 여겨집니다.
[ -z "$TMUX" ] && { tmux attach || exec tmux new-session && exit;}
이 행은 bashrc 파일의 첫 번째 행이어야 먼저로드되었는지 확인합니다. exec가 bash 프로세스를 tmux 프로세스로 바꾼 후 연결할 세션이 없더라도 연결이 닫히기 때문에 "tmux attach"앞에 "exec"호출을 넣을 수 없습니다. 따라서 연결된 세션에서 분리하거나 종료 한 후 연결을 종료하려면 "exit"호출이 필요합니다. 그러나 new-session 명령 앞에 "exec"를 추가하는 것은 실행될 마지막 명령이므로 괜찮습니다.
다음 코드 줄 을의 끝에 추가 하십시오 .bashrc
.
[[ $TERM != "screen" ]] && exec tmux
방금 키보드 바로 가기로 만들었습니다 (Ubuntu가 아닌 Linux Mint에서이게 쉬운 지 모르겠습니다) ...
It might be hard to see, but the custom shortcut is gnome-terminal --window --maximize -e tmux
. This starts a new gnome-terminal
window maximized and then exec
utes tmux
for you.
I additionally have another custom shortcut that starts a "normal" gnome-terminal
maximized (it's the same without the -e tmux
).
I feel this is the best way because you can start whatever terminal whatever way you want and is the most customizable way.
I started with this https://wiki.archlinux.org/index.php/Tmux#Bash and enhanced it to reclaim detached sessions and make new ones if all sessions were already attached
# .bashrc
case $- in
*i*)
if command -v tmux>/dev/null; then
if [[ ! $TERM =~ screen ]] && [[ -z $TMUX ]]; then
if tmux ls 2> /dev/null | grep -q -v attached; then
exec tmux attach -t $(tmux ls 2> /dev/null | grep -v attached | head -1 | cut -d : -f 1)
else
exec tmux
fi
fi
fi
;;
esac
To enable tmux for login and ssh sessions, you can add this to the end of your .bashrc:
# enable tmux at login
PNAME="$(ps -o comm= $PPID)";
if [ $PNAME == "login" ] || [ $PNAME == "sshd" ] ; then
exec tmux
fi
This script looks for the parent process of the bash shell. If bash was started from logging in or from ssh, it will execute tmux. If you want this to work with a GUI terminal, you can add that in there as well. For example, if you want to start tmux automatically when you start Ubuntu's standard gnome-terminal
, you would use this:
PNAME="$(ps -o comm= $PPID)";
if [ $PNAME == "login" ] || [ $PNAME == "sshd" ] || [ $PNAME == "gnome-terminal" ] ; then
exec tmux
fi
I've tested the above on Live Ubuntu Desktop and I was able to log in afterwards. This should not break the GUI login unless it invokes the login command to log in. I am not aware of a linux GUI that does this.
Within xfce4 (I'm running Fedora 24 XFCE spin, it's great), I've found the simplest solution is to edit panel shortcuts to so they run:
xfce4-terminal -e tmux
This same command can be used to replace the Keyboard Application Shortcut.
I had previously inserted an if statement into my .bashrc, but it caused login to fail (loop back to the login box whenever a correct password was entered).
The command for Thunar's Open Terminal Here command differs slightly. To change that goto:
Thunar > Edit > Configure Custom Actions... > Open Terminal Here > Edit button, and replace:
exo-open --working-directory %f --launch TerminalEmulator
with: xfce4-terminal --working-directory %f -e tmux
A one-liner that also makes sure the terminal type is set correctly for 256 colors:
[ -z "$TMUX" ] && export TERM=xterm-256color && exec tmux
How about adding
# If not running interactively, do not do anything
[[ $- != *i* ]] && return
[[ -z "$TMUX" ]] && exec tmux
to your .bashrc. It also works for zsh.
Taken from https://wiki.archlinux.org/index.php/Tmux#Start_tmux_with_default_session_layout
'development' 카테고리의 다른 글
서비스 애플리케이션 및 Google Analytics API V3 : 서버 간 OAuth2 인증? (0) | 2020.12.04 |
---|---|
폴더 또는 JAR에서 런타임에 클래스를로드하는 방법은 무엇입니까? (0) | 2020.12.04 |
잘라 내기 명령을 사용하여 여러 열 제거 (0) | 2020.12.04 |
Git Bash Shell이 심볼릭 링크를 생성하지 못함 (0) | 2020.12.04 |
Android Studio에서 링크 된 소스 폴더를 추가하는 방법은 무엇입니까? (0) | 2020.12.04 |