0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

今いる仮想端末がtmuxの中にいるか判定するワンライナー

Last updated at Posted at 2024-12-18

今いる仮想端末がtmuxの中にいるか判定するワンライナー

[[ $(tty) == $(tmux list-panes -F '#{pane_tty}') ]] && echo true || echo false

概要

  • tmux display-message -p '#S' でセッション名を表示できる。
  • ただ、tmuxの外にいても、別の仮想端末でtmuxが起動していたらセッション名が表示できてしまう。
  • そのため、今いる仮想端末がtmuxの中にいるか判定する目的には利用できなかった。
  • そこで、ttytmux list-panes -F '#{pane_tty}'の出力の一致を判定する。

解説

  • tty で現在の端末デバイス名を表示する
  • tmux list-panes -F '#{pane_tty}' で今のペインの端末デバイス名を表示する
  • 一致すれば true
  • 不一致なら false

$(tty)

  • ttyコマンド
  • 現在の端末デバイスを表示する
$ tty
/dev/ttys001

$(tmux list-panes -F '#{pane_tty}')

$ tmux list-panes -F '#{pane_tty}'
/dev/ttys004
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?