-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
Showing
13 changed files
with
175 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,19 @@ | ||
Sometimes you'll add URLs to a task's summary or its context. | ||
Sometimes you'll add URIs to a task's summary or its context. | ||
|
||
Such URLs (eg. https://github.com/dhth/omm, https://tools.dhruvs.space, | ||
https://c.xkcd.com/random/comic) could be placed anywhere in the | ||
summary/context. | ||
Such URIs could be placed anywhere in the summary/context. For example: | ||
|
||
omm lets you open these URLs via a single keypress. You can either press `b` to | ||
open up a list of all URLs, and then open one of them by pressing `⏎` or open | ||
all of them by pressing `B`. | ||
- 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 | ||
|
||
Note: If a task has a single URL added to it, pressing `b` will skip showing the | ||
list, and open the URL directly. | ||
omm lets you open these URIs via a single keypress. You can either press `b` to | ||
open up a list of all URIs, and then open one of them by pressing `⏎` or open | ||
all of them by pressing `B` (some of them will fail to be opened on your machine | ||
since they point to non-existent resources, but you get the point). | ||
|
||
Note: If a task has a single URI added to it, pressing `b` will skip showing the | ||
list, and open the URI directly. | ||
|
||
Try both approaches now. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package types | ||
|
||
var ( | ||
colors = []string{ | ||
"#d3869b", | ||
"#b5e48c", | ||
"#90e0ef", | ||
"#ca7df9", | ||
"#ada7ff", | ||
"#bbd0ff", | ||
"#48cae4", | ||
"#8187dc", | ||
"#ffb4a2", | ||
"#b8bb26", | ||
"#ffc6ff", | ||
"#4895ef", | ||
"#83a598", | ||
"#fabd2f", | ||
} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package utils | ||
|
||
import ( | ||
"regexp" | ||
"strings" | ||
|
||
"mvdan.cc/xurls/v2" | ||
) | ||
|
||
// duplicated from https://github.com/mvdan/xurls/blob/master/xurls.go#L83-L88 as xurls doesn't let the user extend or | ||
// override SchemesNoAuthority | ||
var ( | ||
knownSchemes = []string{ | ||
`cid`, | ||
`file`, | ||
`magnet`, | ||
`mailto`, | ||
`mid`, | ||
`sms`, | ||
`tel`, | ||
`xmpp`, | ||
`spotify`, | ||
`facetime`, | ||
`facetime-audio`, | ||
} | ||
anyScheme = `(?:[a-zA-Z][a-zA-Z.\-+]*://|` + anyOf(knownSchemes...) + `:)` | ||
) | ||
|
||
func anyOf(strs ...string) string { | ||
var b strings.Builder | ||
b.WriteString("(?:") | ||
for i, s := range strs { | ||
if i != 0 { | ||
b.WriteByte('|') | ||
} | ||
b.WriteString(regexp.QuoteMeta(s)) | ||
} | ||
b.WriteByte(')') | ||
return b.String() | ||
} | ||
|
||
func GetURIRegex() *regexp.Regexp { | ||
rgx, err := xurls.StrictMatchingScheme(anyScheme) | ||
if err != nil { | ||
return xurls.Strict() | ||
} | ||
|
||
return rgx | ||
} | ||
|
||
func ExtractURIs(rg *regexp.Regexp, text string) []string { | ||
return rg.FindAllString(text, -1) | ||
} |
Oops, something went wrong.