From c27e4373d193a45ba0523d477d444bb21b2fc2c6 Mon Sep 17 00:00:00 2001 From: Jeff LANCE Date: Wed, 20 Jul 2022 00:58:49 +0200 Subject: [PATCH] Update --- conf.d/nvim/dashboard.lua | 26 +++++++++++++++--- conf.d/nvim/functions.vim | 8 +++--- conf.d/nvim/init.vim | 9 +++++++ conf.d/nvim/keybindings.vim | 20 +++++++------- conf.d/nvim/telescope.lua | 53 +++++++++++++++++++++++++++++++++++++ 5 files changed, 99 insertions(+), 17 deletions(-) create mode 100644 conf.d/nvim/telescope.lua diff --git a/conf.d/nvim/dashboard.lua b/conf.d/nvim/dashboard.lua index a5df7d0..20e2a6b 100644 --- a/conf.d/nvim/dashboard.lua +++ b/conf.d/nvim/dashboard.lua @@ -21,6 +21,25 @@ local db = require('dashboard') local dotfiles = home .. '/dotfiles' +db.custom_header = { + '', + ' ⣿⣿⣷⡁⢆⠈⠕⢕⢂⢕⢂⢕⢂⢔⢂⢕⢄⠂⣂⠂⠆⢂⢕⢂⢕⢂⢕⢂⢕⢂ ', + ' ⣿⣿⣿⡷⠊⡢⡹⣦⡑⢂⢕⢂⢕⢂⢕⢂⠕⠔⠌⠝⠛⠶⠶⢶⣦⣄⢂⢕⢂⢕ ', + ' ⣿⣿⠏⣠⣾⣦⡐⢌⢿⣷⣦⣅⡑⠕⠡⠐⢿⠿⣛⠟⠛⠛⠛⠛⠡⢷⡈⢂⢕⢂ ', + ' ⠟⣡⣾⣿⣿⣿⣿⣦⣑⠝⢿⣿⣿⣿⣿⣿⡵⢁⣤⣶⣶⣿⢿⢿⢿⡟⢻⣤⢑⢂ ', + ' ⣾⣿⣿⡿⢟⣛⣻⣿⣿⣿⣦⣬⣙⣻⣿⣿⣷⣿⣿⢟⢝⢕⢕⢕⢕⢽⣿⣿⣷⣔ ', + ' ⣿⣿⠵⠚⠉⢀⣀⣀⣈⣿⣿⣿⣿⣿⣿⣿⣿⣿⣗⢕⢕⢕⢕⢕⢕⣽⣿⣿⣿⣿ ', + ' ⢷⣂⣠⣴⣾⡿⡿⡻⡻⣿⣿⣴⣿⣿⣿⣿⣿⣿⣷⣵⣵⣵⣷⣿⣿⣿⣿⣿⣿⡿ ', + ' ⢌⠻⣿⡿⡫⡪⡪⡪⡪⣺⣿⣿⣿⣿⣿⠿⠿⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠃ ', + ' ⠣⡁⠹⡪⡪⡪⡪⣪⣾⣿⣿⣿⣿⠋⠐⢉⢍⢄⢌⠻⣿⣿⣿⣿⣿⣿⣿⣿⠏⠈ ', + ' ⡣⡘⢄⠙⣾⣾⣾⣿⣿⣿⣿⣿⣿⡀⢐⢕⢕⢕⢕⢕⡘⣿⣿⣿⣿⣿⣿⠏⠠⠈ ', + ' ⠌⢊⢂⢣⠹⣿⣿⣿⣿⣿⣿⣿⣿⣧⢐⢕⢕⢕⢕⢕⢅⣿⣿⣿⣿⡿⢋⢜⠠⠈ ', + ' ⠄⠁⠕⢝⡢⠈⠻⣿⣿⣿⣿⣿⣿⣿⣷⣕⣑⣑⣑⣵⣿⣿⣿⡿⢋⢔⢕⣿⠠⠈ ', + ' ⠨⡂⡀⢑⢕⡅⠂⠄⠉⠛⠻⠿⢿⣿⣿⣿⣿⣿⣿⣿⣿⡿⢋⢔⢕⢕⣿⣿⠠⠈ ', + ' ⠄⠪⣂⠁⢕⠆⠄⠂⠄⠁⡀⠂⡀⠄⢈⠉⢍⢛⢛⢛⢋⢔⢕⢕⢕⣽⣿⣿⠠⠈ ', + '', +} + db.custom_center = { { icon = nil, @@ -35,15 +54,14 @@ db.custom_center = { }, { desc = 'Fichiers récemment ouverts ', - action = 'DashboardFindHistory', + action = "lua require('telescope.builtin').oldfiles()", shortcut = 'SPC f h' }, { desc = 'Parcourir les dotfiles ', - action = "lua require('telescope.builtin').find_files({" .. dotfiles .. "})", - -- action = 'Telescope dotfiles path=' .. home .. '/dotfiles', + action = "lua require('telescope.builtin').find_files({ cwd = \'" .. dotfiles .. "\' })", shortcut = 'SPC f d' - } + }, } -- Highlight Group diff --git a/conf.d/nvim/functions.vim b/conf.d/nvim/functions.vim index c86cb0c..9102152 100644 --- a/conf.d/nvim/functions.vim +++ b/conf.d/nvim/functions.vim @@ -72,13 +72,13 @@ endfunction " Close current buffer -" If the last buffer is closed go back to Startify -function! BufClose() +" If the last buffer is closed go back to startup screen +function! CloseBuffer() if (CountBuffers() == 1 || IsExplorerBuffer() || IsEmptyBuffer()) - bwipeout + bwipeout! Dashboard else - bwipeout + bwipeout! endif endfunction diff --git a/conf.d/nvim/init.vim b/conf.d/nvim/init.vim index dfa5ab4..7ba259a 100644 --- a/conf.d/nvim/init.vim +++ b/conf.d/nvim/init.vim @@ -688,6 +688,15 @@ let g:suda_smart_edit = 1 " }}} +" Telescope {{{ +" ----- + +source $HOME/.config/nvim/telescope.lua + +" ----- +" }}} + + " Tmuxline {{{ " ----- diff --git a/conf.d/nvim/keybindings.vim b/conf.d/nvim/keybindings.vim index f8530ea..d73a886 100644 --- a/conf.d/nvim/keybindings.vim +++ b/conf.d/nvim/keybindings.vim @@ -54,15 +54,17 @@ map :saveas " Buffers {{{ " ----- -command! -bang -nargs=? -complete=dir Files - \ call fzf#vim#files( - \ , - \ fzf#vim#with_preview( - \ {'options': ['--layout=reverse', '--info=inline']} - \ ), - \ 0 - \ ) -map :echom 'Close buffer' :call BufClose() +" command! -bang -nargs=? -complete=dir Files +" \ call fzf#vim#files( +" \ , +" \ fzf#vim#with_preview( +" \ {'options': ['--layout=reverse', '--info=inline']} +" \ ), +" \ 0 +" \ ) +command -bang CloseBuffer :call CloseBuffer() + +map :echom 'Close buffer' :CloseBuffer! map :e map :DashboardNewFile map :bn diff --git a/conf.d/nvim/telescope.lua b/conf.d/nvim/telescope.lua new file mode 100644 index 0000000..8a6c85e --- /dev/null +++ b/conf.d/nvim/telescope.lua @@ -0,0 +1,53 @@ +local previewers = require("telescope.previewers") +local Job = require("plenary.job") +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 + -- maybe we want to write something to the buffer here + vim.schedule(function() + vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, { "BINARY" }) + end) + end + end + }):sync() +end + +require("telescope").setup { + defaults = { + preview = { + mime_hook = function(filepath, bufnr, opts) + local is_image = function(filepath) + local image_extensions = {'png','jpg'} -- Supported image formats + local split_path = vim.split(filepath:lower(), '.', {plain=true}) + local extension = split_path[#split_path] + return vim.tbl_contains(image_extensions, extension) + end + if is_image(filepath) then + local term = vim.api.nvim_open_term(bufnr, {}) + local function send_output(_, data, _ ) + for _, d in ipairs(data) do + vim.api.nvim_chan_send(term, d..'\r\n') + end + end + vim.fn.jobstart( + { + 'catimg', filepath -- Terminal image viewer command + }, + {on_stdout=send_output, stdout_buffered=true}) + else + require("telescope.previewers.utils").set_preview_message(bufnr, opts.winid, "Binary cannot be previewed") + end + end + }, + buffer_previewer_maker = new_maker, + } +} + +