首页 > 解决方案 > tmux create new pane or window with current activated conda environment

问题描述

When I create a new pane or window using tmux, I'd like to use the same conda environement I was just using.

I.e. I'm now using a conda env named XXXenv, and I use Ctrl+b + % to create a new pane, what I want is the new created pane is activated by the conda env XXXenv.

In fact, I have tried Have tmux windows inherit activated anaconda environment, but it doesn't work for me.

标签: condatmux

解决方案


嘿嘿,有一个名为 CONDA_DEFAULT_ENV 的环境变量。创建一个定义窗格布局的 bash 脚本,并使用此 var 将原始窗格的活动 conda 环境发送到任何新窗格。然后通过一些 tmux 快捷方式调用它。

开发-sesh.sh

#!/bin/sh

current_session=$(tmux display-message -p '#S')
current_conda=$CONDA_DEFAULT_ENV

tmux split-window -v -p 75 -b
tmux select-pane -t 1
tmux split-window -h -p 50
tmux send-keys  -t "$current_session.0" "conda activate $current_conda" 'Enter';
tmux send-keys  -t "$current_session.1" "conda activate $current_conda" 'Enter';
tmux send-keys  -t "$current_session.2" "conda activate $current_conda" 'Enter';
tmux send-keys  -t "$current_session.0" "clear && figlet Welcome" 'Enter';
tmux send-keys  -t "$current_session.1" "clear" 'Enter';
tmux send-keys  -t "$current_session.2" "clear" 'Enter';
tmux rename-window "dev";

tmux.conf

bind -n C-n send-keys 'bash ~/.dotfiles/dev-sesh.sh' Enter

结果在此处输入图像描述


推荐阅读