From 2e836c63582060eb7398b8b6696cdc9c30df231e Mon Sep 17 00:00:00 2001 From: Lonny Wong Date: Sun, 14 Jul 2024 21:51:26 +0800 Subject: [PATCH] support custom drag file upload command --- README.cn.md | 20 +++++++++++++++++++ README.en.md | 20 +++++++++++++++++++ tssh/config.go | 54 ++++++++++++++++++++++++++++---------------------- tssh/trzsz.go | 7 ++++++- 4 files changed, 76 insertions(+), 25 deletions(-) diff --git a/README.cn.md b/README.cn.md index 863a0bf..899bc4d 100644 --- a/README.cn.md +++ b/README.cn.md @@ -300,6 +300,14 @@ trzsz-ssh ( tssh ) 设计为 ssh 客户端的直接替代品,提供与 openssh EnableDragFile Yes ``` +- 如果想在拖拽上传时覆盖现有文件,请将 `DragFileUploadCommand` 配置为 `trz -y` : + + ``` + Host xxx + # 如果配置在 ~/.ssh/config 中,可以加上 `#!!` 前缀,以兼容标准 ssh + DragFileUploadCommand trz -y + ``` + - 如果只是想临时启用拖拽上传功能,可以在命令行中使用 `tssh --dragfile` 登录服务器。 - 在 `~/.ssh/config` 或 `ExConfigPath` 配置文件中,配置 `EnableTrzsz` 为 `No` 禁用 trzsz 和 zmodem。 @@ -322,6 +330,15 @@ trzsz-ssh ( tssh ) 设计为 ssh 客户端的直接替代品,提供与 openssh EnableZmodem Yes ``` +- 如果想在拖拽文件时使用 rz 上传,请将 `DragFileUploadCommand` 配置为 `rz` : + + ``` + Host xxx + # 如果配置在 ~/.ssh/config 中,可以加上 `#!!` 前缀,以兼容标准 ssh + EnableDragFile Yes + DragFileUploadCommand rz + ``` + - 除了服务器,本地电脑也要安装 `lrzsz`,Windows 可以从 [lrzsz-win32](https://github.com/trzsz/lrzsz-win32/releases) 下载,解压并加到 `PATH` 环境变量中,也可以如下安装: ``` @@ -588,6 +605,9 @@ trzsz-ssh ( tssh ) 设计为 ssh 客户端的直接替代品,提供与 openssh # tsz 下载时,自动保存的路径,为空时弹出对话框手工选择,默认为空 DefaultDownloadPath = ~/Downloads + # 全局的拖拽文件上传命令,注意 ~/.ssh/config 中配置的优先级更高 + DragFileUploadCommand = trz -y + # tssh 搜索和选择服务器时,配置主题风格和自定义颜色 PromptThemeLayout = simple PromptThemeColors = {"active_host": "magenta|bold", "inactive_host": "magenta"} diff --git a/README.en.md b/README.en.md index bcbcef4..7f3f224 100644 --- a/README.en.md +++ b/README.en.md @@ -300,6 +300,14 @@ trzsz-ssh ( tssh ) is an ssh client designed as a drop-in replacement for the op EnableDragFile Yes ``` +- If you want to overwrite the existing files when dragging files to upload, configure `DragFileUploadCommand` to `trz -y`: + + ``` + Host xxx + # If configured in ~/.ssh/config, add `#!!` prefix to be compatible with openssh. + DragFileUploadCommand trz -y + ``` + - If you want to temporarily enable the drag and drop to upload feature, use `tssh --dragfile` to log in. - In the `~/.ssh/config` or `ExConfigPath` configuration file, configure `EnableTrzsz` to `No` to disable the trzsz and zmodem feature. @@ -322,6 +330,15 @@ trzsz-ssh ( tssh ) is an ssh client designed as a drop-in replacement for the op EnableZmodem Yes ``` +- If you want to use `rz` to upload when dragging files, configure `DragFileUploadCommand` to `rz`: + + ``` + Host xxx + # If configured in ~/.ssh/config, add `#!!` prefix to be compatible with openssh. + EnableDragFile Yes + DragFileUploadCommand rz + ``` + - Not only the server, but also the local computer needs to install `lrzsz`. For Windows, you can download from [lrzsz-win32](https://github.com/trzsz/lrzsz-win32/releases), unzip and add to `PATH` environment, or install it as follows: ``` @@ -588,6 +605,9 @@ trzsz-ssh ( tssh ) is an ssh client designed as a drop-in replacement for the op # The automatically save path for tsz downloading, the default is empty which poping up a folder dialog. DefaultDownloadPath = ~/Downloads + # The global drag file upload command, note that the priority configured in ~/.ssh/config is higher. + DragFileUploadCommand = trz -y + # When searching and selecting servers with tssh, the theme and colors. PromptThemeLayout = simple PromptThemeColors = {"active_host": "magenta|bold", "inactive_host": "magenta"} diff --git a/tssh/config.go b/tssh/config.go index d3a293a..f896fcd 100644 --- a/tssh/config.go +++ b/tssh/config.go @@ -68,30 +68,31 @@ type sshHost struct { } type tsshConfig struct { - language string - configPath string - sysConfigPath string - exConfigPath string - defaultUploadPath string - defaultDownloadPath string - promptThemeLayout string - promptThemeColors map[string]string - promptPageSize uint8 - promptDefaultMode string - promptDetailItems string - promptCursorIcon string - promptSelectedIcon string - setTerminalTitle string - loadConfig sync.Once - loadExConfig sync.Once - loadHosts sync.Once - config *ssh_config.Config - sysConfig *ssh_config.Config - exConfig *ssh_config.Config - loadDefaultColors sync.Once - defaultThemeColors map[string]string - allHosts []*sshHost - wildcardPatterns []*ssh_config.Pattern + language string + configPath string + sysConfigPath string + exConfigPath string + defaultUploadPath string + defaultDownloadPath string + dragFileUploadCommand string + promptThemeLayout string + promptThemeColors map[string]string + promptPageSize uint8 + promptDefaultMode string + promptDetailItems string + promptCursorIcon string + promptSelectedIcon string + setTerminalTitle string + loadConfig sync.Once + loadExConfig sync.Once + loadHosts sync.Once + config *ssh_config.Config + sysConfig *ssh_config.Config + exConfig *ssh_config.Config + loadDefaultColors sync.Once + defaultThemeColors map[string]string + allHosts []*sshHost + wildcardPatterns []*ssh_config.Pattern } var userConfig *tsshConfig @@ -138,6 +139,8 @@ func parseTsshConfig() { userConfig.defaultUploadPath = resolveHomeDir(value) case name == "defaultdownloadpath" && userConfig.defaultDownloadPath == "": userConfig.defaultDownloadPath = resolveHomeDir(value) + case name == "dragfileuploadcommand" && userConfig.dragFileUploadCommand == "": + userConfig.dragFileUploadCommand = value case name == "promptthemelayout" && userConfig.promptThemeLayout == "": userConfig.promptThemeLayout = value case name == "promptthemecolors" && len(userConfig.promptThemeColors) == 0: @@ -192,6 +195,9 @@ func showTsshConfig() { if userConfig.defaultDownloadPath != "" { debug("DefaultDownloadPath = %s", userConfig.defaultDownloadPath) } + if userConfig.dragFileUploadCommand != "" { + debug("DragFileUploadCommand = %s", userConfig.dragFileUploadCommand) + } if userConfig.promptThemeLayout != "" { debug("PromptThemeLayout = %s", userConfig.promptThemeLayout) } diff --git a/tssh/trzsz.go b/tssh/trzsz.go index 752da88..59ccd9d 100644 --- a/tssh/trzsz.go +++ b/tssh/trzsz.go @@ -169,9 +169,14 @@ func enableTrzsz(args *sshArgs, ss *sshClientSession) error { _ = ss.session.WindowChange(height, width) }) - // setup default paths + // setup trzsz config trzszFilter.SetDefaultUploadPath(userConfig.defaultUploadPath) trzszFilter.SetDefaultDownloadPath(userConfig.defaultDownloadPath) + dragFileUploadCommand := getExOptionConfig(args, "DragFileUploadCommand") + if dragFileUploadCommand == "" { + dragFileUploadCommand = userConfig.dragFileUploadCommand + } + trzszFilter.SetDragFileUploadCommand(dragFileUploadCommand) // setup tunnel connect trzszFilter.SetTunnelConnector(func(port int) net.Conn {