Skip to content

docs: document --template variables and add SSHFS and RDP examples - #160

Open
Arnaudmyges wants to merge 3 commits into
quantumsheep:masterfrom
Arnaudmyges:docs/command-templates
Open

Arnaudmyges wants to merge 3 commits into
quantumsheep:masterfrom
Arnaudmyges:docs/command-templates

Conversation

@Arnaudmyges

Copy link
Copy Markdown

--template is how sshs runs something other than ssh (you pointed to it for SSHFS in #84), but the README does not mention it, so its variables can only be found in the source.

This adds a "Custom commands with templates" section:

  • the variables a template can use (name, aliases, destination, user, port, proxy_command), taken from ssh::Host;
  • the fact that the command is split with shlex and run without a shell, so pipes, && and $VAR do not work (with a sh -c workaround);
  • --on-session-start-template / --on-session-end-template;
  • two examples: the SSHFS one from Add SFTP support #84, and opening RDP sessions with FreeRDP from a separate hosts file.

I use the RDP one to get the same picker for my Windows hosts; it was tested with sshs 4.8.0. The SSHFS command is the one from #84.

Docs only, no code change.

🤖 Generated with Claude Code

The --template option is the way to run something other than ssh (see
quantumsheep#84), but the README did not mention it. Add a section listing the
variables a template can use, explaining that the command runs without
a shell, and giving two examples: SSHFS and RDP through FreeRDP.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Comment thread README.md Outdated

```bash
sshs --config ~/.config/rdp-hosts \
--template 'xfreerdp3 /v:{{{destination}}}{{#if port}}:{{{port}}}{{/if}}{{#if user}} "/u:{{{user}}}"{{/if}} /dynamic-resolution +clipboard'

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is specific to X11 FreeRDP 3, can it also be forward compatible by using xfreerdp without the 3?

Suggested change
--template 'xfreerdp3 /v:{{{destination}}}{{#if port}}:{{{port}}}{{/if}}{{#if user}} "/u:{{{user}}}"{{/if}} /dynamic-resolution +clipboard'
--template 'xfreerdp /v:{{{destination}}}{{#if port}}:{{{port}}}{{/if}}{{#if user}} "/u:{{{user}}}"{{/if}} /dynamic-resolution +clipboard'

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, done in 1bfb015. One catch: Arch Linux and Debian/Ubuntu ship FreeRDP 3 as xfreerdp3 / sdl-freerdp3 (Fedora and Homebrew keep xfreerdp), so I added a short note below the example for those distributions.

Comment thread README.md Outdated
| Variable | Value |
| --------------- | -------------------------------------------------------- |
| `name` | First pattern of the `Host` line |
| `aliases` | Other patterns of the `Host` line, joined with `, ` |

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
| `aliases` | Other patterns of the `Host` line, joined with `, ` |
| `aliases` | Other identical patterns, joined with `, ` |

Aliases are created when all options of the host are exactly the same. It's possible for multiple hosts on the same line to have different configuration.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the explanation, applied in 788054a.

Comment thread README.md Outdated

## Custom commands with templates

By default, selecting a host runs `ssh "{{{name}}}"`. The `--template` option replaces that command with your own [Handlebars](https://handlebarsjs.com/guide/) template, so sshs can launch any tool from the same host list.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
By default, selecting a host runs `ssh "{{{name}}}"`. The `--template` option replaces that command with your own [Handlebars](https://handlebarsjs.com/guide/) template, so sshs can launch any tool from the same host list.
By default, selecting a host runs `ssh "{{{name}}}"`. The `--template` / `-t` option replaces that command with your own [Handlebars](https://handlebarsjs.com/guide/) template, so sshs can launch any tool from the same host list.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Applied in 788054a.

Comment thread README.md Outdated
Mount a host with [SSHFS](https://github.com/libfuse/sshfs):

```bash
sshs --template 'sshfs "{{{name}}}":/path/to/remote /path/to/local'

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This mounts the filesystem, what about using --on-session-end-template the unmount?

Suggested change
sshs --template 'sshfs "{{{name}}}":/path/to/remote /path/to/local'
sshs --template 'sshfs "{{{name}}}":/path/to/remote /path/to/local' --on-session-end-template "fusermount -u /path/to/local"

Note: I'm not sure of the syntax

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea, done in 788054a, with one change: sshfs goes to the background as soon as the filesystem is mounted, so as the main template it returns right away and the end template would unmount immediately. The example now mounts in --on-session-start-template, opens ranger on the mount point as the main command, and unmounts in --on-session-end-template when you quit it (same idea as the ranger workflow in #84). I checked the order with sshs 4.8.0: start, main, then end. I used fusermount3 -u, since sshfs 3 depends on FUSE 3 and Arch only ships fusermount with the separate fuse2 package; there is a note for umount on macOS.

Mount in --on-session-start-template (sshfs goes to the background once
mounted), browse with a file manager, unmount in --on-session-end-template.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.

2 participants