以下は、独自のTmuxセッションを開始できるTmuxHome.shスクリプトです。
# tmux Start Script Need To Work!!
if which tmux >/dev/null 2>&1; then
#if not inside a tmux session, and if no session is started, start a new session
test -z "$TMUX" && (tmux attach || tmux new-session)
fi
さて、私はデフォルトの.tmux.confを使用するTmuxHome.shとtmux-work.confを使用するTmuxWork.shの例を提供したいと思います。どちらもアクティブで、別々のセッションで実行されます。何の問題もなくこれを行う方法は?たぶん次のTmuxTty.shやTmuxDev.shなど...
Arch Wikiサイトは素晴らしいです: https://wiki.archlinux.org/index.php/Tmux 今は昔とは異なります。
ベストアンサー1
tmux
両方の呼び出しに適切なパラメータを簡単に渡すことができます。
tmux
パラメータを使用してカスタム設定ファイルを独自-f
に渡しますtmux
。- の場合は、
new-session
パラメータを使用してセッション名を渡す必要があります-s
。 - の場合(「t」は「target」を表します)を介してセッション名を渡すことができます
attach
。-t
一緒に入れてください:
# TmuxWork.sh
if which tmux >/dev/null 2>&1; then
#if not inside a tmux session, and if no session is started, start a new session
test -z "$TMUX" && (
tmux -f ~/.tmux-work.conf attach -t work ||
tmux -f ~/.tmux-work.conf new-session -s work
)
fi
new-session
(ほとんどの場合、attach
セッション内で実行されるような他のコマンドには重要ではないため、設定ファイルを渡すだけです。)
実際にこのスクリプトを拡張できます。変化「home」セッションまたは別のセッション内で実行する場合は、switch-client
「work」セッションに次のコマンドを使用します。
if test -n "$TMUX" ; then
tmux switch-client -t work
else
tmux attach -t work ||
tmux -f ~/.tmux-work.conf new-session -s work
fi
一部のスクリプトでは、セッション名(この場合は「アクション」)とカスタムプロファイル名をシェル変数に保存し、このコードスニペットを再利用して、管理するセッション数だけカスタムスクリプトを提供できます。 。