diff options
| author | 2026-02-24 12:58:53 -0800 | |
|---|---|---|
| committer | 2026-02-24 12:58:53 -0800 | |
| commit | 24a4cea0b1f5c1d5640ec0ab0b27c080c226268f (patch) | |
| tree | 6d7af3416db1cb3de89c14ce598e95f10734ff9d | |
| parent | 12894d7dd9471cd08807cb2245529b94c77f5bff (diff) | |
| download | new-dotfiles-24a4cea0b1f5c1d5640ec0ab0b27c080c226268f.tar.gz new-dotfiles-24a4cea0b1f5c1d5640ec0ab0b27c080c226268f.zip | |
glide: Add new tab command with more features
| -rw-r--r-- | glide/.config/glide/glide.ts | 131 |
1 files changed, 131 insertions, 0 deletions
diff --git a/glide/.config/glide/glide.ts b/glide/.config/glide/glide.ts index 678b876..4b061b9 100644 --- a/glide/.config/glide/glide.ts +++ b/glide/.config/glide/glide.ts @@ -250,3 +250,134 @@ glide.keymaps.set("normal", "gh", async () => { }), }); }, { description: "Jump to heading in current page" }); + +// From https://github.com/glide-browser/glide/discussions/147#discussioncomment-15337351 + +/** + * custom search providers + */ +const search_info: Record<string, { url: string, sep: string }> = { + 'youtube': { + url: "https://www.youtube.com/results?search_query=", sep: "+" + } +} as const + +/* +* pick tabs via a selection of bookmarks and history +*/ + +glide.keymaps.set("normal", "<leader>t", async () => { + + //let combined: Array<Browser.Bookmarks.BookmarkTreeNode | Browser.History.HistoryItem> = [] + let combined = [] + const bookmarks = await browser.bookmarks.getRecent(20); + bookmarks.forEach(bmark => combined.push({ title: bmark.title, url: bmark.url, type: 'B' })); + + const history = await browser.history.search({ text: "", maxResults: 100 }); + history.forEach(entry => combined.push({ title: entry.title, url: entry.url, type: 'H' })); + + const tabs = await browser.tabs.query({}); + tabs.forEach(entry => combined.push({ title: entry.title ?? 'Unnamed Tab', url: entry.url, type: 'T' })); + + // filtering + const newtab = (await browser.runtime.getManifest()).chrome_url_overrides?.newtab + const startpage = glide.prefs.get("browser.startup.homepage") + + let filtered_combined = combined.filter(e => e.url !== startpage && e.url !== newtab) + + glide.commandline.show({ + title: "open", + options: filtered_combined.map((entry) => ({ + label: entry.title, + render() { + return DOM.create_element("div", { + style: { + display: "flex", + alignItems: "center", + gap: "8px", + }, + children: [ + DOM.create_element("span", [entry.type], { + style: { color: "#777", fontSize: "0.9em" }, + }), + DOM.create_element("span", [entry.title]), + DOM.create_element("span", [entry.url], { + style: { color: "#777", fontSize: "0.9em" }, + }), + ], + }); + }, + async execute({ input: input }) { + + + if (entry.title.toLowerCase().includes(input.toLowerCase())) { + const tab = await glide.tabs.get_first({ + url: entry.url, + }); + if (tab) { + const windowid = tab.windowId; + if (windowid === undefined) { + return + } + await browser.windows.update(windowid, { + focused: true + }) + await browser.tabs.update(tab.id, { + active: true, + }); + } else { + + await browser.tabs.update((await glide.tabs.active()).id, { + active: true, + url: entry.url, + }); + } + } else { + const terms = input.split(" ",) + const first = terms[0] + if (terms.length > 1 && first !== undefined && first in search_info) { + let info = search_info[first]; + let query = info?.url + terms.slice(1).join(info?.sep) + browser.tabs.create({ + active: true, + url: query + }); + return; + } + + let url: URL; + try { + url = new URL(input) + } catch (_) { + try { + url = new URL("http://" + input) // firefox automatically makes this https + + // avoids single word searches becoming URLs + if (url.hostname.split(".").length == 1 && url.hostname !== "localhost") { + throw "probably not a hostname"; + } + } catch (_) { // probably not a url + browser.search.search({ + query: terms.filter(s => s).join(" "), + disposition: "NEW_WINDOW", + }) + return + } + + } + // so it IS a URL! + + const tab = browser.tabs.get_first({ url }); + + if (tab) { + browser.tabs.update(tab.id, { active: true }); + } + else { + browser.tabs.create({ active: true, url }); + } + } + + }, + })), + }); +}, { description: "Open the site searcher" }); |
