forked from nakamuray/zaw
/
git-files.zsh
34 lines (29 loc) · 1.3 KB
/
git-files.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
# zaw source for git files
function zaw-src-git-files() {
local all_files modified raw_candidates raw_cand_descriptions
local all_without_modified mod_description
git rev-parse --git-dir >/dev/null 2>&1
if [[ $? == 0 ]]; then
all_files=$(git ls-files $(git rev-parse --show-cdup))
modified=$(git ls-files $(git rev-parse --show-cdup) --modified)
if [[ $modified == "" ]]; then
raw_candidates=$all_files
raw_cand_descriptions=$all_files
else
mod_description=$(echo $modified | awk '{print $0 " MODIFIED"}')
all_without_modified=$(echo "${modified}\\n${all_files}" |sort |uniq -u )
raw_candidates=$(echo "${modified}\\n${all_without_modified}")
raw_cand_descriptions=$(echo "${mod_description}\\n${all_without_modified}")
fi
: ${(A)candidates::=${(f)"$(echo $raw_candidates)"}}
: ${(A)cand_descriptions::=${(f)"$(echo $raw_cand_descriptions)"}}
fi
actions=("zaw-callback-edit-file" "zaw-src-git-files-add" "zaw-callback-append-to-buffer")
act_descriptions=("edit file" "add" "append to edit buffer")
options=(-m -n)
}
function zaw-src-git-files-add () {
BUFFER="git add $1"
zle accept-line
}
zaw-register-src -n git-files zaw-src-git-files