mirror of
https://github.com/Xevion/dotfiles.git
synced 2026-01-31 02:24:11 -06:00
- New chai function for interactive apply with multi-select and diff preview - Enhanced chshow for browsing managed files with edit/view modes - Shared fzf-utils.ts with standardized colors and chezmoi file parsing - Bash version of fzf abbreviation search with Alt+A binding
56 lines
1.4 KiB
Cheetah
56 lines
1.4 KiB
Cheetah
function chai --description "Interactive chezmoi apply with fzf diff preview"
|
|
# Get status data first (before fzf takes over TTY)
|
|
# Script outputs to stderr for "no changes" message, stdout for data
|
|
set -l data (fzf-chezmoi-apply.ts 2>/dev/null)
|
|
set -l script_status $status
|
|
|
|
# Handle error or no changes case
|
|
if test $script_status -ne 0
|
|
return 1
|
|
end
|
|
|
|
if test -z "$data"
|
|
echo "No changes to apply"
|
|
return 0
|
|
end
|
|
|
|
# Run fzf separately so it gets proper TTY access
|
|
set -l selected (printf '%s\n' $data | fzf \
|
|
--ansi \
|
|
--height=50% \
|
|
--reverse \
|
|
--delimiter='\t' \
|
|
--with-nth=4 \
|
|
--nth=1 \
|
|
--prompt='Apply Changes > ' \
|
|
--preview='chezmoi diff {1} 2>/dev/null | head -100' \
|
|
--preview-window=right:60%:wrap \
|
|
--multi \
|
|
--bind='ctrl-a:toggle-all' \
|
|
--marker='* ' \
|
|
--pointer='>' \
|
|
--header='Tab: toggle | Ctrl+A: all | Enter: apply')
|
|
|
|
if test $status -ne 0 -o -z "$selected"
|
|
echo "Cancelled"
|
|
return 1
|
|
end
|
|
|
|
# Apply selected files
|
|
set -l targets
|
|
for line in $selected
|
|
set -l target (string split \t $line)[1]
|
|
set -a targets $target
|
|
end
|
|
|
|
set -l count (count $targets)
|
|
echo "Applying $count file(s)..."
|
|
|
|
for target in $targets
|
|
echo " $target"
|
|
chezmoi apply ~/$target
|
|
end
|
|
|
|
echo "Applied $count file(s)"
|
|
end
|