feat: add hidden tag to hide hosts from TUI and search

Hosts tagged with "hidden" are excluded from the TUI list, shell
completions, and sshm search. Direct connections via sshm <host>
still work regardless of the tag.

A toggle key (H) shows or hides hidden hosts in the TUI, with a
yellow banner indicating the active state. The key is documented
in the help panel (h).

A contextual hint on the Tags field in the add and edit forms
reminds the user that "hidden" hides the host from the list.
This commit is contained in:
2026-02-25 20:27:22 +01:00
parent 838941e3eb
commit 9c639206f7
11 changed files with 90 additions and 11 deletions

View File

@@ -1624,6 +1624,27 @@ func GetAllConfigFiles() ([]string, error) {
return files, nil
}
// FilterVisibleHosts returns only hosts that do not have the "hidden" tag.
func FilterVisibleHosts(hosts []SSHHost) []SSHHost {
var visible []SSHHost
for _, h := range hosts {
if !hostHasTag(h.Tags, "hidden") {
visible = append(visible, h)
}
}
return visible
}
// hostHasTag reports whether the given tag list contains the target tag (case-insensitive).
func hostHasTag(tags []string, target string) bool {
for _, t := range tags {
if strings.EqualFold(t, target) {
return true
}
}
return false
}
// GetAllConfigFilesFromBase returns all SSH config files starting from a specific base config file
func GetAllConfigFilesFromBase(baseConfigPath string) ([]string, error) {
if baseConfigPath == "" {

View File

@@ -438,7 +438,12 @@ func (m *addFormModel) renderGeneralTab() string {
b.WriteString(fieldStyle.Render(field.label))
b.WriteString("\n")
b.WriteString(m.inputs[field.index].View())
b.WriteString("\n\n")
b.WriteString("\n")
if field.index == tagsInput && m.focused == tagsInput {
b.WriteString(m.styles.FormHelp.Render(` tip: use "hidden" to hide this host from the list`))
b.WriteString("\n")
}
b.WriteString("\n")
}
return b.String()

View File

@@ -599,7 +599,12 @@ func (m *editFormModel) renderEditGeneralTab() string {
b.WriteString(fieldStyle.Render(field.label))
b.WriteString("\n")
b.WriteString(m.inputs[field.index].View())
b.WriteString("\n\n")
b.WriteString("\n")
if field.index == 7 && m.focusArea == focusAreaProperties && m.focused == 7 {
b.WriteString(m.styles.FormHelp.Render(` tip: use "hidden" to hide this host from the list`))
b.WriteString("\n")
}
b.WriteString("\n")
}
return b.String()

View File

@@ -81,6 +81,9 @@ func (m *helpModel) View() string {
lipgloss.JoinHorizontal(lipgloss.Left,
m.styles.FocusedLabel.Render("p "),
m.styles.HelpText.Render("ping all hosts")),
lipgloss.JoinHorizontal(lipgloss.Left,
m.styles.FocusedLabel.Render("H "),
m.styles.HelpText.Render("toggle hidden hosts visibility")),
lipgloss.JoinHorizontal(lipgloss.Left,
m.styles.FocusedLabel.Render("f "),
m.styles.HelpText.Render("setup port forwarding")),

View File

@@ -70,8 +70,10 @@ func (p PortForwardType) String() string {
type Model struct {
table table.Model
searchInput textinput.Model
hosts []config.SSHHost
allHosts []config.SSHHost // all parsed hosts, including hidden ones
hosts []config.SSHHost // visible hosts (filtered by showHidden)
filteredHosts []config.SSHHost
showHidden bool // when true, hidden-tagged hosts are shown
searchMode bool
deleteMode bool
deleteHost *config.SSHHost // Host to be deleted (with line number for precise targeting)
@@ -108,6 +110,14 @@ type Model struct {
showingError bool
}
// applyVisibilityFilter returns hosts filtered according to the showHidden flag.
func (m Model) applyVisibilityFilter(hosts []config.SSHHost) []config.SSHHost {
if m.showHidden {
return hosts
}
return config.FilterVisibleHosts(hosts)
}
// updateTableStyles updates the table header border color based on focus state
func (m *Model) updateTableStyles() {
s := table.DefaultStyles()

View File

@@ -48,7 +48,7 @@ func NewModel(hosts []config.SSHHost, configFile string, searchMode bool, curren
// Create the model with default sorting by name
m := Model{
hosts: hosts,
allHosts: hosts,
historyManager: historyManager,
pingManager: pingManager,
sortMode: SortByName,
@@ -63,8 +63,12 @@ func NewModel(hosts []config.SSHHost, configFile string, searchMode bool, curren
searchMode: searchMode,
}
// Apply visibility filter (showHidden is false by default)
visibleHosts := m.applyVisibilityFilter(hosts)
m.hosts = visibleHosts
// Sort hosts according to the default sort mode
sortedHosts := m.sortHosts(hosts)
sortedHosts := m.sortHosts(visibleHosts)
// Create the search input
ti := textinput.New()

View File

@@ -187,7 +187,8 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
if err != nil {
return m, tea.Quit
}
m.hosts = m.sortHosts(hosts)
m.allHosts = hosts
m.hosts = m.sortHosts(m.applyVisibilityFilter(hosts))
// Reapply search filter if there is one active
if m.searchInput.Value() != "" {
@@ -231,7 +232,8 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
if err != nil {
return m, tea.Quit
}
m.hosts = m.sortHosts(hosts)
m.allHosts = hosts
m.hosts = m.sortHosts(m.applyVisibilityFilter(hosts))
// Reapply search filter if there is one active
if m.searchInput.Value() != "" {
@@ -276,7 +278,8 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
if err != nil {
return m, tea.Quit
}
m.hosts = m.sortHosts(hosts)
m.allHosts = hosts
m.hosts = m.sortHosts(m.applyVisibilityFilter(hosts))
// Reapply search filter if there is one active
if m.searchInput.Value() != "" {
@@ -535,7 +538,8 @@ func (m Model) handleListViewKeys(msg tea.KeyMsg) (tea.Model, tea.Cmd) {
m.table.Focus()
return m, nil
}
m.hosts = m.sortHosts(hosts)
m.allHosts = hosts
m.hosts = m.sortHosts(m.applyVisibilityFilter(hosts))
// Reapply search filter if there is one active
if m.searchInput.Value() != "" {
@@ -705,6 +709,19 @@ func (m Model) handleListViewKeys(msg tea.KeyMsg) (tea.Model, tea.Cmd) {
m.viewMode = ViewHelp
return m, nil
}
case "H":
if !m.searchMode && !m.deleteMode {
// Toggle visibility of hidden hosts
m.showHidden = !m.showHidden
m.hosts = m.sortHosts(m.applyVisibilityFilter(m.allHosts))
if m.searchInput.Value() != "" {
m.filteredHosts = m.filterHosts(m.searchInput.Value())
} else {
m.filteredHosts = m.hosts
}
m.updateTableRows()
return m, nil
}
case "s":
if !m.searchMode && !m.deleteMode {
// Cycle through sort modes (only 2 modes now)

View File

@@ -86,6 +86,14 @@ func (m Model) renderListView() string {
components = append(components, errorStyle.Render("❌ "+m.errorMessage))
}
// Add indicator when hidden hosts are shown
if m.showHidden {
hiddenBannerStyle := lipgloss.NewStyle().
Foreground(lipgloss.Color("11")).
Bold(true)
components = append(components, hiddenBannerStyle.Render(" [showing hidden hosts — press H to hide]"))
}
// Add the search bar with the appropriate style based on focus
searchPrompt := "Search (/ to focus): "
if m.searchMode {