diff options
| author | Paul Buetow <paul@buetow.org> | 2026-07-19 10:46:22 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-07-19 10:46:22 +0300 |
| commit | 8ec2807ece746b001e3d64a1db990ce239a98801 (patch) | |
| tree | 435415c1a9040c41276466d8a74137a964c01a2d /internal/ui/table.go | |
| parent | 9c87952fbae0b84cde3802086eed88f3a0c51051 (diff) | |
cv0: open YouTube links in an alternative browser
The 'o' open key now routes youtube.com/youtu.be video links to an
optional alternative browser (e.g. chromium) via the new
--youtube-browser-cmd flag, while every other URL keeps using
--browser-cmd. When the flag is unset, YouTube links fall back to the
default browser as before.
- add youtubeBrowserCmd field and SetYouTubeBrowserCmd setter
- add youtubeHostRegex plus isYouTubeURL and browserForURL helpers
- wire --youtube-browser-cmd flag in main.go
- unit-test URL detection and browser selection
- document the flag in README
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Diffstat (limited to 'internal/ui/table.go')
| -rw-r--r-- | internal/ui/table.go | 28 |
1 files changed, 23 insertions, 5 deletions
diff --git a/internal/ui/table.go b/internal/ui/table.go index e168ba7..5efb41e 100644 --- a/internal/ui/table.go +++ b/internal/ui/table.go @@ -35,7 +35,12 @@ var ( // fileRefRegex matches an @-prefixed file reference such as // "@path/to/file.txt". The leading (^|\s) anchor keeps it from matching // the "@host" part of an email address; capture group 2 is the path. - fileRefRegex = regexp.MustCompile(`(^|\s)@(\S+)`) + fileRefRegex = regexp.MustCompile(`(^|\s)@(\S+)`) + // youtubeHostRegex matches the host of a YouTube video link so the "o" + // key can route it to an alternative browser. It covers youtube.com (with + // optional www./m. subdomains) and the youtu.be short-link domain. Case is + // ignored because hostnames are case-insensitive. + youtubeHostRegex = regexp.MustCompile(`(?i)^(www\.|m\.)?(youtube\.com|youtu\.be)$`) searchRegexCache = make(map[string]*regexp.Regexp, 16) searchRegexMu sync.RWMutex ) @@ -221,10 +226,15 @@ type Model struct { inProgress int due int - filters []string - tasks []task.Task - undoStack []undoAction - browserCmd string + filters []string + tasks []task.Task + undoStack []undoAction + browserCmd string + // youtubeBrowserCmd, when non-empty, overrides browserCmd for YouTube + // links opened with the "o" key. This lets the user route videos to a + // browser better suited for them (e.g. chromium) while keeping the + // default browser (e.g. firefox) for everything else. + youtubeBrowserCmd string agentFilterHotkey string taskwarrior task.Taskwarrior @@ -1436,6 +1446,14 @@ func (m *Model) SetAgentFilterHotkey(key string) error { return nil } +// SetYouTubeBrowserCmd configures the browser command used specifically for +// YouTube links opened with the "o" key. An empty value (the default) means +// YouTube links are opened with the regular browser command like any other +// URL. Surrounding whitespace is trimmed so a blank flag value counts as unset. +func (m *Model) SetYouTubeBrowserCmd(cmd string) { + m.youtubeBrowserCmd = strings.TrimSpace(cmd) +} + func (m *Model) agentFilterHotkeyLabel() string { if strings.TrimSpace(m.agentFilterHotkey) == "" { return "3" |
