From d43a4f3b7455599968b9e61c64944ef2759458d6 Mon Sep 17 00:00:00 2001 From: Ariel D'Alessandro Date: Sun, 13 Feb 2022 12:32:19 +0100 Subject: More refactor move telescope to it's own repo and restructure --- lua/alpha/telescope/setup.lua | 172 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 172 insertions(+) create mode 100644 lua/alpha/telescope/setup.lua (limited to 'lua/alpha/telescope/setup.lua') diff --git a/lua/alpha/telescope/setup.lua b/lua/alpha/telescope/setup.lua new file mode 100644 index 0000000..75ddfa9 --- /dev/null +++ b/lua/alpha/telescope/setup.lua @@ -0,0 +1,172 @@ +local actions = require "telescope.actions" +local action_state = require "telescope.actions.state" +local action_layout = require "telescope.actions.layout" + +local set_prompt_to_entry_value = function(prompt_bufnr) + local entry = action_state.get_selected_entry() + if not entry or not type(entry) == "table" then + return + end + + action_state.get_current_picker(prompt_bufnr):reset_prompt(entry.ordinal) +end + +require("telescope").setup { + defaults = { + prompt_prefix = "❯ ", + selection_caret = "❯ ", + + winblend = 0, + + layout_strategy = "horizontal", + layout_config = { + width = 0.95, + height = 0.85, + -- preview_cutoff = 120, + prompt_position = "top", + + horizontal = { + preview_width = function(_, cols, _) + if cols > 200 then + return math.floor(cols * 0.4) + else + return math.floor(cols * 0.6) + end + end, + }, + + vertical = { + width = 0.9, + height = 0.95, + preview_height = 0.5, + }, + + flex = { + horizontal = { + preview_width = 0.9, + }, + }, + }, + + selection_strategy = "reset", + sorting_strategy = "descending", + scroll_strategy = "cycle", + color_devicons = true, + + mappings = { + i = { + [""] = false, + [""] = actions.select_horizontal, + [""] = "move_selection_next", + + [""] = set_prompt_to_entry_value, + + -- These are new :) + [""] = action_layout.toggle_preview, + [""] = action_layout.toggle_mirror, + -- [""] = action_layout.toggle_prompt_position, + + -- [""] = actions.master_stack, + + -- [""] = actions.send_to_qflist + actions.open_qflist, + -- [""] = actions.send_selected_to_qflist + actions.open_qflist, + + -- This is nicer when used with smart-history plugin. + [""] = actions.cycle_history_next, + [""] = actions.cycle_history_prev, + + [""] = function(prompt_bufnr) + local opts = { + callback = actions.toggle_selection, + loop_callback = actions.send_selected_to_qflist, + } + require("telescope").extensions.hop._hop_loop(prompt_bufnr, opts) + end, + + [""] = function() + vim.api.nvim_input "" + end, + }, + }, + + -- borderchars = { "─", "│", "─", "│", "╭", "╮", "╯", "╰" }, + -- file_ignore_patterns = nil, + + file_previewer = require("telescope.previewers").vim_buffer_cat.new, + grep_previewer = require("telescope.previewers").vim_buffer_vimgrep.new, + qflist_previewer = require("telescope.previewers").vim_buffer_qflist.new, + + history = { + path = "~/.local/share/nvim/databases/telescope_history.sqlite3", + limit = 100, + }, + }, + + pickers = { + fd = { + mappings = { + n = { + ["kj"] = "close", + }, + }, + }, + + git_branches = { + mappings = { + i = { + [""] = false, + }, + }, + }, + }, + + extensions = { + fzy_native = { + override_generic_sorter = true, + override_file_sorter = true, + }, + + fzf_writer = { + use_highlighter = false, + minimum_grep_characters = 6, + }, + + hop = { + -- keys define your hop keys in order; defaults to roughly lower- and uppercased home row + keys = { "a", "s", "d", "f", "g", "h", "j", "k", "l", ";" }, -- ... and more + + -- Highlight groups to link to signs and lines; the below configuration refers to demo + -- sign_hl typically only defines foreground to possibly be combined with line_hl + sign_hl = { "WarningMsg", "Title" }, + + -- optional, typically a table of two highlight groups that are alternated between + line_hl = { "CursorLine", "Normal" }, + + -- options specific to `hop_loop` + -- true temporarily disables Telescope selection highlighting + clear_selection_hl = false, + -- highlight hopped to entry with telescope selection highlight + -- note: mutually exclusive with `clear_selection_hl` + trace_entry = true, + -- jump to entry where hoop loop was started from + reset_selection = true, + }, + + ["ui-select"] = { + require("telescope.themes").get_dropdown { + -- even more opts + }, + }, + }, +} +_ = require("telescope").load_extension "dap" +_ = require("telescope").load_extension "notify" +_ = require("telescope").load_extension "file_browser" +_ = require("telescope").load_extension "ui-select" +_ = require("telescope").load_extension "fzf" +_ = require("telescope").load_extension "git_worktree" +-- _ = require("telescope").load_extension "neoclip" +-- _ = require("telescope").load_extension "frecency" +-- _ = require("telescope").load_extension "smart_history" +_ = require("telescope").load_extension "projectionist" +_ = require("telescope").load_extension "laravel" -- cgit v1.2.3