Skip to content

Commit

Permalink
🔧 (mini.files): some cool keybinds in found in @linkarzu's video
Browse files Browse the repository at this point in the history
  • Loading branch information
elythh committed Dec 1, 2024
1 parent 690caf7 commit f178b48
Showing 1 changed file with 48 additions and 4 deletions.
52 changes: 48 additions & 4 deletions config/plug/mini/files.nix
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
preview = true;
width_preview = 100;
};
mappings =
{
};
mappings = {
synchronize = "s";
};
};
keymaps = lib.mkIf (config.plugins.mini.enable && lib.hasAttr "files" config.plugins.mini.modules) [
{
Expand All @@ -34,6 +34,50 @@
silent = true;
};
}
{
mode = "n";
key = "<M-c>";
action.__raw = ''
function()
local curr_entry = MiniFiles.get_fs_entry()
if curr_entry then
-- Convert path to be relative to home directory
local home_dir = vim.fn.expand("~")
local relative_path = curr_entry.path:gsub("^" .. home_dir, "~")
vim.fn.setreg("+", relative_path) -- Copy the relative path to the clipboard register
vim.notify(relative_path, vim.log.levels.INFO)
vim.notify("Path copied to clipboard: ", vim.log.levels.INFO)
else
vim.notify("No file or directory selected", vim.log.levels.WARN)
end
end
'';
}
{
mode = "n";
key = "<M-C>";
action.__raw = ''
function()
-- Get the current entry (file or directory)
local curr_entry = MiniFiles.get_fs_entry()
if curr_entry then
local path = curr_entry.path
-- Escape the path for shell command
local escaped_path = vim.fn.fnameescape(path)
-- Build the osascript command to copy the file or directory to the clipboard
local cmd = string.format([[cat %s | wl-copy ]], escaped_path)
local result = vim.fn.system(cmd)
if vim.v.shell_error ~= 0 then
vim.notify("Copy failed: " .. result, vim.log.levels.ERROR)
else
vim.notify(path, vim.log.levels.INFO)
vim.notify("Copied to system clipboard", vim.log.levels.INFO)
end
else
vim.notify("No file or directory selected", vim.log.levels.WARN)
end
end
'';
}
];

}

2 comments on commit f178b48

@linkarzu
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My mini.files config was updated some days ago, I fixed a few things and re-organized stuff, you should check it out!

@elythh
Copy link
Owner Author

@elythh elythh commented on f178b48 Dec 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for the notice ! 😄

Please sign in to comment.