Skip to content

Commit

Permalink
fix: yazi settings
Browse files Browse the repository at this point in the history
  • Loading branch information
shubham-cpp committed Jan 3, 2025
1 parent 10a12f4 commit 3c76515
Show file tree
Hide file tree
Showing 8 changed files with 266 additions and 14 deletions.
3 changes: 1 addition & 2 deletions .config/lazygit/state.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
lastupdatecheck: 0
recentrepos:
- /home/shubham/Documents/Programming/WebDev/temp-app
- /home/shubham/Documents/dotfiles
- /home/shubham/Documents/Programming/WebDev/social-media-manager-app
- /home/shubham/Documents/Programming/WebDev/invoice-genrator-nextjs
- /home/shubham/Documents/Programming/WebDev/invoice-generator-sveltekit
- /home/shubham/Documents/Programming/WebDev/vue3-chrome-ai
- /home/shubham/Documents/Programming/WebDev/demo-shadcn
- /home/shubham/Downloads/GitClones/srcbook
- /home/shubham/Documents/Programming/WebDev/page-form
- /home/shubham/Documents/Programming/WebDev/discord-clone
- /home/shubham/Downloads/GitClones/lfimg
startuppopupversion: 5
lastversion: 0.44.1
Expand Down
1 change: 1 addition & 0 deletions .config/nvim/lua/plugins/conform.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ return {
vim.o.formatexpr = "v:lua.require'conform'.formatexpr()"
end,
config = function()
vim.env.ESLINT_D_PPID = vim.fn.getpid()
local prettier = { 'prettierd', 'prettier', stop_after_first = true }
local slow_format_filetypes = {}

Expand Down
15 changes: 14 additions & 1 deletion .config/nvim/lua/plugins/lsp/typescript.lua
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,20 @@ return {
handlers = {
tsserver = false,
ts_ls = false,
eslint = false,
eslint = function(server, opts)
local default_attach = opts.on_attach
opts.on_attach = function(client, bufnr)
default_attach(client, bufnr)
vim.api.nvim_create_autocmd('BufWritePre', {
buffer = bufnr,
desc = 'Run Eslint fix before save',
callback = function()
vim.cmd 'EslintFixAll'
end,
})
end
require('lspconfig')[server].setup(opts)
end,
vtsls = function(server, opts)
require('lspconfig.configs').vtsls = require('vtsls').lspconfig
local default_attach = opts.on_attach
Expand Down
15 changes: 8 additions & 7 deletions .config/nvim/lua/plugins/nvim-lint.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ local languages = {
sass = { 'stylelint', 'cspell' },
less = { 'stylelint', 'cspell' },
python = { 'ruff', 'cspell' },
astro = { 'eslint_d', 'cspell' },
svelte = { 'eslint_d', 'cspell' },
javascript = { 'eslint_d', 'cspell' },
javascriptreact = { 'eslint_d', 'cspell' },
typescript = { 'eslint_d', 'cspell' },
typescriptreact = { 'eslint_d', 'cspell' },
vue = { 'eslint_d', 'cspell' },
astro = { 'cspell' },
svelte = { 'cspell' },
javascript = { 'cspell' },
javascriptreact = { 'cspell' },
typescript = { 'cspell' },
typescriptreact = { 'cspell' },
vue = { 'cspell' },
yaml = { 'yamllint', 'cspell' },
php = { 'php', 'phpstan', 'phpcs', 'cspell' },
}
Expand Down Expand Up @@ -59,6 +59,7 @@ return {
ft = vim.tbl_keys(languages),
config = function(_, opts)
local lint = require 'lint'
vim.env.ESLINT_D_PPID = vim.fn.getpid()
languages = vim.tbl_deep_extend('force', languages, opts.languages or {})
linters = vim.tbl_deep_extend('force', linters, opts.linters or {})

Expand Down
7 changes: 6 additions & 1 deletion .config/yazi/keymap.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,10 @@ prepend_keymap = [
{ on= ["g","l","f"],run="cd ~/.local/share/fonts", desc = "Goto fonts" },
{ on= ["g","l","t"],run="cd ~/.local/share/Trash/files", desc = "Goto Trash" },

{ on = [ "l" ], run = 'plugin --sync smart-enter', desc = "Enter the child directory, or open the file" },
{ on = [ "l" ], run = 'plugin smart-enter', desc = "Enter the child directory, or open the file" },
{ on = [ "c", "a" ], run = "plugin compress", desc = "Archive selected files" }
]
append_keymap = [
{ on = "<Space>", run = "toggle" },
{ on = "<C-a>", run = "toggle_all --state=on" },
]
228 changes: 228 additions & 0 deletions .config/yazi/plugins/compress.yazi/init.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,228 @@
-- Send error notification
local function notify_error(message, urgency)
ya.notify({
title = "Archive",
content = message,
level = urgency,
timeout = 5,
})
end

-- Check for windows
local is_windows = ya.target_family() == "windows"

-- Make table of selected or hovered: path = filenames
local selected_or_hovered = ya.sync(function()
local tab, paths, names, path_fnames = cx.active, {}, {}, {}
for _, u in pairs(tab.selected) do
paths[#paths + 1] = tostring(u:parent())
names[#names + 1] = tostring(u:name())
end
if #paths == 0 and tab.current.hovered then
paths[1] = tostring(tab.current.hovered.url:parent())
names[1] = tostring(tab.current.hovered.name)
end
for idx, name in ipairs(names) do
if not path_fnames[paths[idx]] then
path_fnames[paths[idx]] = {}
end
table.insert(path_fnames[paths[idx]], name)
end
return path_fnames, tostring(tab.current.cwd)
end)

-- Check if archive command is available
local function is_command_available(cmd)
local stat_cmd

if is_windows then
stat_cmd = string.format("where %s > nul 2>&1", cmd)
else
stat_cmd = string.format("command -v %s >/dev/null 2>&1", cmd)
end

local cmd_exists = os.execute(stat_cmd)
if cmd_exists then
return true
else
return false
end
end

-- Archive command list --> string
local function find_binary(cmd_list)
for _, cmd in ipairs(cmd_list) do
if is_command_available(cmd) then
return cmd
end
end
return cmd_list[1] -- Return first command as fallback
end

-- Check if file exists
local function file_exists(name)
local f = io.open(name, "r")
if f ~= nil then
io.close(f)
return true
else
return false
end
end

-- Append filename to it's parent directory
local function combine_url(path, file)
path, file = Url(path), Url(file)
return tostring(path:join(file))
end

return {
entry = function()
-- Exit visual mode
ya.manager_emit("escape", { visual = true })

-- Define file table and output_dir (pwd)
local path_fnames, output_dir = selected_or_hovered()

-- Get input
local output_name, event = ya.input({
title = "Create archive:",
position = { "top-center", y = 3, w = 40 },
})
if event ~= 1 then
return
end

-- Use appropriate archive command
local archive_commands = {
["%.zip$"] = { command = "zip", args = { "-r" } },
["%.7z$"] = { command = { "7z", "7zz" }, args = { "a" } },
["%.tar.gz$"] = { command = "tar", args = { "rpf" }, compress = "gzip" },
["%.tar.xz$"] = { command = "tar", args = { "rpf" }, compress = "xz" },
["%.tar.bz2$"] = { command = "tar", args = { "rpf" }, compress = "bzip2" },
["%.tar.zst$"] = { command = "tar", args = { "rpf" }, compress = "zstd", compress_args = { "--rm" } },
["%.tar$"] = { command = "tar", args = { "rpf" } },
}

if is_windows then
archive_commands = {
["%.zip$"] = { command = "7z", args = { "a", "-tzip" } },
["%.7z$"] = { command = "7z", args = { "a" } },
["%.tar.gz$"] = {
command = "tar",
args = { "rpf" },
compress = "7z",
compress_args = { "a", "-tgzip", "-sdel", output_name },
},
["%.tar.xz$"] = {
command = "tar",
args = { "rpf" },
compress = "7z",
compress_args = { "a", "-txz", "-sdel", output_name },
},
["%.tar.bz2$"] = {
command = "tar",
args = { "rpf" },
compress = "7z",
compress_args = { "a", "-tbzip2", "-sdel", output_name },
},
["%.tar.zst$"] = { command = "tar", args = { "rpf" }, compress = "zstd", compress_args = { "--rm" } },
["%.tar$"] = { command = "tar", args = { "rpf" } },
}
end

-- Match user input to archive command
local archive_cmd, archive_args, archive_compress, archive_compress_args
for pattern, cmd_pair in pairs(archive_commands) do
if output_name:match(pattern) then
archive_cmd = cmd_pair.command
archive_args = cmd_pair.args
archive_compress = cmd_pair.compress
archive_compress_args = cmd_pair.compress_args or {}
end
end

-- Check if archive command has multiple names
if type(archive_cmd) == "table" then
archive_cmd = find_binary(archive_cmd)
end

-- Check if no archive command is available for the extention
if not archive_cmd then
notify_error("Unsupported file extention", "error")
return
end

-- Exit if archive command is not available
if not is_command_available(archive_cmd) then
notify_error(string.format("%s not available", archive_cmd), "error")
return
end

-- Exit if compress command is not available
if archive_compress and not is_command_available(archive_compress) then
notify_error(string.format("%s compression not available", archive_compress), "error")
return
end

-- If file exists show overwrite prompt
local output_url = combine_url(output_dir, output_name)
while true do
if file_exists(output_url) then
local overwrite_answer = ya.input({
title = "Overwrite " .. output_name .. "? y/N:",
position = { "top-center", y = 3, w = 40 },
})
if overwrite_answer:lower() ~= "y" then
notify_error("Operation canceled", "warn")
return -- If no overwrite selected, exit
else
local rm_status, rm_err = os.remove(output_url)
if not rm_status then
notify_error(string.format("Failed to remove %s, exit code %s", output_name, rm_err), "error")
return
end -- If overwrite fails, exit
end
end
if archive_compress and not output_name:match("%.tar$") then
output_name = output_name:match("(.*%.tar)") -- Test for .tar and .tar.*
output_url = combine_url(output_dir, output_name) -- Update output_url
else
break
end
end

-- Add to output archive in each path, their respective files
for path, names in pairs(path_fnames) do
local archive_status, archive_err =
Command(archive_cmd):args(archive_args):arg(output_url):args(names):cwd(path):spawn():wait()
if not archive_status or not archive_status.success then
notify_error(
string.format(
"%s with selected files failed, exit code %s",
archive_args,
archive_status and archive_status.code or archive_err
),
"error"
)
end
end

-- Use compress command if needed
if archive_compress then
local compress_status, compress_err =
Command(archive_compress):args(archive_compress_args):arg(output_name):cwd(output_dir):spawn():wait()
if not compress_status or not compress_status.success then
notify_error(
string.format(
"%s with %s failed, exit code %s",
archive_compress,
output_name,
compress_status and compress_status.code or compress_err
),
"error"
)
end
end
end,
}
1 change: 1 addition & 0 deletions .config/yazi/plugins/smart-enter.yazi/init.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
--- @sync entry
return {
entry = function()
local h = cx.active.current.hovered
Expand Down
10 changes: 7 additions & 3 deletions .config/yazi/yazi.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ show_hidden = true
show_symlink = true
scrolloff = 12

[opener]
archive = [
{ run = 'atool -x "$1"', desc = "Extract here" },
[open]
append_rules = [
{ name = "application/zip", use = "plugin archive" },
{ name = "application/x-tar", use = "plugin archive" },
{ name = "application/x-archive", use = "plugin archive" },
{ name = "application/x-archive", use = "plugin archive" },
{ name = "application/x-xz", use = "plugin archive" },
]

0 comments on commit 3c76515

Please sign in to comment.