blog-site

git clone git://git.lin.moe/blog-site.git

 1---
 2title: "SSH 快捷运行 TUI 程序"
 3date: 2022-10-04T11:22:11+08:00
 4---
 5
 6我平时有用 weechat 看 IRC 的习惯,使用方式是:
 71. ssh 到 ( 用 tmux ) 运行着 weechat 的服务器。
 82. 运行 `tmux -L weechat attach` 命令。  
 9
10每次都要这么两步,觉得很麻烦,想试试在 ssh config 添加配置来自动执行。  
11
12于是我的 ssh 配置多了这么一条  
13```
14Host irc 
15	HostName my_weechat_server
16	User lindsay
17	Port 22222
18	
19	# 连接成功后执行的命令,
20	# exec 是为了 weechat 退出后自动断开 ssh ,详细请看 man exec(n)
21	RemoteCommand exec tmux -L weechat attach
22	
23	# weechat 必须要有 TTY/PTY 才能运行
24	RequestTTY yes 
25```
26
27其他 TUI 应用也同样适用,比如运行 neomutt
28```
29Host mail 
30	HostName localhost 
31	RemoteCommand exec neomutt 
32	RequestTTY yes 
33```
34如果不想污染 `~/.ssh/config` 文件,可以将这类配置另外保存一个文件,然后在  ~/.ssh/config 中添加一行 `include <your_ssh_tui_config_path>`