Skip to content

feat(app): run an optional command after SSH login - #292

Open
Irzos wants to merge 2 commits into
TooonyChen:mainfrom
Irzos:feature/ssh-login-command
Open

Irzos wants to merge 2 commits into
TooonyChen:mainfrom
Irzos:feature/ssh-login-command

Conversation

@Irzos

@Irzos Irzos commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Add a per-host Run command after login field under SSH connection → Advanced. Leave it blank to disable it.
  • Run the command once in the first interactive terminal when opening a session or manually reconnecting. Additional split panes start without running it again.
  • Commands such as cd /srv/app && conda activate myenv can change the working directory and activate an environment for the shell you continue using.

Closes #281

Testing

  • Verified that the connection editor saves, reloads, and clears the command. Checked the English and Simplified Chinese layouts.
  • Added regression coverage for initial connection, manual reconnect, and split panes. Also verified working-directory and environment changes in an interactive zsh session over a local OpenSSH server.
  • go vet ./... and go tool mygo vet passed.
  • On macOS, the race suite passed with TestCloseAllMixed skipped. With test(app): click the rendered blank area in Close All tests #291 applied alongside this change, TestCloseAllMixed passed three consecutive runs with race detection.

Copy link
Copy Markdown
Owner

Thanks for picking up #281 so quickly. The feature works as described: with real bash, fish and tmux the shell ends up in the directory with the environment active, the command is not run again in split panes, it goes through the host's encoding, and it stays out of the app's command history. Nothing is broken in the code. I would like a different shape for it before it merges, though.

Where the command lives. A free-text command in the connection editor makes a second place where commands are written, next to the Commands panel. I would rather keep commands in one place: the connection editor picks one of the saved quick commands to run after login, instead of holding its own text.

  • In SSH connection → Advanced, replace the text input with a select: "None" (the default) and the saved quick commands, shown by name and grouped as in the Commands panel if that is cheap.
  • The host stores the quick command's ID, not its text. What runs at login is that command as it is at that moment, so editing it in the Commands panel changes what every host using it runs. A multi-line command sends all its lines, with the same Enter behavior the Commands panel uses when sending it.
  • When the referenced command no longer exists (deleted, or a host synced to a machine that does not have the command: quick commands are not synced yet, see fix(cloudsync): synchronize saved quick commands #235), nothing runs, and the select shows that the saved choice is missing instead of silently showing "None", so that saving the editor does not drop the reference by accident.
  • When to run stays as you have it: first terminal of a new session and of a manual reconnect, not in later split panes.
  • With no quick commands saved, the select has only "None" and a muted hint that commands are added in the Commands panel.

Layout. As a label, "Run command after login" is the longest on the page, and the whole label column grows with it (about 110 to 285 px in English): Method, User and Password shift right, their inputs narrow, and two hints wrap. Please keep the label within the width the page already has ("Login command" / "登录命令" would do), or put this row's label above the control. The window should not need to grow from 600 to 680 for one row.

The file panel should follow. After login the shell is in /srv/app but the Files panel stays in the home folder, although "follow the terminal's directory" is on; a later cd typed by hand does move it. #281 asks for exactly "cd to a folder after connecting", so the panel should end up there too. Send does not wake the directory follower, and SFTP opens Getwd() afterwards; both ends probably need a touch.

Two things for the docs, no code needed: the command is typed into whatever the login lands in, so it is meant for hosts that open a shell (a bastion menu or a password-expiry prompt would receive it as input); and since it rides on a quick command it is stored in plain text, so it is not the place for a token.

Smaller: the Chinese hint starts with "可选。" and the English one does not.


Generated by Claude Code

Irzos commented Dec 2, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the review. I’ve updated the login command to use a saved quick command from the Commands panel.

  • The SSH connection editor defaults to None and stores the selected command’s ID. If the command is missing locally, the editor shows Missing command, preserves the reference, and skips sending anything.
  • On a new connection or manual reconnect, the first terminal receives the command’s current contents once. Multiline commands use the same Enter behavior as the Commands panel.
  • With directory following enabled, the Files panel follows the first terminal’s directory when that terminal has focus. This also works when SFTP finishes opening after the shell has already changed directories.
  • The editor keeps its original size. I also updated the English and Chinese docs to explain the shell requirement and plain-text storage.

go test -race ./..., go vet ./..., go tool mygo vet, and go build ./... all passed. I also verified with local OpenSSH that the Files panel follows the login command on the initial connection and picks up an edited command on manual reconnect.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

新增连接后自动cd到指定目录的功能

2 participants