Skip to content

Commit

Permalink
refactor: rename google_chrome to chrome
Browse files Browse the repository at this point in the history
For consistency and simplicity sake. Previously, I did this as I thought
it might get confused with the Chromium browser (yet to be supported).
  • Loading branch information
dhruvmanila committed Jan 5, 2022
1 parent 4dc4805 commit b81e3b2
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 19 deletions.
23 changes: 15 additions & 8 deletions lua/telescope/_extensions/bookmarks.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ local config = require("telescope.config").values
local actions = require "telescope.actions"
local entry_display = require "telescope.pickers.entry_display"

local utils = require "telescope._extensions.bookmarks.utils"
local smart_url_opener =
require("telescope._extensions.bookmarks.actions").smart_url_opener

Expand All @@ -19,13 +20,13 @@ local state = {
os_homedir = vim.loop.os_homedir(),
}

---Aliases to be displayed in the prompt title.
local aliases = {
---Prompt title.
local title = {
brave = "Brave",
google_chrome = "Google Chrome",
safari = "Safari",
chrome = "Chrome",
edge = "Edge",
firefox = "Firefox",
edge = "Microsoft Edge",
safari = "Safari",
}

---Set the configuration state.
Expand All @@ -40,10 +41,16 @@ end
---@param opts table
local function bookmarks(opts)
opts = opts or {}
-- TODO: Deprecation warning start: Removal scheduled at: 31/01/2022
if state.selected_browser == "google_chrome" then
utils.warn "Deprecated browser name: 'google_chrome'. Please use 'chrome' instead."
state.selected_browser = "chrome"
end
-- TODO: Deprecation warning end
local selected_browser = state.selected_browser

if not aliases[selected_browser] then
local supported = table.concat(vim.tbl_keys(aliases), ", ")
if not title[selected_browser] then
local supported = table.concat(vim.tbl_keys(title), ", ")
error(
string.format("Unsupported browser: %s (%s)", selected_browser, supported)
)
Expand Down Expand Up @@ -73,7 +80,7 @@ local function bookmarks(opts)
end

pickers.new(opts, {
prompt_title = "Search " .. aliases[selected_browser] .. " Bookmarks",
prompt_title = "Search " .. title[selected_browser] .. " Bookmarks",
finder = finders.new_table {
results = results,
entry_maker = function(entry)
Expand Down
4 changes: 2 additions & 2 deletions lua/telescope/_extensions/bookmarks/brave.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
local google_chrome = require "telescope._extensions.bookmarks.google_chrome"
local chrome = require "telescope._extensions.bookmarks.chrome"

local brave = {}

Expand All @@ -7,7 +7,7 @@ local brave = {}
---@param state ConfigState
---@return Bookmark[]|nil
function brave.collect_bookmarks(state)
return google_chrome.collect_bookmarks(state)
return chrome.collect_bookmarks(state)
end

return brave
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
local google_chrome = {}
local chrome = {}

local utils = require "telescope._extensions.bookmarks.utils"

Expand All @@ -17,7 +17,7 @@ local bookmarks_filepath = {
"Default",
"Bookmarks",
},
google_chrome = {
chrome = {
"Library",
"Application Support",
"Google",
Expand All @@ -41,7 +41,7 @@ local bookmarks_filepath = {
"Default",
"Bookmarks",
},
google_chrome = {
chrome = {
".config",
"google-chrome",
"Default",
Expand All @@ -64,7 +64,7 @@ local bookmarks_filepath = {
"Default",
"Bookmarks",
},
google_chrome = {
chrome = {
"AppData",
"Local",
"Google",
Expand Down Expand Up @@ -117,7 +117,7 @@ end
---Collect all the bookmarks for Google Chrome or Brave browser.
---@param state ConfigState
---@return Bookmark[]|nil
function google_chrome.collect_bookmarks(state)
function chrome.collect_bookmarks(state)
local components = bookmarks_filepath[state.os_name][state.selected_browser]
if not components then
utils.warn(
Expand Down Expand Up @@ -147,4 +147,4 @@ function google_chrome.collect_bookmarks(state)
return parse_bookmarks_data(data)
end

return google_chrome
return chrome
6 changes: 3 additions & 3 deletions lua/telescope/_extensions/bookmarks/edge.lua
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
local google_chrome = require "telescope._extensions.bookmarks.google_chrome"
local chrome = require "telescope._extensions.bookmarks.chrome"

local edge = {}

---Collect all the bookmarks for the Microsoft Edge browser.
---Collect all the bookmarks for Microsoft Edge browser.
---NOTE: Microsoft Edge and Google Chrome uses the same underlying format to store bookmarks.
---@param state ConfigState
---@return Bookmark[]|nil
function edge.collect_bookmarks(state)
return google_chrome.collect_bookmarks(state)
return chrome.collect_bookmarks(state)
end

return edge

0 comments on commit b81e3b2

Please sign in to comment.