import "@johnlindquist/kit";
let bookmarks = await readFile(
home("Library/Application Support/Google/Chrome/Default/Bookmarks"),
);
bookmarks = JSON.parse(bookmarks);
bookmarks = bookmarks.roots.bookmark_bar.children;
let historyStack = [];
const CUSTOMSEPARATOR = "-CUSTOMSEPARATOR-";
while (true) {
const getBookmark = ({ name, url, type }) => {
if (type === "folder") {
return {
name: `🗂️ ${name}`,
description: "⤵️ Select directory",
value: `folder${CUSTOMSEPARATOR}${name}`,
};
}
return {
name: `⛓️ ${name}`,
description: url,
type,
value: `link${CUSTOMSEPARATOR}${url}`,
};
};
let options = bookmarks.map(getBookmark);
if (historyStack.length > 0) {
options = [
{ name: "..", description: "Go back", value: "go-back" },
...options,
];
}
const lastSelection = await arg("Select A Bookmark!", options);
if (lastSelection === "go-back") {
bookmarks = historyStack.pop();
continue;
}
const [type, value] = lastSelection.split(CUSTOMSEPARATOR);
if (type === "folder") {
historyStack.push(bookmarks);
bookmarks = bookmarks.find((bookmark) => bookmark.name === value).children;
continue;
}
if (type === "link") {
exec(`open "${value}"`);
break;
}
console.log("Unknown type", type);
}
sh(bookmarks);
bookmarks = bookmarks.find((bookmark) => bookmark.name === value).children;
continue;
}
if (type === "link") {
exec(`open "${value}"`);
break;
}
console.log("Unknown type", type);
}