-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathigit.plugin.zsh
147 lines (132 loc) · 2.78 KB
/
igit.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
_igit_base_dir=$(cd $(dirname $0); pwd)
source ${_igit_base_dir}/commands/add.zsh
source ${_igit_base_dir}/commands/branch.zsh
source ${_igit_base_dir}/commands/cherry-pick.zsh
source ${_igit_base_dir}/commands/delete.zsh
source ${_igit_base_dir}/commands/diff.zsh
source ${_igit_base_dir}/commands/log.zsh
source ${_igit_base_dir}/commands/merge.zsh
source ${_igit_base_dir}/commands/stash.zsh
source ${_igit_base_dir}/commands/switch.zsh
source ${_igit_base_dir}/commands/tag.zsh
source ${_igit_base_dir}/commands/revert.zsh
igit() {
if [ $# -lt 1 ]; then
_igit_usage
return 0
fi
git rev-parse --is-inside-work-tree > /dev/null 2>&1
if [ $? -gt 0 ]; then
echo "igit: not a git repository"
return 1
fi
case $1 in
"add")
[[ -z "$(git status -uall --short)" ]] && return 0
_igit_add ;;
"branch")
_igit_branch ;;
"cherry-pick")
_igit_cherry_pick ;;
"delete")
_igit_delete ;;
"diff")
[[ -z "$(git status -uall --short)" ]] && return 0
_igit_diff ;;
"log")
_igit_log ;;
"merge")
_igit_merge ;;
"stash")
_igit_stash ;;
"switch")
_igit_switch ;;
"tag")
_igit_tag ;;
"revert")
_igit_revert ;;
"help")
_igit_usage ;;
*)
echo "igit: '$1' is not an igit command. See 'igit help'"
return 1
esac
}
_fzf_for_igit() {
fzf --height 75% \
--reverse \
--border \
--ansi \
--color fg:188,bg:233,hl:103,fg+:222,bg+:234,hl+:104 \
--color info:183,prompt:110,spinner:107,pointer:167,marker:215 \
--preview-window down:70% \
$@
}
_igit_usage () {
echo -e "\n\e[32mUsage:\e[m"
cat << EOF
igit [command]
EOF
echo -e "\e[32mCommands:\e[m"
cat << EOF
add
branch
cherry-pick
delete
diff
log
merge
stash
switch
tag
revert
help
EOF
}
_igit() {
_values \
'commands' \
'add' \
'branch' \
'cherry-pick' \
'delete' \
'diff' \
'log' \
'merge' \
'stash' \
'switch' \
'tag' \
'revert' \
'help'
}
compdef _igit igit
_zle_add() {
igit add
zle accept-line
}
_zle_branch() {
igit branch
zle accept-line
}
_zle_log() {
igit log
zle accept-line
}
_zle_merge() {
igit merge
zle accept-line
}
_zle_switch() {
igit switch
zle accept-line
}
zle -N _zle_add
zle -N _zle_branch
zle -N _zle_log
zle -N _zle_merge
zle -N _zle_switch
bindkey '^G^A' _zle_add
bindkey '^G^B' _zle_branch
bindkey '^G^L' _zle_log
bindkey '^G^M' _zle_merge
bindkey '^G^S' _zle_switch