Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion dot_bash_profile.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,8 @@ gh () {
local gh_personal_repo_root="$HOME/dev/repos/github.com/aguil"

if [ -z "${GH_CONFIG_DIR:-}" ]; then
if route_config_dir="$(_chez_gh_route_config_dir)"; then
if declare -F _chez_gh_route_config_dir >/dev/null 2>&1 \
&& route_config_dir="$(_chez_gh_route_config_dir)"; then
GH_CONFIG_DIR="$route_config_dir" command gh "$@"
return $?
fi
Expand All @@ -249,6 +250,10 @@ gh () {
command gh "$@"
}

# Agent subprocesses (Claude Code, Cursor) rehydrate shell state from export -p
# and inherit BASH_FUNC_gh without private helpers. Export the helper too.
export -f _chez_gh_route_config_dir gh 2>/dev/null || true

tmuxdev () {
local chezmoi_source
local script_path
Expand Down
14 changes: 6 additions & 8 deletions dot_config/nvim/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -411,21 +411,19 @@ require('lazy').setup({
-- [[ Configure Telescope ]]
-- See `:help telescope` and `:help telescope.setup()`
require('telescope').setup {
-- You can put your default mappings / updates / etc. in here
-- All the info you're looking for is in `:help telescope.setup()`
--
-- defaults = {
-- mappings = {
-- i = { ['<c-enter>'] = 'to_fuzzy_refine' },
-- },
-- },
defaults = {
dynamic_preview_title = true,
qflist_previewer = require('custom.telescope_delta').qflist_previewer,
grep_previewer = require('custom.telescope_delta').grep_previewer,
},
pickers = {
find_files = { hidden = true },
},
extensions = {
['ui-select'] = { require('telescope.themes').get_dropdown() },
},
}
require('custom.telescope_delta').apply_git_previewers()

-- Enable Telescope extensions if they are installed
pcall(require('telescope').load_extension, 'fzf')
Expand Down
141 changes: 26 additions & 115 deletions dot_config/nvim/lua/custom/plugins/git.lua
Original file line number Diff line number Diff line change
Expand Up @@ -54,64 +54,6 @@ local function system_async(cmd, cwd, callback)
end)
end

local function system_ok(cmd, cwd)
local _, code = system_result(cmd, cwd)
return code == 0
end

local function shell_join(cmd)
return table.concat(vim.tbl_map(vim.fn.shellescape, cmd), ' ')
end

local function default_branch_candidates()
return vim.g.dot_vcs_default_branches or { 'master', 'main' }
end

local function find_git_default_branch(root)
local lines, code = system_result({
'git',
'symbolic-ref',
'--quiet',
'--short',
'refs/remotes/origin/HEAD',
}, root)
local origin_head = lines[1]
if code == 0 and origin_head and origin_head ~= '' then
return origin_head
end

for _, branch in ipairs(default_branch_candidates()) do
if system_ok({ 'git', 'rev-parse', '--verify', '--quiet', branch }, root) then
return branch
end
if system_ok({ 'git', 'rev-parse', '--verify', '--quiet', 'origin/' .. branch }, root) then
return 'origin/' .. branch
end
end
end

local function find_jj_default_branch(root)
for _, branch in ipairs(default_branch_candidates()) do
if system_ok({ 'jj', 'log', '--no-graph', '--limit', '1', '-r', branch, '-T', 'commit_id' }, root) then
return branch
end
local remote_branch = branch .. '@origin'
if system_ok({
'jj',
'log',
'--no-graph',
'--limit',
'1',
'-r',
remote_branch,
'-T',
'commit_id',
}, root) then
return remote_branch
end
end
end

local function stat_path(line)
line = line:gsub('\27%[[%d;]*m', '')
local path = line:match '^%s*(.-)%s*|'
Expand Down Expand Up @@ -144,21 +86,22 @@ local function open_branch_changes()
return
end

local base = kind == 'jj' and find_jj_default_branch(root) or find_git_default_branch(root)
if not base then
vim.notify('Could not find default branch. Set vim.g.dot_vcs_default_branches.', vim.log.levels.WARN)
local range = vcs.resolve_diff_range(kind, root)
if not range then
vim.notify('Could not resolve diff range. Set vim.g.dot_vcs_default_branches.', vim.log.levels.WARN)
return
end

local jj_target = kind == 'jj' and '@' or nil
local range = kind == 'jj' and base .. '..' .. jj_target or base .. '...HEAD'
local name_cmd = kind == 'jj' and { 'jj', '--color', 'never', 'diff', '--name-only', '-r', range }
or { 'git', 'diff', '--no-color', '--name-only', base .. '...HEAD' }
local name_cmd = vcs.branch_name_only_cmd(kind, root)
if not name_cmd then
vim.notify('Could not resolve diff range. Set vim.g.dot_vcs_default_branches.', vim.log.levels.WARN)
return
end

system_async(name_cmd, root, function(paths, code, stderr)
if code ~= 0 then
local detail = stderr ~= '' and (': ' .. stderr) or '.'
vim.notify('Could not load branch changes for ' .. base .. detail, vim.log.levels.WARN)
vim.notify('Could not load changes for ' .. range .. detail, vim.log.levels.WARN)
return
end

Expand All @@ -170,7 +113,7 @@ local function open_branch_changes()
end

if vim.tbl_isempty(entries) then
vim.notify('No branch change files found for ' .. base .. '.', vim.log.levels.INFO)
vim.notify('No changed files for ' .. range .. '.', vim.log.levels.INFO)
return
end

Expand All @@ -181,20 +124,20 @@ local function open_branch_changes()
local conf = require('telescope.config').values
local actions = require 'telescope.actions'
local action_state = require 'telescope.actions.state'
local telescope_delta = require 'custom.telescope_delta'
local file_entry_maker = make_entry.gen_from_file { cwd = root }
local delta_available = vim.fn.executable 'delta' == 1
local diff_previewer = previewers.new_buffer_previewer {
title = 'Branch diff',
define_preview = function(self, entry)
local path = entry.value
local diff_cmd = kind == 'jj' and { 'jj', '--color', 'never', 'diff', '--git', '-r', range, '--', path }
or { 'git', 'diff', '--no-color', range, '--', path }
local diff_cmd = vcs.file_branch_diff_cmd(kind, root, path)
if not diff_cmd then
vim.api.nvim_buf_set_lines(self.state.bufnr, 0, -1, false, { 'No diff for ' .. path })
return
end

if delta_available then
local command = shell_join(diff_cmd) .. ' | ' .. shell_join { 'delta', '--default-language', 'bash' }
vim.api.nvim_buf_call(self.state.bufnr, function()
vim.fn.termopen(command, { cwd = root })
end)
if telescope_delta.available() then
telescope_delta.termopen_diff(self.state.bufnr, root, diff_cmd)
return
end

Expand All @@ -219,8 +162,7 @@ local function open_branch_changes()

pickers
.new({}, {
prompt_title = kind == 'jj' and 'jj: branch changes ' .. range
or 'git: branch changes vs ' .. base,
prompt_title = kind == 'jj' and ('jj: changes ' .. range) or ('git: changes ' .. range),
finder = finders.new_table {
results = entries,
entry_maker = function(path)
Expand Down Expand Up @@ -366,60 +308,29 @@ return {
return vim.fs.normalize(path:sub(1, #path - #suffix - 1))
end

local jj_signs_base_mode = 'default_branch'
local jj_blame_enabled = true
local jj_blame_ns = vim.api.nvim_create_namespace 'dot-jj-current-line-blame'
local jj_blame_group = vim.api.nvim_create_augroup('dot-jj-current-line-blame', { clear = true })

local function resolve_jj_signs_base(root)
if jj_signs_base_mode == 'working_copy' then
return '@-'
end
return find_jj_default_branch(root) or '@-'
end

local function set_jj_signs_base(root)
local base = resolve_jj_signs_base(root)
local base = vcs.resolve_jj_signs_base(root)
require('jjsigns.config').config.base = base
return base
end

local function toggle_jj_signs_base()
local bufname = vim.api.nvim_buf_get_name(0)
local path = bufname ~= '' and vim.fs.normalize(bufname) or vim.fn.getcwd(0)
local root = vcs.find_root(path)
if not root or not vim.uv.fs_stat(root .. '/.jj') then
vim.notify('Not inside a jj repository.', vim.log.levels.WARN)
return
end

if jj_signs_base_mode == 'default_branch' then
jj_signs_base_mode = 'working_copy'
else
jj_signs_base_mode = 'default_branch'
if not find_jj_default_branch(root) then
vim.notify('Could not find default branch. Falling back to @-. Set vim.g.dot_vcs_default_branches.', vim.log.levels.WARN)
end
end

local base = set_jj_signs_base(root)
require('jjsigns.attach').refresh_all()
vim.notify('jjsigns base: ' .. base)
end

local function default_jj_signs_base()
local root = vcs.find_root(vim.fn.getcwd(0))
if not root or not vim.uv.fs_stat(root .. '/.jj') then
return '@-'
end

local base = find_jj_default_branch(root)
local base = vcs.find_jj_default_branch(root)
if not base then
return
end
return base
end

local jj_blame_enabled = true
local jj_blame_ns = vim.api.nvim_create_namespace 'dot-jj-current-line-blame'
local jj_blame_group = vim.api.nvim_create_augroup('dot-jj-current-line-blame', { clear = true })

local function clear_jj_blame(bufnr)
vim.api.nvim_buf_clear_namespace(bufnr, jj_blame_ns, 0, -1)
end
Expand Down Expand Up @@ -597,7 +508,6 @@ return {
end,
})

vim.keymap.set('n', '<leader>tJ', toggle_jj_signs_base, { desc = 'Toggle jj signs base' })
end,
},

Expand All @@ -623,6 +533,7 @@ return {
'NeogitOrg/neogit',
init = function()
vim.keymap.set('n', '<leader>gg', open_vcs_ui, { desc = 'VCS: Neogit or jj status' })
vim.keymap.set('n', '<leader>tJ', vcs.toggle_base_mode, { desc = 'Toggle diff base (default branch / working copy)' })
end,
dependencies = {
'nvim-lua/plenary.nvim',
Expand Down
Loading
Loading