@@ -307,35 +307,36 @@ class CoderCLIManager(
307307 Host ${getHostPrefix()} -bg--*
308308 ProxyCommand ${backgroundProxyArgs.joinToString(" " )} --ssh-host-prefix ${getHostPrefix()} -bg-- %h
309309 """ .trimIndent()
310- .plus(" \n " + sshOpts.prependIndent(" " ))
311- .plus(extraConfig),
310+ .plus(" \n " + sshOpts.prependIndent(" " ))
311+ .plus(extraConfig),
312312 ).replace(" \n " , System .lineSeparator()) +
313313 System .lineSeparator() + endBlock
314-
315- } else {
316- workspaceNames.joinToString(
317- System .lineSeparator(),
318- startBlock + System .lineSeparator(),
319- System .lineSeparator() + endBlock,
320- transform = {
321- """
314+ } else if (workspaceNames.isEmpty()) {
315+ " "
316+ } else {
317+ workspaceNames.joinToString(
318+ System .lineSeparator(),
319+ startBlock + System .lineSeparator(),
320+ System .lineSeparator() + endBlock,
321+ transform = {
322+ """
322323 Host ${getHostName(it.first, currentUser, it.second)}
323324 ProxyCommand ${proxyArgs.joinToString(" " )} ${getWorkspaceParts(it.first, it.second)}
324- """ .trimIndent()
325- .plus(" \n " + sshOpts.prependIndent(" " ))
326- .plus(extraConfig)
327- .plus(" \n " )
328- .plus(
329- """
325+ """ .trimIndent()
326+ .plus(" \n " + sshOpts.prependIndent(" " ))
327+ .plus(extraConfig)
328+ .plus(" \n " )
329+ .plus(
330+ """
330331 Host ${getBackgroundHostName(it.first, currentUser, it.second)}
331332 ProxyCommand ${backgroundProxyArgs.joinToString(" " )} ${getWorkspaceParts(it.first, it.second)}
332- """ .trimIndent()
333- .plus(" \n " + sshOpts.prependIndent(" " ))
334- .plus(extraConfig),
335- ).replace(" \n " , System .lineSeparator())
336- },
337- )
338- }
333+ """ .trimIndent()
334+ .plus(" \n " + sshOpts.prependIndent(" " ))
335+ .plus(extraConfig),
336+ ).replace(" \n " , System .lineSeparator())
337+ },
338+ )
339+ }
339340
340341 if (contents == null ) {
341342 logger.info(" No existing SSH config to modify" )
@@ -478,15 +479,13 @@ class CoderCLIManager(
478479 *
479480 * Throws if the command execution fails.
480481 */
481- fun startWorkspace (workspaceOwner : String , workspaceName : String ): String {
482- return exec(
483- " --global-config" ,
484- coderConfigPath.toString(),
485- " start" ,
486- " --yes" ,
487- workspaceOwner+ " /" + workspaceName,
488- )
489- }
482+ fun startWorkspace (workspaceOwner : String , workspaceName : String ): String = exec(
483+ " --global-config" ,
484+ coderConfigPath.toString(),
485+ " start" ,
486+ " --yes" ,
487+ workspaceOwner + " /" + workspaceName,
488+ )
490489
491490 private fun exec (vararg args : String ): String {
492491 val stdout =
@@ -519,8 +518,7 @@ class CoderCLIManager(
519518 /*
520519 * This function returns the ssh-host-prefix used for Host entries.
521520 */
522- fun getHostPrefix (): String =
523- " coder-jetbrains-${deploymentURL.safeHost()} "
521+ fun getHostPrefix (): String = " coder-jetbrains-${deploymentURL.safeHost()} "
524522
525523 /* *
526524 * This function returns the ssh host name generated for connecting to the workspace.
@@ -529,29 +527,27 @@ class CoderCLIManager(
529527 workspace : Workspace ,
530528 currentUser : User ,
531529 agent : WorkspaceAgent ,
532- ): String =
533- if (features.wildcardSSH) {
534- " ${getHostPrefix()} --${workspace.ownerName} --${workspace.name} .${agent.name} "
530+ ): String = if (features.wildcardSSH) {
531+ " ${getHostPrefix()} --${workspace.ownerName} --${workspace.name} .${agent.name} "
532+ } else {
533+ // For a user's own workspace, we use the old syntax without a username for backwards compatibility,
534+ // since the user might have recent connections that still use the old syntax.
535+ if (currentUser.username == workspace.ownerName) {
536+ " coder-jetbrains--${workspace.name} .${agent.name} --${deploymentURL.safeHost()} "
535537 } else {
536- // For a user's own workspace, we use the old syntax without a username for backwards compatibility,
537- // since the user might have recent connections that still use the old syntax.
538- if (currentUser.username == workspace.ownerName) {
539- " coder-jetbrains--${workspace.name} .${agent.name} --${deploymentURL.safeHost()} "
540- } else {
541- " coder-jetbrains--${workspace.ownerName} --${workspace.name} .${agent.name} --${deploymentURL.safeHost()} "
538+ " coder-jetbrains--${workspace.ownerName} --${workspace.name} .${agent.name} --${deploymentURL.safeHost()} "
542539 }
543540 }
544541
545542 fun getBackgroundHostName (
546543 workspace : Workspace ,
547544 currentUser : User ,
548545 agent : WorkspaceAgent ,
549- ): String =
550- if (features.wildcardSSH) {
551- " ${getHostPrefix()} -bg--${workspace.ownerName} --${workspace.name} .${agent.name} "
552- } else {
553- getHostName(workspace, currentUser, agent) + " --bg"
554- }
546+ ): String = if (features.wildcardSSH) {
547+ " ${getHostPrefix()} -bg--${workspace.ownerName} --${workspace.name} .${agent.name} "
548+ } else {
549+ getHostName(workspace, currentUser, agent) + " --bg"
550+ }
555551
556552 companion object {
557553 val logger = Logger .getInstance(CoderCLIManager ::class .java.simpleName)
0 commit comments