Skip to content

Commit 0ad4d44

Browse files
authored
feat: consider uris with custom schemes as bookmarks (#21)
For example: - https://c.xkcd.com/random/comic - `spotify:track:4fVBFyglBhMf0erfF7pBJp` - `obsidian://open?vault=VAULT&file=FILE` - `mailto:[email protected]` - `slack://channel?team=TEAM_ID&id=ID` Resolves #20.
1 parent 44aeaa2 commit 0ad4d44

File tree

13 files changed

+175
-74
lines changed

13 files changed

+175
-74
lines changed
Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
1-
Sometimes you'll add URLs to a task's summary or its context.
1+
Sometimes you'll add URIs to a task's summary or its context.
22

3-
Such URLs (eg. https://github.com/dhth/omm, https://tools.dhruvs.space,
4-
https://c.xkcd.com/random/comic) could be placed anywhere in the
5-
summary/context.
3+
Such URIs could be placed anywhere in the summary/context. For example:
64

7-
omm lets you open these URLs via a single keypress. You can either press `b` to
8-
open up a list of all URLs, and then open one of them by pressing `` or open
9-
all of them by pressing `B`.
5+
- https://c.xkcd.com/random/comic
6+
- spotify:track:4fVBFyglBhMf0erfF7pBJp
7+
- obsidian://open?vault=VAULT&file=FILE
8+
9+
- slack://channel?team=TEAM_ID&id=ID
1010

11-
Note: If a task has a single URL added to it, pressing `b` will skip showing the
12-
list, and open the URL directly.
11+
omm lets you open these URIs via a single keypress. You can either press `b` to
12+
open up a list of all URIs, and then open one of them by pressing `` or open
13+
all of them by pressing `B` (some of them will fail to be opened on your machine
14+
since they point to non-existent resources, but you get the point).
15+
16+
Note: If a task has a single URI added to it, pressing `b` will skip showing the
17+
list, and open the URI directly.
1318

1419
Try both approaches now.

internal/types/colors.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package types
2+
3+
var (
4+
colors = []string{
5+
"#d3869b",
6+
"#b5e48c",
7+
"#90e0ef",
8+
"#ca7df9",
9+
"#ada7ff",
10+
"#bbd0ff",
11+
"#48cae4",
12+
"#8187dc",
13+
"#ffb4a2",
14+
"#b8bb26",
15+
"#ffc6ff",
16+
"#4895ef",
17+
"#83a598",
18+
"#fabd2f",
19+
}
20+
)

internal/types/types.go

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -26,23 +26,7 @@ const (
2626
var (
2727
createdAtColor = "#928374"
2828
hasContextColor = "#928374"
29-
taskColors = []string{
30-
"#d3869b",
31-
"#b5e48c",
32-
"#90e0ef",
33-
"#ca7df9",
34-
"#ada7ff",
35-
"#bbd0ff",
36-
"#48cae4",
37-
"#8187dc",
38-
"#ffb4a2",
39-
"#b8bb26",
40-
"#ffc6ff",
41-
"#4895ef",
42-
"#83a598",
43-
"#fabd2f",
44-
}
45-
createdAtStyle = lipgloss.NewStyle().
29+
createdAtStyle = lipgloss.NewStyle().
4630
Foreground(lipgloss.Color(createdAtColor))
4731

4832
hasContextStyle = lipgloss.NewStyle().
@@ -155,7 +139,7 @@ func GetDynamicStyle(str string) lipgloss.Style {
155139
h.Write([]byte(str))
156140
hash := h.Sum32()
157141

158-
color := taskColors[int(hash)%len(taskColors)]
142+
color := colors[int(hash)%len(colors)]
159143
return lipgloss.NewStyle().
160144
Foreground(lipgloss.Color(color))
161145
}

internal/ui/assets/help.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,5 +84,5 @@ B open all bookmarks added to current task
8484
### Task Bookmarks List
8585

8686
```text
87-
⏎ open URL in browser
87+
⏎ open URI in browser
8888
```

internal/ui/cmds.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ func openTextEditor(fPath string, editorCmd []string, taskIndex int, taskId uint
9292
})
9393
}
9494

95-
func openURL(url string) tea.Cmd {
95+
func openURI(uri string) tea.Cmd {
9696
var cmd string
9797
var args []string
9898
switch runtime.GOOS {
@@ -104,16 +104,16 @@ func openURL(url string) tea.Cmd {
104104
default:
105105
cmd = "xdg-open"
106106
}
107-
c := exec.Command(cmd, append(args, url)...)
107+
c := exec.Command(cmd, append(args, uri)...)
108108
return tea.ExecProcess(c, func(err error) tea.Msg {
109-
return urlOpenedMsg{url, err}
109+
return uriOpenedMsg{uri, err}
110110
})
111111
}
112112

113-
func openURLsDarwin(urls []string) tea.Cmd {
114-
c := exec.Command("open", urls...)
113+
func openURIsDarwin(uris []string) tea.Cmd {
114+
c := exec.Command("open", uris...)
115115
return tea.ExecProcess(c, func(err error) tea.Msg {
116-
return urlsOpenedDarwinMsg{urls, err}
116+
return urisOpenedDarwinMsg{uris, err}
117117
})
118118
}
119119

internal/ui/initial.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"github.com/charmbracelet/lipgloss"
1010
"github.com/dhth/omm/internal/types"
1111
"github.com/dhth/omm/internal/utils"
12-
"mvdan.cc/xurls/v2"
1312
)
1413

1514
func InitialModel(db *sql.DB, config Config) model {
@@ -135,7 +134,7 @@ func InitialModel(db *sql.DB, config Config) model {
135134
atlSelStyle: atlSelItemStyle,
136135
contextVPTaskId: 0,
137136
rtos: runtime.GOOS,
138-
urlRegex: xurls.Strict(),
137+
uriRegex: utils.GetURIRegex(),
139138
taskDetailsMdRenderer: tr,
140139
}
141140

internal/ui/model.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ type model struct {
8989
terminalHeight int
9090
contextVPTaskId uint64
9191
rtos string
92-
urlRegex *regexp.Regexp
92+
uriRegex *regexp.Regexp
9393
shortenedListHt int
9494
contextMdRenderer *glamour.TermRenderer
9595
taskDetailsMdRenderer *glamour.TermRenderer

internal/ui/msgs.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,12 @@ type textEditorClosed struct {
6666
err error
6767
}
6868

69-
type urlOpenedMsg struct {
69+
type uriOpenedMsg struct {
7070
url string
7171
err error
7272
}
7373

74-
type urlsOpenedDarwinMsg struct {
74+
type urisOpenedDarwinMsg struct {
7575
urls []string
7676
err error
7777
}

internal/ui/update.go

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -873,8 +873,8 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
873873
m.archivedTaskList.Select(listIndex)
874874

875875
case contextBookmarksView:
876-
url := m.taskBMList.SelectedItem().FilterValue()
877-
cmds = append(cmds, openURL(url))
876+
uri := m.taskBMList.SelectedItem().FilterValue()
877+
cmds = append(cmds, openURI(uri))
878878
case prefixSelectionView:
879879
prefix := m.prefixSearchList.SelectedItem().FilterValue()
880880

@@ -1155,24 +1155,24 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
11551155
break
11561156
}
11571157

1158-
urls, ok := m.getTaskUrls()
1158+
uris, ok := m.getTaskURIs()
11591159
if !ok {
11601160
break
11611161
}
11621162

1163-
if len(urls) == 0 {
1163+
if len(uris) == 0 {
11641164
m.errorMsg = "No bookmarks for this task"
11651165
break
11661166
}
11671167

1168-
if len(urls) == 1 {
1169-
cmds = append(cmds, openURL(urls[0]))
1168+
if len(uris) == 1 {
1169+
cmds = append(cmds, openURI(uris[0]))
11701170
break
11711171
}
11721172

1173-
bmItems := make([]list.Item, len(urls))
1174-
for i, url := range urls {
1175-
bmItems[i] = list.Item(types.ContextBookmark(url))
1173+
bmItems := make([]list.Item, len(uris))
1174+
for i, uri := range uris {
1175+
bmItems[i] = list.Item(types.ContextBookmark(uri))
11761176
}
11771177
m.taskBMList.SetItems(bmItems)
11781178
switch m.activeView {
@@ -1189,28 +1189,28 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
11891189
break
11901190
}
11911191

1192-
urls, ok := m.getTaskUrls()
1192+
uris, ok := m.getTaskURIs()
11931193
if !ok {
11941194
break
11951195
}
11961196

1197-
if len(urls) == 0 {
1197+
if len(uris) == 0 {
11981198
m.errorMsg = "No bookmarks for this task"
11991199
break
12001200
}
12011201

1202-
if len(urls) == 1 {
1203-
cmds = append(cmds, openURL(urls[0]))
1202+
if len(uris) == 1 {
1203+
cmds = append(cmds, openURI(uris[0]))
12041204
break
12051205
}
12061206

12071207
if m.rtos == types.GOOSDarwin {
1208-
cmds = append(cmds, openURLsDarwin(urls))
1208+
cmds = append(cmds, openURIsDarwin(uris))
12091209
break
12101210
}
12111211

1212-
for _, url := range urls {
1213-
cmds = append(cmds, openURL(url))
1212+
for _, uri := range uris {
1213+
cmds = append(cmds, openURI(uri))
12141214
}
12151215

12161216
case "y":
@@ -1451,13 +1451,13 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
14511451
}
14521452

14531453
cmds = append(cmds, updateTaskContext(m.db, msg.taskIndex, msg.taskId, string(context), m.activeTaskList))
1454-
case urlOpenedMsg:
1454+
case uriOpenedMsg:
14551455
if msg.err != nil {
1456-
m.errorMsg = fmt.Sprintf("Error opening url: %s", msg.err)
1456+
m.errorMsg = fmt.Sprintf("Error opening uri: %s", msg.err)
14571457
}
1458-
case urlsOpenedDarwinMsg:
1458+
case urisOpenedDarwinMsg:
14591459
if msg.err != nil {
1460-
m.errorMsg = fmt.Sprintf("Error opening urls: %s", msg.err)
1460+
m.errorMsg = fmt.Sprintf("Error opening uris: %s", msg.err)
14611461
}
14621462

14631463
case contextWrittenToCBMsg:
@@ -1627,7 +1627,7 @@ func (m *model) setContextFSContent(task types.Task) {
16271627
m.taskDetailsVP.SetContent(details)
16281628
}
16291629

1630-
func (m model) getTaskUrls() ([]string, bool) {
1630+
func (m model) getTaskURIs() ([]string, bool) {
16311631
var t types.Task
16321632
var ok bool
16331633

@@ -1648,11 +1648,11 @@ func (m model) getTaskUrls() ([]string, bool) {
16481648
return nil, false
16491649
}
16501650

1651-
var urls []string
1652-
urls = append(urls, utils.ExtractURLs(m.urlRegex, t.Summary)...)
1651+
var uris []string
1652+
uris = append(uris, utils.ExtractURIs(m.uriRegex, t.Summary)...)
16531653
if t.Context != nil {
1654-
urls = append(urls, utils.ExtractURLs(m.urlRegex, *t.Context)...)
1654+
uris = append(uris, utils.ExtractURIs(m.uriRegex, *t.Context)...)
16551655
}
16561656

1657-
return urls, true
1657+
return uris, true
16581658
}

internal/utils/assets/gruvbox.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
"block_prefix": ". "
6969
},
7070
"task": {
71-
"ticked": "[] ",
71+
"ticked": "[] ",
7272
"unticked": "[ ] "
7373
},
7474
"link": {

0 commit comments

Comments
 (0)