feat: introduce shortcuts and shell hook support
Release / release (push) Successful in 50s

- **Shortcuts**: Add hostname normalization with domain stripping and hyphen folding. Include alias generation for cached hosts.
- **Shell Hook**: Automate 24h cache refresh trigger with shell startup hook. Add install/uninstall commands for bash, zsh, and fish.
- **Wizard**: Extend setup wizard to configure shortcuts (domains, hyphen stripping) and default SSH port.
- **Cache**: Add `GetByShortcut` for resolving hosts via normalized shortcuts. Implement `NeedsRefresh` / `SetRefreshed` logic for refresh timestamps.
- **Tests**: Comprehensive unit tests for shortcuts, hook installation, cache refresh, and alias generation.
- **Docs**: Update README with shortcuts, shell hook, and default SSH port configuration.
This commit is contained in:
Sebastian Unterschütz
2026-05-27 22:53:24 +02:00
parent d127a3b957
commit 7c902cab3a
13 changed files with 1378 additions and 19 deletions
+13
View File
@@ -86,6 +86,19 @@ func ReplaceHost(args []string, destIdx int, newHost string) []string {
return result
}
// HasPortFlag reports whether a port was specified via -p in args.
func HasPortFlag(args []string) bool {
for i, a := range args {
if a == "-p" && i+1 < len(args) {
return true
}
if len(a) > 2 && a[0] == '-' && a[1] == 'p' {
return true
}
}
return false
}
// HasUserFlag reports whether a user was specified via -l in args.
// Used to avoid overriding an explicit -l with the configured default user.
func HasUserFlag(args []string) bool {
+31
View File
@@ -144,6 +144,37 @@ func TestHasUserFlag_LFlagAtEnd(t *testing.T) {
}
}
func TestHasPortFlag_FlagSeparated(t *testing.T) {
if !HasPortFlag([]string{"-p", "2222", "host"}) {
t.Error("should detect -p <port>")
}
}
func TestHasPortFlag_FlagAttached(t *testing.T) {
if !HasPortFlag([]string{"-p2222", "host"}) {
t.Error("should detect -p<port> (attached form)")
}
}
func TestHasPortFlag_NotPresent(t *testing.T) {
if HasPortFlag([]string{"-l", "admin", "host"}) {
t.Error("should not detect port flag when absent")
}
}
func TestHasPortFlag_EmptyArgs(t *testing.T) {
if HasPortFlag([]string{}) {
t.Error("empty args should return false")
}
}
func TestHasPortFlag_PAtEnd(t *testing.T) {
// -p at the very end with no value — should return false
if HasPortFlag([]string{"-p"}) {
t.Error("-p with no value should return false")
}
}
func assertParsed(t *testing.T, got *ParsedArgs, host, user string, destIdx int) {
t.Helper()
if got == nil {