OSに応じたtmux構成


41

私のOSがMacの場合にのみ実行したいtmux.confの行がいくつかあります。ただし、tmux.confを複数の異なるOSで使用したいと思います。tmuxが現在実行されているOSを条件とするコマンドを作成するにはどうすればよいですか?


回答:


51

次のif-shellコマンドを使用します。

if-shell "uname | grep -q Darwin" "tmux-cmd1; tmux-cmd2;" "tmux-cmd3; tmux-cmd4"

OS固有のコマンドを別のファイルに入れて、「source-file」コマンドで実行することもできます。

if-shell "uname | grep -q Darwin" "source-file .tmux-macosx" "source-file .tmux-linux"

8
tmuxのコマンドは、現在(のように非同期でtmuxは 1.7)。シェルコマンドはバックグラウンドで効果的に実行され、実行するtmuxコマンドは、or コマンド自体の後に来るコマンドの後にのみ実行さます(tmuxはシングルスレッドです)。効果的に、あなたが使用している場合かで、最初のセッション(および任意のセッション、窓、またはペインは、明示的にして作成して作成)いずれかが欠けているだろうtmuxの設定を通して配置されたかのコマンド。if-shellrun-shell if-shellrun-shellif-shellrun-shell~/.tmux.conf~/tmux.confif-shellrun-shell
クリスジョンセン

1
@ChrisJohnsenはif-shell、tmux 1.8で期待どおりに動作します。私はSSHのためのセットセットのタイトル文字列にそれを使用しています:github.com/blueyed/dotfiles/commit/...
blueyed

2
これは受け入れられるべきです。それが適切な方法です。
CHEV

11

Jimeh https://github.com/jimeh/dotfiles/commit/3838db8に答えがあります。また、クリス・ジョンセンは、GitHubの問題に関する人々を支援してくれた多くの功績があります:https : //Github.com/ChrisJohnsen/tmux-MacOSX-pasteboard/issues/8#issuecomment-4134987

基本的に、safe-reattach-to-user-namespace実際のreattach ...コマンドの存在をチェックするというシェルスクリプトを設定します。

#! /usr/bin/env bash

# If reattach-to-user-namespace is not available, just run the command.
if [ -n "$(command -v reattach-to-user-namespace)" ]; then
  reattach-to-user-namespace $@
else
  exec "$@"
fi
弊社のサイトを使用することにより、あなたは弊社のクッキーポリシーおよびプライバシーポリシーを読み、理解したものとみなされます。
Licensed under cc by-sa 3.0 with attribution required.