feat: add pre_connect hook and optional shortcut alias display
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:
Sebastian UnterschützandClaude Opus 5.5 committed 2026-11-17 12:00:27 +01:00
1 parent 20d7a40543
commit 796925b1a2
15 files changed
+507 -23

No files matched your search

+22 -3
View File
@@ -64,6 +64,7 @@ type searchResultMsg struct {
type hostItem struct {
label string // display only; name remains the canonical target
alias string // shortcut alias shown next to the name (shortcuts.show)
name string
id int
ip string
@@ -97,7 +98,11 @@ func (d compactDelegate) Render(w io.Writer, m list.Model, index int, item list.
if d.marked[h.key()] {
mark = "● "
}
line := fmt.Sprintf(" %s%s %s", mark, h.Title(), lipgloss.NewStyle().Foreground(lipgloss.Color("240")).Render(h.ip))
title := h.Title()
if h.alias != "" {
title += " " + lipgloss.NewStyle().Foreground(lipgloss.Color("109")).Render("→ "+h.alias)
}
line := fmt.Sprintf(" %s%s %s", mark, title, lipgloss.NewStyle().Foreground(lipgloss.Color("240")).Render(h.ip))
if index == m.Index() {
line = lipgloss.NewStyle().Bold(true).Foreground(lipgloss.Color("86")).Render("> " + strings.TrimPrefix(line, " "))
}
@@ -188,7 +193,8 @@ type Model struct {
forwardMode bool // Ctrl+T on the selected item
marked map[string]bool // hostItem.key() of hosts marked with space
hostLabel func(string) string
markOrder []string // targets in the order they were marked
aliasFor func(string) string // shortcut alias per target, "" for none
markOrder []string // targets in the order they were marked
}
func New(client *netbox.Client, c *cache.Cache, defaultUser string, defaultPorts ...int) *Model {
@@ -705,7 +711,14 @@ func (m *Model) updateListItems(entries []netbox.HostEntry) {
if label != e.Target() && (counts[strings.ToLower(label)] > 1 || canonical[strings.ToLower(label)]) {
label = e.Target()
}
items[i] = hostItem{label: label, id: e.ID, name: e.Target(), ip: ip, kind: e.Kind, tags: e.Tags}
alias := ""
if m.aliasFor != nil {
alias = m.aliasFor(e.Target())
if strings.EqualFold(alias, label) {
alias = ""
}
}
items[i] = hostItem{label: label, alias: alias, id: e.ID, name: e.Target(), ip: ip, kind: e.Kind, tags: e.Tags}
}
m.list.SetItems(items)
m.resizeList()
@@ -847,3 +860,9 @@ func parseForwards(input string, available []string) ([]string, error) {
func (m *Model) SetHostLabel(format func(string) string) {
m.hostLabel = format
}
// SetAliases shows the shortcut alias returned for each target next to its
// name; return "" for hosts without one. Configure it before the program starts.
func (m *Model) SetAliases(aliasFor func(target string) string) {
m.aliasFor = aliasFor
}