feat: add pre_connect hook and optional shortcut alias display

- 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:
Sebastian UnterschützandClaude Opus 5.5 committed 2026-11-17 12:00:27 +01:00
1 parent 3804c33669
commit 419c682a71
15 files changed
+507 -23

No files matched your search

+29 -3
View File
@@ -348,6 +348,9 @@ func connectHost(cfg *config.Config, client internalssh.Client, flags internalss
}
fatalf("name a forward or a spec such as 8080:localhost:80; forwards for %s: %s", host.Name, available)
}
if err := runPreConnect(opts.PreConnectCommand(), host, client.Name, flags.DryRun); err != nil {
fatalf("%v", err)
}
_, name := netbox.SplitTarget(host.Name)
execClient(client, client.Apply(args, dests, internalssh.Host{Name: name, IP: host.IP}, opts, flags), flags)
}
@@ -387,6 +390,10 @@ func runTUI() {
m := tui.New(nbClient, c, cfg.SSH.DefaultUser, cfg.SSH.DefaultPort)
m.SetHostLabel(cfg.HostLabel)
if cfg.Shortcuts.Show {
aliases := shortcutAliases(c.All(), *cfg)
m.SetAliases(func(target string) string { return aliases[strings.ToLower(target)] })
}
m.SetNotes(notes.New(cfg.NetBox.URL, nbClient))
m.SetForwards(func(name, kind string, tags []string) []string {
return forwardNames(hostOptions(cfg, resolvedHost{Name: name, Kind: kind, Tags: tags}))
@@ -669,7 +676,8 @@ func cacheCmd() *cobra.Command {
}
func cacheListCmd() *cobra.Command {
return &cobra.Command{
var showAliases bool
cmd := &cobra.Command{
Use: "list",
Short: "Show all cached entries",
RunE: func(cmd *cobra.Command, args []string) error {
@@ -685,13 +693,31 @@ func cacheListCmd() *cobra.Command {
sort.Slice(entries, func(i, j int) bool { return entries[i].Name < entries[j].Name })
w := tabwriter.NewWriter(os.Stdout, 0, 0, 2, ' ', 0)
fmt.Fprintln(w, "NAME\tIP\tKIND\tCACHED AT")
if !showAliases && !cfg.Shortcuts.Show {
fmt.Fprintln(w, "NAME\tIP\tKIND\tCACHED AT")
for _, e := range entries {
fmt.Fprintf(w, "%s\t%s\t%s\t%s\n", e.Name, e.IP, e.Kind, e.CachedAt.Format(time.RFC3339))
}
return w.Flush()
}
aliases := shortcutAliases(entries, *cfg)
fmt.Fprintln(w, "NAME\tALIAS\tIP\tKIND\tCACHED AT")
for _, e := range entries {
fmt.Fprintf(w, "%s\t%s\t%s\t%s\n", e.Name, e.IP, e.Kind, e.CachedAt.Format(time.RFC3339))
fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s\n", e.Name, orDash(aliases[strings.ToLower(e.Name)]), e.IP, e.Kind, e.CachedAt.Format(time.RFC3339))
}
return w.Flush()
},
}
cmd.Flags().BoolVar(&showAliases, "aliases", false, "Show each host's shortcut alias (always on with shortcuts.show)")
return cmd
}
// orDash keeps empty table cells visible.
func orDash(s string) string {
if s == "" {
return "-"
}
return s
}
func cacheClearCmd() *cobra.Command {