Compare commits

...

2 Commits

Author SHA1 Message Date
0872808b7a
refactor(hm/price): use z.lua via home manager not zsh
All checks were successful
Check Formatting of Files / Check-Formatting (push) Successful in 1m35s
2024-09-07 13:35:51 -05:00
17738caeb4
refactor(nvim): extract Z cmd to plugin 2024-09-07 13:34:40 -05:00
6 changed files with 25 additions and 97 deletions

3
.gitmodules vendored
View File

@ -10,9 +10,6 @@
[submodule "dots/.config/zsh/config/plugins/fzf-tab"]
path = users/price/dots/.config/zsh/config/plugins/fzf-tab
url = https://github.com/Aloxaf/fzf-tab.git
[submodule "dots/.config/zsh/config/plugins/z.lua"]
path = users/price/dots/.config/zsh/config/plugins/z.lua
url = https://github.com/skywind3000/z.lua.git
[submodule "dots/.config/zsh/config/plugins/nix-zsh-completions"]
path = users/price/dots/.config/zsh/config/plugins/nix-zsh-completions
url = https://github.com/spwhitt/nix-zsh-completions

View File

@ -1,13 +1,22 @@
{ config, ... }:
{
programs.zsh = {
enable = true;
enableCompletion = true;
initExtra = builtins.readFile ./init-extra.zsh;
completionInit =
let
zsh-cache-dir = "${config.xdg.cacheHome}/zsh";
in
"mkdir -p ${zsh-cache-dir} && autoload -U compinit && compinit -d ${zsh-cache-dir}/zcompdump-$ZSH_VERSION";
programs = {
z-lua = {
enable = true;
options = [
"enhanced"
"once"
];
};
zsh = {
enable = true;
enableCompletion = true;
initExtra = builtins.readFile ./init-extra.zsh;
completionInit =
let
zsh-cache-dir = "${config.xdg.cacheHome}/zsh";
in
"mkdir -p ${zsh-cache-dir} && autoload -U compinit && compinit -d ${zsh-cache-dir}/zcompdump-$ZSH_VERSION";
};
};
}

View File

@ -120,87 +120,6 @@ M.setup = function()
nargs = "*",
desc = "Create tempfile and cd to its directory",
})
local config_home = vim.env.XDG_CONFIG_HOME or vim.env.HOME .. "/.config"
local z_lua_path = config_home .. "/zsh/config/plugins/z.lua/z.lua"
local cached_z_listing = {}
vim.api.nvim_create_user_command("Z", function(opts)
cached_z_listing = {}
local cmd = { "lua", z_lua_path, "-e", opts.args }
local cmd_out = vim.system(cmd, { text = true, env = { _ZL_MATCH_MODE = "1", PWD = tostring(vim.uv.cwd()) } })
:wait()
if cmd_out.code > 0 then
vim.notify(
"Failed with code `" .. cmd_out.code .. "`\nSTDERR: " .. (cmd_out.stderr or ""),
vim.log.levels.WARN,
{
title = "z.lua",
---@param win integer The window handle
on_open = function(win)
vim.api.nvim_set_option_value("filetype", "markdown", { buf = vim.api.nvim_win_get_buf(win) })
end,
}
)
elseif cmd_out.stdout == "" then
vim.notify("Did not receive a match from `z.lua`!", vim.log.levels.WARN, {
title = "z.lua",
---@param win integer The window handle
on_open = function(win)
vim.api.nvim_set_option_value("filetype", "markdown", { buf = vim.api.nvim_win_get_buf(win) })
end,
})
else
local stripped_stdout = cmd_out.stdout:gsub("\n$", "")
vim.cmd("silent! cd " .. stripped_stdout)
vim.notify("Chdir to `" .. stripped_stdout .. "`", vim.log.levels.INFO, {
title = "z.lua",
---@param win integer The window handle
on_open = function(win)
vim.api.nvim_set_option_value("filetype", "markdown", { buf = vim.api.nvim_win_get_buf(win) })
end,
})
end
end, {
nargs = "+",
complete = function(_, _, _)
local cmd = { "lua", z_lua_path, "--complete" }
local cmd_out
if #cached_z_listing == 0 then
cmd_out = vim.system(cmd, { text = true }):wait()
if cmd_out.code == 0 and cmd_out.stdout then
cached_z_listing = vim.split(cmd_out.stdout, "\n")
end
end
return cached_z_listing
end,
desc = "Invoke `z.lua`",
})
vim.api.nvim_create_autocmd("DirChanged", {
callback = function(args)
vim.system({ "lua", z_lua_path, "--add", args.file }, { text = true }, function(out)
if out.code ~= 0 then
vim.notify(
"Failed to regiser directory with `z.lua`!\n====STDERR====\n"
.. out.stderr
.. "\n====STDOUT====\n"
.. out.stdout,
vim.log.levels.WARN,
{
title = "z.lua",
on_open = function(win)
vim.api.nvim_set_option_value(
"filetype",
"markdown",
{ buf = vim.api.nvim_win_get_buf(win) }
)
end,
}
)
end
end)
end,
})
end
return M

View File

@ -0,0 +1,7 @@
return {
{
"PriceHiller/z.nvim",
cmd = { "Z" },
config = true,
},
}

View File

@ -17,9 +17,6 @@ init() {
FPATH="${FPATH}:${wkdir}/nix-zsh-completions"
export _ZL_DATA="${_ZL_DATA:-"$XDG_CACHE_HOME/zlua"}"
eval "$(lua "${wkdir}/z.lua/z.lua" --init zsh enhanced once)"
[[ -r "${XDG_CONFIG_HOME}/fzf/fzf.zsh" ]] && source "${XDG_CONFIG_HOME}/fzf/fzf.zsh"
configure

@ -1 +0,0 @@
Subproject commit 30220996cae675f9ec12fc3aeb2b5c3d957af8c8