mirror of
https://github.com/harivansh-afk/nix.git
synced 2026-04-15 05:02:10 +00:00
fzf
This commit is contained in:
parent
ac7a2c4811
commit
e1550559e3
9 changed files with 132 additions and 68 deletions
24
config/nvim/lua/config/fzf_reload.lua
Normal file
24
config/nvim/lua/config/fzf_reload.lua
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
local M = {}
|
||||
M.opts = nil
|
||||
|
||||
function M.setup(opts) M.opts = vim.deepcopy(opts or {}) end
|
||||
|
||||
function M.reload()
|
||||
local path = vim.env.FZF_DEFAULT_OPTS_FILE or vim.fn.expand "~/.config/fzf/themes/theme"
|
||||
if vim.fn.filereadable(path) == 0 then return end
|
||||
|
||||
local lines = vim.fn.readfile(path)
|
||||
if not lines or #lines == 0 or not M.opts then return end
|
||||
|
||||
local colors = {}
|
||||
for color_spec in table.concat(lines, "\n"):gmatch "%-%-color=([^%s]+)" do
|
||||
for key, value in color_spec:gmatch "([^:,]+):([^,]+)" do
|
||||
colors[key] = value
|
||||
end
|
||||
end
|
||||
|
||||
M.opts.fzf_colors = colors
|
||||
require("fzf-lua").setup(M.opts)
|
||||
end
|
||||
|
||||
return M
|
||||
|
|
@ -1,74 +1,76 @@
|
|||
---@param kind 'issue'|'pr'
|
||||
---@param state 'all'|'open'|'closed'
|
||||
local function gh_picker(kind, state)
|
||||
if vim.fn.executable('gh') ~= 1 then
|
||||
vim.notify('gh CLI not found', vim.log.levels.WARN)
|
||||
return
|
||||
end
|
||||
local next_state = ({ all = 'open', open = 'closed', closed = 'all' })[state]
|
||||
local label = kind == 'pr' and 'PRs' or 'Issues'
|
||||
require('fzf-lua').fzf_exec(('gh %s list --limit 100 --state %s'):format(kind, state), {
|
||||
prompt = ('%s (%s)> '):format(label, state),
|
||||
header = ':: <c-o> to toggle all/open/closed',
|
||||
actions = {
|
||||
['default'] = function(selected)
|
||||
local num = selected[1]:match('^#?(%d+)')
|
||||
if num then
|
||||
vim.system({ 'gh', kind, 'view', num, '--web' })
|
||||
end
|
||||
end,
|
||||
['ctrl-o'] = function()
|
||||
gh_picker(kind, next_state)
|
||||
end,
|
||||
},
|
||||
})
|
||||
if vim.fn.executable "gh" ~= 1 then
|
||||
vim.notify("gh CLI not found", vim.log.levels.WARN)
|
||||
return
|
||||
end
|
||||
local next_state = ({ all = "open", open = "closed", closed = "all" })[state]
|
||||
local label = kind == "pr" and "PRs" or "Issues"
|
||||
require("fzf-lua").fzf_exec(("gh %s list --limit 100 --state %s"):format(kind, state), {
|
||||
prompt = ("%s (%s)> "):format(label, state),
|
||||
header = ":: <c-o> to toggle all/open/closed",
|
||||
actions = {
|
||||
["default"] = function(selected)
|
||||
local num = selected[1]:match "^#?(%d+)"
|
||||
if num then vim.system { "gh", kind, "view", num, "--web" } end
|
||||
end,
|
||||
["ctrl-o"] = function() gh_picker(kind, next_state) end,
|
||||
},
|
||||
})
|
||||
end
|
||||
|
||||
return {
|
||||
'ibhagwan/fzf-lua',
|
||||
dependencies = { 'nvim-tree/nvim-web-devicons' },
|
||||
config = function(_, opts)
|
||||
require('fzf-lua').setup(opts)
|
||||
"ibhagwan/fzf-lua",
|
||||
dependencies = { "nvim-tree/nvim-web-devicons" },
|
||||
config = function(_, opts)
|
||||
local fzf = require "fzf-lua"
|
||||
fzf.setup(opts)
|
||||
|
||||
map('n', '<C-f>', function()
|
||||
local fzf = require('fzf-lua')
|
||||
local git_dir = vim.fn.system('git rev-parse --git-dir 2>/dev/null'):gsub('\n', '')
|
||||
if vim.v.shell_error == 0 and git_dir ~= '' then
|
||||
fzf.git_files()
|
||||
else
|
||||
fzf.files()
|
||||
end
|
||||
end)
|
||||
map('n', '<leader>ff', '<cmd>FzfLua files<cr>')
|
||||
map('n', '<leader>fg', '<cmd>FzfLua live_grep<cr>')
|
||||
map('n', '<leader>fb', '<cmd>FzfLua buffers<cr>')
|
||||
map('n', '<leader>fh', '<cmd>FzfLua help_tags<cr>')
|
||||
map('n', '<leader>fr', '<cmd>FzfLua resume<cr>')
|
||||
map('n', '<leader>fo', '<cmd>FzfLua oldfiles<cr>')
|
||||
map('n', '<leader>fc', '<cmd>FzfLua commands<cr>')
|
||||
map('n', '<leader>fk', '<cmd>FzfLua keymaps<cr>')
|
||||
map('n', '<leader>f/', '<cmd>FzfLua search_history<cr>')
|
||||
map('n', '<leader>f:', '<cmd>FzfLua command_history<cr>')
|
||||
map('n', '<leader>fe', '<cmd>FzfLua files cwd=~/.config<cr>')
|
||||
map('n', 'gq', '<cmd>FzfLua quickfix<cr>')
|
||||
map('n', 'gl', '<cmd>FzfLua loclist<cr>')
|
||||
map('n', '<leader>GB', '<cmd>FzfLua git_branches<cr>')
|
||||
map('n', '<leader>Gc', '<cmd>FzfLua git_commits<cr>')
|
||||
map('n', '<leader>Gs', '<cmd>FzfLua git_status<cr>')
|
||||
map('n', '<leader>Gp', function() gh_picker('pr', 'open') end)
|
||||
map('n', '<leader>Gi', function() gh_picker('issue', 'open') end)
|
||||
end,
|
||||
opts = {
|
||||
'default-title',
|
||||
winopts = {
|
||||
border = 'single',
|
||||
preview = {
|
||||
layout = 'vertical',
|
||||
vertical = 'down:50%',
|
||||
},
|
||||
},
|
||||
fzf_opts = {
|
||||
['--layout'] = 'reverse',
|
||||
},
|
||||
local ok, fzf_reload = pcall(require, "config.fzf_reload")
|
||||
if ok then
|
||||
fzf_reload.setup(opts)
|
||||
fzf_reload.reload()
|
||||
end
|
||||
|
||||
map("n", "<C-f>", function()
|
||||
local git_dir = vim.fn.system("git rev-parse --git-dir 2>/dev/null"):gsub("\n", "")
|
||||
if vim.v.shell_error == 0 and git_dir ~= "" then
|
||||
fzf.git_files()
|
||||
else
|
||||
fzf.files()
|
||||
end
|
||||
end)
|
||||
map("n", "<leader>ff", "<cmd>FzfLua files<cr>")
|
||||
map("n", "<leader>fg", "<cmd>FzfLua live_grep<cr>")
|
||||
map("n", "<leader>fb", "<cmd>FzfLua buffers<cr>")
|
||||
map("n", "<leader>fh", "<cmd>FzfLua help_tags<cr>")
|
||||
map("n", "<leader>fr", "<cmd>FzfLua resume<cr>")
|
||||
map("n", "<leader>fo", "<cmd>FzfLua oldfiles<cr>")
|
||||
map("n", "<leader>fc", "<cmd>FzfLua commands<cr>")
|
||||
map("n", "<leader>fk", "<cmd>FzfLua keymaps<cr>")
|
||||
map("n", "<leader>f/", "<cmd>FzfLua search_history<cr>")
|
||||
map("n", "<leader>f:", "<cmd>FzfLua command_history<cr>")
|
||||
map("n", "<leader>fe", "<cmd>FzfLua files cwd=~/.config<cr>")
|
||||
map("n", "gq", "<cmd>FzfLua quickfix<cr>")
|
||||
map("n", "gl", "<cmd>FzfLua loclist<cr>")
|
||||
map("n", "<leader>GB", "<cmd>FzfLua git_branches<cr>")
|
||||
map("n", "<leader>Gc", "<cmd>FzfLua git_commits<cr>")
|
||||
map("n", "<leader>Gs", "<cmd>FzfLua git_status<cr>")
|
||||
map("n", "<leader>Gp", function() gh_picker("pr", "open") end)
|
||||
map("n", "<leader>Gi", function() gh_picker("issue", "open") end)
|
||||
end,
|
||||
opts = {
|
||||
"default-title",
|
||||
winopts = {
|
||||
border = "single",
|
||||
preview = {
|
||||
layout = "vertical",
|
||||
vertical = "down:50%",
|
||||
},
|
||||
},
|
||||
fzf_opts = {
|
||||
["--layout"] = "reverse",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
|
|
|||
|
|
@ -71,6 +71,8 @@ function M.apply(mode)
|
|||
|
||||
vim.g.cozybox_theme_mode = next_mode
|
||||
apply_cozybox_overrides()
|
||||
local ok_reload, fzf_reload = pcall(require, "config.fzf_reload")
|
||||
if ok_reload then pcall(fzf_reload.reload) end
|
||||
vim.schedule(function()
|
||||
local ok, lualine = pcall(require, "lualine")
|
||||
if ok then pcall(lualine.refresh, { place = { "statusline" } }) end
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
./bat.nix
|
||||
./claude.nix
|
||||
./codex.nix
|
||||
./fzf.nix
|
||||
./gcloud.nix
|
||||
./gh.nix
|
||||
./ghostty.nix
|
||||
|
|
|
|||
10
home/fzf.nix
Normal file
10
home/fzf.nix
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
{config, ...}: let
|
||||
theme = import ../lib/theme.nix {inherit config;};
|
||||
in {
|
||||
home.sessionVariables = {
|
||||
FZF_DEFAULT_OPTS_FILE = theme.paths.fzfCurrentFile;
|
||||
};
|
||||
|
||||
xdg.configFile."fzf/themes/cozybox-dark".text = theme.renderFzf "dark";
|
||||
xdg.configFile."fzf/themes/cozybox-light".text = theme.renderFzf "light";
|
||||
}
|
||||
|
|
@ -9,7 +9,7 @@ in {
|
|||
home.packages = builtins.attrValues customScripts.packages;
|
||||
|
||||
home.activation.initializeThemeState = lib.hm.dag.entryAfter ["writeBoundary"] ''
|
||||
mkdir -p "${customScripts.theme.paths.stateDir}" "${customScripts.theme.paths.ghosttyDir}" "${customScripts.theme.paths.tmuxDir}"
|
||||
mkdir -p "${customScripts.theme.paths.stateDir}" "${customScripts.theme.paths.fzfDir}" "${customScripts.theme.paths.ghosttyDir}" "${customScripts.theme.paths.tmuxDir}"
|
||||
|
||||
if [[ -f "${customScripts.theme.paths.stateFile}" ]]; then
|
||||
mode=$(tr -d '[:space:]' < "${customScripts.theme.paths.stateFile}")
|
||||
|
|
@ -20,16 +20,19 @@ in {
|
|||
|
||||
case "$mode" in
|
||||
light)
|
||||
fzf_target="${customScripts.theme.paths.fzfDir}/cozybox-light"
|
||||
ghostty_target="${customScripts.theme.paths.ghosttyDir}/cozybox-light"
|
||||
tmux_target="${customScripts.tmuxConfigs.light}"
|
||||
;;
|
||||
*)
|
||||
printf '%s\n' "${customScripts.theme.defaultMode}" > "${customScripts.theme.paths.stateFile}"
|
||||
fzf_target="${customScripts.theme.paths.fzfDir}/cozybox-dark"
|
||||
ghostty_target="${customScripts.theme.paths.ghosttyDir}/cozybox-dark"
|
||||
tmux_target="${customScripts.tmuxConfigs.dark}"
|
||||
;;
|
||||
esac
|
||||
|
||||
ln -sfn "$fzf_target" "${customScripts.theme.paths.fzfCurrentFile}"
|
||||
ln -sfn "$ghostty_target" "${customScripts.theme.paths.ghosttyCurrentFile}"
|
||||
ln -sfn "$tmux_target" "${customScripts.theme.paths.tmuxCurrentFile}"
|
||||
'';
|
||||
|
|
|
|||
|
|
@ -3,6 +3,8 @@
|
|||
paths = {
|
||||
stateDir = "${config.xdg.stateHome}/theme";
|
||||
stateFile = "${config.xdg.stateHome}/theme/current";
|
||||
fzfDir = "${config.xdg.configHome}/fzf/themes";
|
||||
fzfCurrentFile = "${config.xdg.configHome}/fzf/themes/theme";
|
||||
ghosttyDir = "${config.xdg.configHome}/ghostty/themes";
|
||||
ghosttyCurrentFile = "${config.xdg.configHome}/ghostty/themes/cozybox-current";
|
||||
tmuxDir = "${config.xdg.configHome}/tmux/theme";
|
||||
|
|
@ -20,6 +22,8 @@
|
|||
foreground = "#ebdbb2";
|
||||
text = "#d4be98";
|
||||
mutedText = "#7c6f64";
|
||||
blue = "#5b84de";
|
||||
green = "#8ec97c";
|
||||
purple = "#d3869b";
|
||||
border = "#181818";
|
||||
palette = [
|
||||
|
|
@ -52,6 +56,8 @@
|
|||
foreground = "#3c3836";
|
||||
text = "#3c3836";
|
||||
mutedText = "#665c54";
|
||||
blue = "#076678";
|
||||
green = "#427b58";
|
||||
purple = "#d3869b";
|
||||
border = "#e7e7e7";
|
||||
palette = [
|
||||
|
|
@ -104,6 +110,14 @@
|
|||
set-option -g pane-border-style fg=${theme.border}
|
||||
set-option -g pane-active-border-style fg=${theme.border}
|
||||
'';
|
||||
|
||||
renderFzf = mode: let
|
||||
theme = themes.${mode};
|
||||
in ''
|
||||
--color=fg:${theme.text},bg:${theme.background},hl:${theme.blue}
|
||||
--color=fg+:${theme.text},bg+:${theme.surface},hl+:${theme.blue}
|
||||
--color=info:${theme.green},prompt:${theme.blue},pointer:${theme.text},marker:${theme.green},spinner:${theme.text}
|
||||
'';
|
||||
in {
|
||||
inherit defaultMode paths renderGhostty renderTmux themes;
|
||||
inherit defaultMode paths renderFzf renderGhostty renderTmux themes;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -69,6 +69,10 @@
|
|||
"@DEFAULT_MODE@" = theme.defaultMode;
|
||||
"@STATE_DIR@" = theme.paths.stateDir;
|
||||
"@STATE_FILE@" = theme.paths.stateFile;
|
||||
"@FZF_DIR@" = theme.paths.fzfDir;
|
||||
"@FZF_CURRENT_FILE@" = theme.paths.fzfCurrentFile;
|
||||
"@FZF_DARK_FILE@" = "${theme.paths.fzfDir}/cozybox-dark";
|
||||
"@FZF_LIGHT_FILE@" = "${theme.paths.fzfDir}/cozybox-light";
|
||||
"@GHOSTTY_DIR@" = theme.paths.ghosttyDir;
|
||||
"@GHOSTTY_CURRENT_FILE@" = theme.paths.ghosttyCurrentFile;
|
||||
"@GHOSTTY_DARK_FILE@" = "${theme.paths.ghosttyDir}/cozybox-dark";
|
||||
|
|
|
|||
|
|
@ -16,17 +16,20 @@ read_mode() {
|
|||
|
||||
link_mode_assets() {
|
||||
local mode="$1"
|
||||
local fzf_target
|
||||
local ghostty_target
|
||||
local tmux_target
|
||||
local apple_dark_mode
|
||||
|
||||
case "$mode" in
|
||||
dark)
|
||||
fzf_target="@FZF_DARK_FILE@"
|
||||
ghostty_target="@GHOSTTY_DARK_FILE@"
|
||||
tmux_target="@TMUX_DARK_FILE@"
|
||||
apple_dark_mode=true
|
||||
;;
|
||||
light)
|
||||
fzf_target="@FZF_LIGHT_FILE@"
|
||||
ghostty_target="@GHOSTTY_LIGHT_FILE@"
|
||||
tmux_target="@TMUX_LIGHT_FILE@"
|
||||
apple_dark_mode=false
|
||||
|
|
@ -37,8 +40,9 @@ link_mode_assets() {
|
|||
;;
|
||||
esac
|
||||
|
||||
mkdir -p "@STATE_DIR@" "@GHOSTTY_DIR@" "@TMUX_DIR@"
|
||||
mkdir -p "@STATE_DIR@" "@FZF_DIR@" "@GHOSTTY_DIR@" "@TMUX_DIR@"
|
||||
printf '%s\n' "$mode" > "@STATE_FILE@"
|
||||
ln -sfn "$fzf_target" "@FZF_CURRENT_FILE@"
|
||||
ln -sfn "$ghostty_target" "@GHOSTTY_CURRENT_FILE@"
|
||||
ln -sfn "$tmux_target" "@TMUX_CURRENT_FILE@"
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue