refactor(dmenu): simplify history display to show URL without scheme
- commit
- a703a07d482677306da4d5b59890219fdbf126c8
- author
- bnema · · 2025-11-19 06:45 UTC
- parent
- 760db44
- signature
- unsigned
1 file · +7 -38
M internal/cli/dmenu.go +7 -38
| @@ -4,16 +4,16 @@ import ( | |||
| 4 | 4 | "bufio" | |
| 5 | 5 | "context" | |
| 6 | 6 | "fmt" | |
| 7 | - | "net/url" | |
| 8 | 7 | "os" | |
| 9 | 8 | "sort" | |
| 10 | 9 | "strings" | |
| 11 | 10 | "time" | |
| 12 | 11 | ||
| 12 | + | "github.com/spf13/cobra" | |
| 13 | + | ||
| 13 | 14 | "github.com/bnema/dumber/internal/cache" | |
| 14 | 15 | "github.com/bnema/dumber/internal/config" | |
| 15 | 16 | "github.com/bnema/dumber/internal/services" | |
| 16 | - | "github.com/spf13/cobra" | |
| 17 | 17 | ) | |
| 18 | 18 | ||
| 19 | 19 | const ( | |
| @@ -88,42 +88,11 @@ func generateOptions(cli *CLI) error { | |||
| 88 | 88 | for _, match := range result.Matches { | |
| 89 | 89 | entry := match.Entry | |
| 90 | 90 | ||
| 91 | - | // Parse URL for domain extraction | |
| 92 | - | parsedURL, err := url.Parse(entry.URL) | |
| 93 | - | var domain string | |
| 94 | - | if err != nil || parsedURL.Host == "" { | |
| 95 | - | domain = "local" | |
| 96 | - | } else { | |
| 97 | - | domain = parsedURL.Host | |
| 98 | - | } | |
| 99 | - | ||
| 100 | - | // Determine title | |
| 101 | - | title := entry.Title | |
| 102 | - | if title == "" || title == entry.URL { | |
| 103 | - | // Use meaningful fallback for untitled pages | |
| 104 | - | if parsedURL != nil && parsedURL.Path != "" && parsedURL.Path != "/" { | |
| 105 | - | title = fmt.Sprintf("[%s%s]", domain, parsedURL.Path) | |
| 106 | - | } else { | |
| 107 | - | title = fmt.Sprintf("[%s]", domain) | |
| 108 | - | } | |
| 109 | - | } | |
| 110 | - | ||
| 111 | - | // Check if it's a Google search result and format accordingly | |
| 112 | - | isGoogleSearch := domain == "www.google.com" && strings.Contains(entry.URL, "/search?q=") | |
| 113 | - | if isGoogleSearch { | |
| 114 | - | if parsedURL != nil { | |
| 115 | - | if q := parsedURL.Query().Get("q"); q != "" { | |
| 116 | - | title = fmt.Sprintf("Google: \"%s\"", q) | |
| 117 | - | } | |
| 118 | - | } | |
| 119 | - | } | |
| 120 | - | ||
| 121 | - | // Format: "Title | domain.com | full-url" | |
| 122 | - | // Using pipe separator for rofi/dmenu compatibility | |
| 123 | - | display := fmt.Sprintf("%s | %s | %s", | |
| 124 | - | truncateString(title, 50), | |
| 125 | - | domain, | |
| 126 | - | truncateString(entry.URL, 70)) | |
| 91 | + | // Strip scheme from URL (remove https:// or http://) | |
| 92 | + | display := entry.URL | |
| 93 | + | display = strings.TrimPrefix(display, "https://") | |
| 94 | + | display = strings.TrimPrefix(display, "http://") | |
| 95 | + | display = truncateString(display, 100) | |
| 127 | 96 | ||
| 128 | 97 | // Get favicon URL from cached entry | |
| 129 | 98 | faviconURL := match.Entry.FaviconURL | |
| @@ -4,16 +4,16 @@ import ( | |||||
| 4 | "bufio" | 4 | "bufio" | ||
| 5 | "context" | 5 | "context" | ||
| 6 | "fmt" | 6 | "fmt" | ||
| 7 | - | "net/url" | |||
| 8 | "os" | 7 | "os" | ||
| 9 | "sort" | 8 | "sort" | ||
| 10 | "strings" | 9 | "strings" | ||
| 11 | "time" | 10 | "time" | ||
| 12 | 11 | ||||
| 12 | + | "github.com/spf13/cobra" | |||
| 13 | + | ||||
| 13 | "github.com/bnema/dumber/internal/cache" | 14 | "github.com/bnema/dumber/internal/cache" | ||
| 14 | "github.com/bnema/dumber/internal/config" | 15 | "github.com/bnema/dumber/internal/config" | ||
| 15 | "github.com/bnema/dumber/internal/services" | 16 | "github.com/bnema/dumber/internal/services" | ||
| 16 | - | "github.com/spf13/cobra" | |||
| 17 | ) | 17 | ) | ||
| 18 | 18 | ||||
| 19 | const ( | 19 | const ( | ||
| @@ -88,42 +88,11 @@ func generateOptions(cli *CLI) error { | |||||
| 88 | for _, match := range result.Matches { | 88 | for _, match := range result.Matches { | ||
| 89 | entry := match.Entry | 89 | entry := match.Entry | ||
| 90 | 90 | ||||
| 91 | - | // Parse URL for domain extraction | 91 | + | // Strip scheme from URL (remove https:// or http://) |
| 92 | - | parsedURL, err := url.Parse(entry.URL) | 92 | + | display := entry.URL |
| 93 | - | var domain string | 93 | + | display = strings.TrimPrefix(display, "https://") |
| 94 | - | if err != nil || parsedURL.Host == "" { | 94 | + | display = strings.TrimPrefix(display, "http://") |
| 95 | - | domain = "local" | 95 | + | display = truncateString(display, 100) |
| 96 | - | } else { | |||
| 97 | - | domain = parsedURL.Host | |||
| 98 | - | } | |||
| 99 | - | ||||
| 100 | - | // Determine title | |||
| 101 | - | title := entry.Title | |||
| 102 | - | if title == "" || title == entry.URL { | |||
| 103 | - | // Use meaningful fallback for untitled pages | |||
| 104 | - | if parsedURL != nil && parsedURL.Path != "" && parsedURL.Path != "/" { | |||
| 105 | - | title = fmt.Sprintf("[%s%s]", domain, parsedURL.Path) | |||
| 106 | - | } else { | |||
| 107 | - | title = fmt.Sprintf("[%s]", domain) | |||
| 108 | - | } | |||
| 109 | - | } | |||
| 110 | - | ||||
| 111 | - | // Check if it's a Google search result and format accordingly | |||
| 112 | - | isGoogleSearch := domain == "www.google.com" && strings.Contains(entry.URL, "/search?q=") | |||
| 113 | - | if isGoogleSearch { | |||
| 114 | - | if parsedURL != nil { | |||
| 115 | - | if q := parsedURL.Query().Get("q"); q != "" { | |||
| 116 | - | title = fmt.Sprintf("Google: \"%s\"", q) | |||
| 117 | - | } | |||
| 118 | - | } | |||
| 119 | - | } | |||
| 120 | - | ||||
| 121 | - | // Format: "Title | domain.com | full-url" | |||
| 122 | - | // Using pipe separator for rofi/dmenu compatibility | |||
| 123 | - | display := fmt.Sprintf("%s | %s | %s", | |||
| 124 | - | truncateString(title, 50), | |||
| 125 | - | domain, | |||
| 126 | - | truncateString(entry.URL, 70)) | |||
| 127 | 96 | ||||
| 128 | // Get favicon URL from cached entry | 97 | // Get favicon URL from cached entry | ||
| 129 | faviconURL := match.Entry.FaviconURL | 98 | faviconURL := match.Entry.FaviconURL | ||