ravelll の日記

よしなに

tmux でカレントディレクトリをデフォルトとしてウインドウやペインを開く

日頃頻繁に tmux で画面分割していて、rails server したくなったら新しく window 開いて実行、みたいなことをよくやる。
で、それをバババッとやるとホームディレクトリで rails s して rails の Help が表示されてる新 window が生まれる。
これが地味に心的ダメージあるので、調べて直した。

まとめ

new-window -c #{pane_current_path} で実現できる。

調査ログ

で、マニュアルを調べてみると new-window は -c オプションを使うことで開くディレクトリを指定できるようだった。 以下マニュアルから引用。

-c specifies the working directory in which the new window is created.

なるほど、これでやれそう。
けど、カレントディレクトリってどう指定するんだろう…?

更に調べてみると、pane_current_path なる変数を渡せるらしい。

New Tmux Panes go to the same directory as the current pane; new tmux windows go to home directory?

マニュアルから pane_current_path を検索してみると、それに加えて変数が色々と定義されてた。

     The following variables are available, where appropriate:

     Variable name          Alias    Replaced with
     alternate_on                    If pane is in alternate screen
     ...

     ...
     pane_current_path               Current path if available
     ...

ペイン上のマウスカーソルの位置まで変数に用意されてるし、何か面白いことできそうな感じ。幅跳びとか。

--

reference