feat: add pre_connect hook and optional shortcut alias display
Test / test (pull_request) Successful in 4m27s
Test / test (pull_request) Successful in 4m27s
- ssh.pre_connect: local shell command run before every connection, layered like proxy_jump (global, instance/static host, rules; "none" disables). Host details are passed as NETSSH_* env vars, a non-zero exit aborts the connection, --dry-run only prints it. - shortcuts.show: show shortcut aliases in the TUI host list, an ALIAS column in `cache list` / `hosts list` (also via --aliases) and in Tab completion. - Both editable in `netssh configure`; README and CHANGELOG updated. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017GpWAuVpPncumMViLLc8N4
This commit is contained in:
1 parent
20d7a40543
commit
796925b1a2
15 files changed
+507
-23
No files matched your search
@@ -24,6 +24,21 @@ type SSHOptions struct {
|
||||
Options map[string]string `mapstructure:"options"`
|
||||
// Forwards are named port forwards, selected with --forward or netssh tunnel.
|
||||
Forwards map[string]Forward `mapstructure:"forwards"`
|
||||
// PreConnect is a shell command run locally before connecting; a non-zero
|
||||
// exit aborts the connection. "none" disables a hook set by a broader layer.
|
||||
PreConnect string `mapstructure:"pre_connect"`
|
||||
}
|
||||
|
||||
// PreConnectNone disables an inherited pre_connect hook.
|
||||
const PreConnectNone = "none"
|
||||
|
||||
// PreConnectCommand returns the hook to run, or "" when none is configured.
|
||||
func (o SSHOptions) PreConnectCommand() string {
|
||||
command := strings.TrimSpace(o.PreConnect)
|
||||
if strings.EqualFold(command, PreConnectNone) {
|
||||
return ""
|
||||
}
|
||||
return command
|
||||
}
|
||||
|
||||
// Forward is one port forward; exactly one of the fields is set.
|
||||
@@ -155,6 +170,9 @@ func (o SSHOptions) Validate(scope string) error {
|
||||
return fmt.Errorf("%s.options: invalid option %q", scope, key)
|
||||
}
|
||||
}
|
||||
if strings.ContainsRune(o.PreConnect, 0) {
|
||||
return fmt.Errorf("%s.pre_connect must not contain NUL bytes", scope)
|
||||
}
|
||||
for name, forward := range o.Forwards {
|
||||
if !instanceName.MatchString(name) {
|
||||
return fmt.Errorf("%s.forwards: name %q must contain only letters, digits, underscores, or hyphens", scope, name)
|
||||
@@ -221,6 +239,9 @@ func (o SSHOptions) merge(override SSHOptions) SSHOptions {
|
||||
if override.AddressFamily != "" {
|
||||
out.AddressFamily = override.AddressFamily
|
||||
}
|
||||
if strings.TrimSpace(override.PreConnect) != "" {
|
||||
out.PreConnect = override.PreConnect
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user