From 0dfeb542fef99ee1a35cc0dc58ec5b18fd279c2e Mon Sep 17 00:00:00 2001 From: Oliver Davies Date: Wed, 17 Nov 2021 12:00:00 +0000 Subject: [PATCH] feat(nvim): telescope configuration --- nvim/.config/nvim/after/plugin/telescope.lua | 32 ++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/nvim/.config/nvim/after/plugin/telescope.lua b/nvim/.config/nvim/after/plugin/telescope.lua index ccbb77a..fb2378b 100644 --- a/nvim/.config/nvim/after/plugin/telescope.lua +++ b/nvim/.config/nvim/after/plugin/telescope.lua @@ -1,3 +1,35 @@ +local previewers = require('telescope.previewers') +local Job = require('plenary.job') + +-- Create a new maker that won't preview binary files +-- https://github.com/nvim-telescope/telescope.nvim/wiki/Configuration-Recipes#dont-preview-binaries +local new_maker = function(filepath, bufnr, opts) + filepath = vim.fn.expand(filepath) + Job:new({ + command = 'file', + args = { '--mime-type', '-b', filepath }, + on_exit = function(j) + local mime_type = vim.split(j:result()[1], '/')[1] + if mime_type == "text" then + previewers.buffer_previewer_maker(filepath, bufnr, opts) + else + vim.schedule(function() + vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, { 'BINARY' }) + end) + end + end + }):sync() +end + +require "telescope".setup{ + defaults = { + buffer_previewer_maker = new_maker, + prompt_prefix = "$ " + } +} + +require "telescope".load_extension("fzf") + local map = vim.api.nvim_set_keymap local options = {