Skip to content

Commit

Permalink
feat: support setting sftp path (#267)
Browse files Browse the repository at this point in the history
  • Loading branch information
hstyi authored Feb 18, 2025
1 parent b332bad commit 3cd9f92
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
6 changes: 6 additions & 0 deletions src/main/kotlin/app/termora/Database.kt
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,12 @@ class Database private constructor(private val env: Environment) : Disposable {
*/
var editCommand by StringPropertyDelegate(StringUtils.EMPTY)


/**
* sftp command
*/
var sftpCommand by StringPropertyDelegate(StringUtils.EMPTY)

}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/app/termora/SFTPPtyTerminalTab.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class SFTPPtyTerminalTab(windowScope: WindowScope, host: Host) : PtyHostTerminal
private var sshClient: SshClient? = null
private var sshSession: ClientSession? = null
private var lastPasswordReporterDataListener: PasswordReporterDataListener? = null
private val sftpCommand get() = Database.getDatabase().sftp.sftpCommand

companion object {
val canSupports by lazy {
Expand All @@ -42,9 +43,8 @@ class SFTPPtyTerminalTab(windowScope: WindowScope, host: Host) : PtyHostTerminal

override suspend fun openPtyConnector(): PtyConnector {


val useJumpHosts = host.options.jumpHosts.isNotEmpty() || host.proxy.type != ProxyType.No
val commands = mutableListOf("sftp")
val commands = mutableListOf(StringUtils.defaultIfBlank(sftpCommand, "sftp"))
var host = this.host

// 如果配置了跳板机或者代理,那么通过 SSH 的端口转发到本地
Expand Down
17 changes: 17 additions & 0 deletions src/main/kotlin/app/termora/SettingsOptionsPane.kt
Original file line number Diff line number Diff line change
Expand Up @@ -1297,6 +1297,7 @@ class SettingsOptionsPane : OptionsPane() {
private inner class SFTPOption : JPanel(BorderLayout()), Option {

val editCommandField = OutlineTextField(255)
val sftpCommandField = OutlineTextField(255)
private val sftp get() = database.sftp

init {
Expand All @@ -1311,6 +1312,13 @@ class SettingsOptionsPane : OptionsPane() {
sftp.editCommand = editCommandField.text
}
})


sftpCommandField.document.addDocumentListener(object : DocumentAdaptor() {
override fun changedUpdate(e: DocumentEvent) {
sftp.sftpCommand = sftpCommandField.text
}
})
}


Expand All @@ -1321,7 +1329,14 @@ class SettingsOptionsPane : OptionsPane() {
editCommandField.placeholderText = "open -a TextEdit {0}"
}

if (SystemInfo.isWindows) {
sftpCommandField.placeholderText = "sftp.exe"
} else {
sftpCommandField.placeholderText = "sftp"
}

editCommandField.text = sftp.editCommand
sftpCommandField.text = sftp.sftpCommand
}

override fun getIcon(isSelected: Boolean): Icon {
Expand All @@ -1345,6 +1360,8 @@ class SettingsOptionsPane : OptionsPane() {
val builder = FormBuilder.create().layout(layout).debug(false)
builder.add("${I18n.getString("termora.settings.sftp.edit-command")}:").xy(1, 1)
builder.add(editCommandField).xy(3, 1)
builder.add("${I18n.getString("termora.tabbed.contextmenu.sftp-command")}:").xy(1, 3)
builder.add(sftpCommandField).xy(3, 3)

return builder.build()

Expand Down

0 comments on commit 3cd9f92

Please sign in to comment.