bash - tmux 从 tmux 配置中的 shell 获取变量值
问题描述
有什么方法可以通过 shell 获取变量到 tmux config 的值。
我写了一些脚本,但它不能设置为像 bash 脚本这样的变量。
enName=$(ip addr show | awk '/inet.*brd/{print $NF}' | grep -o -P '^e.*')
wlName=$(ip addr show | awk '/inet.*brd/{print $NF}' | grep -o -P '^w.*')
[[ ! -z $wlName ]] && interface=$wlName || interface=$enName
ip=$(ifconfig $interface | grep 'inet ' | awk '{print $2}')
net_device_ip="$interface $ip"
- 编辑 -
实际上我想要的是在 tmux 配置文件中维护变量 net_device_ip 。如果可能,bash 脚本在其配置中以 tmux 方式运行。
我想设置的就像:
set -g status-left " #[fg=colour160]#S #{net_device_ip}"
如何通过使用 tmux 命令 run-shell & set-environment 设置变量和运行 shell
谢谢
(tmux 版本:3.0a)
解决方案
你几乎拥有它。您只需要 a$
而不是 a#
对您的变量评估。
我在我的.tmux.conf
.
我有点不清楚你是否试图将你的脚本和你的 tmux conf 文件作为两个不同的部分来维护,但你需要从你的文件中运行脚本或将脚本写入你的.tmux.conf
文件,以便net_device_ip
在范围内定义.
因此,一个完整的解决方案是将其添加到.tmux.conf
文件的末尾:
enName=$(ip addr show | awk '/inet.*brd/{print $NF}' | grep -o -P '^e.*')
wlName=$(ip addr show | awk '/inet.*brd/{print $NF}' | grep -o -P '^w.*')
[[ ! -z $wlName ]] && interface=$wlName || interface=$enName
ip=$(ifconfig $interface | grep 'inet ' | awk '{print $2}')
net_device_ip="$interface $ip"
set -g status-left " #[fg=colour160]#S ${net_device_ip}"
推荐阅读
- reporting-services - SSRS - hh:mm:ss tt 显示为“hh:mm:ss tt”而不是实际时间
- java - 如何使用带有 arraylist 对象的 IF 语句并在其上调用 size() 方法。在 Java 中
- python - 正则表达式不包括匹配组中的零宽度断言
- swift - 带有关联值的枚举 + 泛型 + 带有关联类型的协议
- python - selenium 无法在知乎提交答案
- javascript - 在 javascript 变量和 HTML 属性值中使用 BASE64 编码字符串是否安全?
- r - gplots heatmap.2 慢,Rowv=FALSE
- javascript - 固定标题和锚链接:如何减少可点击区域?
- rundeck - 通过 Ansible 管理 Rundeck
- python-3.x - 如何将 SlidesSnippet 工具用于 google slides api python