From 6cf4c2630dc15d08ddde1f87860004233f8f3492 Mon Sep 17 00:00:00 2001 From: rob cobb Date: Fri, 7 Jan 2022 15:47:37 -0500 Subject: add by-window symlinks --- extension/background.js | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'extension/background.js') diff --git a/extension/background.js b/extension/background.js index 4bd9bec..cd5e5f3 100644 --- a/extension/background.js +++ b/extension/background.js @@ -210,6 +210,7 @@ Routes["/tabs/by-title"] = { return { entries: [".", "..", ...tabs.map(tab => sanitize(String(tab.title)) + "." + String(tab.id))] }; } }; + Routes["/tabs/by-title/:TAB_TITLE.#TAB_ID"] = { description: `Represents one open tab. It's a symbolic link to the folder /tabs/by-id/#TAB_ID.`, @@ -223,6 +224,38 @@ It's a symbolic link to the folder /tabs/by-id/#TAB_ID.`, return {}; } }; + +Routes["/tabs/by-window"] = { + description: 'Open tabs, organized by window then title; each subfolder represents an open tab.', + usage: 'ls $0', + getattr() { + return { + st_mode: unix.S_IFDIR | 0777, // writable so you can delete tabs + st_nlink: 3, + st_size: 0, + }; + }, + async readdir() { + const tabs = await browser.tabs.query({}); + return { entries: [".", "..", ...tabs.map(tab => sanitize(String(tab.windowId) + "." + String(tab.title)) + "." + String(tab.id))] }; + } +}; + +Routes["/tabs/by-window/#TAB_WINDOW_ID.:TAB_TITLE.#TAB_ID"] = { + description: `Represents one open tab. +It's a symbolic link to the folder /tabs/by-id/#TAB_ID.`, + // TODO: date + usage: ['rm $0'], + async readlink({tabId}) { + return { buf: "../by-id/" + tabId }; + }, + async unlink({tabId}) { + await browser.tabs.remove(tabId); + return {}; + } +}; + + Routes["/tabs/last-focused"] = { description: `Represents the most recently focused tab. It's a symbolic link to the folder /tabs/by-id/[ID of most recently focused tab].`, -- cgit v1.2.3 From bf7edaec22512dd385e95d2eba49287a45288cce Mon Sep 17 00:00:00 2001 From: rob cobb Date: Fri, 7 Jan 2022 16:22:16 -0500 Subject: add tabs directory to window --- extension/background.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'extension/background.js') diff --git a/extension/background.js b/extension/background.js index cd5e5f3..1655d5a 100644 --- a/extension/background.js +++ b/extension/background.js @@ -628,6 +628,24 @@ Routes["/windows"] = { return { entries: [".", "..", ...windows.map(window => String(window.id))] }; } }; + +Routes["/windows/#WINDOW_ID/tabs"] = { + async readdir({windowId}) { + const tabs = await browser.tabs.query({windowId}); + return { entries: [".", "..", ...tabs.map(tab => sanitize(String(tab.title) + "." + String(tab.id))) ] } + } +} + +Routes["/windows/#WINDOW_ID/tabs/:TAB_TITLE.#TAB_ID"] = { + async readlink({tabId}) { + return { buf: "../../../tabs/by-id/" + tabId }; + }, + async unlink({tabId}) { + await browser.tabs.remove(tabId); + return {}; + } +} + Routes["/windows/last-focused"] = { description: `A symbolic link to /windows/[id for the last focused window].`, async readlink() { @@ -635,6 +653,7 @@ Routes["/windows/last-focused"] = { return { buf: windowId }; } }; + (function() { const withWindow = (readHandler, writeHandler) => makeRouteWithContents(async ({windowId}) => { const window = await browser.windows.get(windowId); -- cgit v1.2.3