Skip to content

Commit

Permalink
support custom drag file upload command
Browse files Browse the repository at this point in the history
  • Loading branch information
lonnywong committed Jul 14, 2024
1 parent 34e6fc6 commit 2e836c6
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 25 deletions.
20 changes: 20 additions & 0 deletions README.cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -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。
Expand All @@ -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` 环境变量中,也可以如下安装:

```
Expand Down Expand Up @@ -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"}
Expand Down
20 changes: 20 additions & 0 deletions README.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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:

```
Expand Down Expand Up @@ -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"}
Expand Down
54 changes: 30 additions & 24 deletions tssh/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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)
}
Expand Down
7 changes: 6 additions & 1 deletion tssh/trzsz.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 2e836c6

Please sign in to comment.