diff --git a/lua/custom/mappings.lua b/lua/custom/mappings.lua new file mode 100644 index 00000000..fb9d2fe7 --- /dev/null +++ b/lua/custom/mappings.lua @@ -0,0 +1,48 @@ +local utils = require 'custom.utils' + +vim.keymap.set('n', 'yn', function() + local filename = vim.fn.expand '%:t' + vim.fn.setreg('+', filename) +end, { desc = '[Y]ank file [N]ame' }) + +vim.keymap.set('n', 'yp', function() + local filepath = vim.fn.expand '%:p' + vim.fn.setreg('+', filepath) +end, { desc = '[Y]ank file [P]ame' }) + +vim.keymap.set('n', 'ys', function() + local filepath = vim.fn.expand '%:p' + local filename = vim.fn.expand '%:t' + local modify = vim.fn.fnamemodify + + local vals = { + ['BASENAME'] = modify(filename, ':r'), + ['EXTENSION'] = modify(filename, ':e'), + ['FILENAME'] = filename, + ['PATH (CWD)'] = modify(filepath, ':.'), + ['PATH (HOME)'] = modify(filepath, ':~'), + ['PATH'] = filepath, + ['URI'] = vim.uri_from_fname(filepath), + } + + local options = vim.tbl_filter(function(val) + return vals[val] ~= '' + end, vim.tbl_keys(vals)) + if vim.tbl_isempty(options) then + utils.notify('No values to copy', vim.log.levels.WARN) + return + end + table.sort(options) + vim.ui.select(options, { + prompt = 'Choose to copy to clipboard:', + format_item = function(item) + return ('%s: %s'):format(item, vals[item]) + end, + }, function(choice) + local result = vals[choice] + if result then + utils.notify(('Copied: `%s`'):format(result)) + vim.fn.setreg('+', result) + end + end) +end, { desc = '[Y]ank [S]elector' }) diff --git a/lua/custom/plugins/init.lua b/lua/custom/plugins/init.lua index 9aee54a7..4cec4d80 100644 --- a/lua/custom/plugins/init.lua +++ b/lua/custom/plugins/init.lua @@ -5,6 +5,7 @@ vim.opt.relativenumber = true vim.g.have_nerd_font = true +require 'custom.mappings' require('lazy').setup { require 'kickstart.plugins.indent_line', require 'kickstart.plugins.autopairs', diff --git a/lua/custom/plugins/neo-tree.lua b/lua/custom/plugins/neo-tree.lua index 3a94de58..dd194198 100644 --- a/lua/custom/plugins/neo-tree.lua +++ b/lua/custom/plugins/neo-tree.lua @@ -77,7 +77,6 @@ return { local filepath = node:get_id() local filename = node.name local modify = vim.fn.fnamemodify - local vals = { ['BASENAME'] = modify(filename, ':r'), ['EXTENSION'] = modify(filename, ':e'),