-
Notifications
You must be signed in to change notification settings - Fork 0
/
chezmoi.plugin.zsh
executable file
·62 lines (50 loc) · 1.61 KB
/
chezmoi.plugin.zsh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# Ensure chezmoi is available
if (( ! ${+commands[chezmoi]} )); then
return 1
fi
function __fzfsh_chezmoi_parse() {
local files=()
while read -r item; do files+=("$HOME/$item"); done <<< "$1"
echo $files
}
function fzfsh::chezmoi::re-add() {
local options=$(chezmoi status)
[[ -z "$options" ]] && return 1
local files=()
local items=$(echo "$options" \
| awk '{ print substr($0, 4) }' \
| fzf --multi --preview="chezmoi diff $HOME/{} | delta")
[[ -z "$items" ]] && return 1
while read -r item; do files+=("$HOME/$item"); done <<< "$items"
chezmoi re-add $files
}
function fzfsh::chezmoi::apply() {
local options=$(chezmoi status)
[[ -z "$options" ]] && return 1
local files=()
local items=$(echo "$options" \
| awk '{ print substr($0, 4) }' \
| fzf --multi --preview="chezmoi diff $HOME/{} | delta")
[[ -z "$items" ]] && return 1
while read -r item; do files+=("$HOME/$item"); done <<< "$items"
chezmoi apply $files
}
function fzfsh::chezmoi::edit() {
local files=()
local items=$(chezmoi list --include=files | fzf --multi)
[[ -z "$items" ]] && return 1
while read -r item; do files+=("$HOME/$item"); done <<< "$items"
chezmoi edit $files
}
function fzfsh::chezmoi::diff() {
local options=$(chezmoi status)
[[ -z "$options" ]] && return 1
local cmd="chezmoi diff $HOME/{} | delta"
echo "$options" \
| awk '{ print substr($0, 4) }' \
| fzf --bind="enter:execute($cmd --side-by-side --paging=always)" --preview="$cmd"
}
alias cadd='fzfsh::chezmoi::re-add'
alias capply='fzfsh::chezmoi::apply'
alias cdiff='fzfsh::chezmoi::diff'
alias cedit='fzfsh::chezmoi::edit'