-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy path.git-alias-completions.bash
More file actions
87 lines (77 loc) · 2.81 KB
/
.git-alias-completions.bash
File metadata and controls
87 lines (77 loc) · 2.81 KB
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
#!/usr/bin/env bash
#
# Bash completions for git aliases
#
# Source git completions if not already loaded
if ! declare -f __git_complete &>/dev/null; then
# Try to source git-completion.bash
for completion_file in \
/usr/share/bash-completion/completions/git \
/usr/local/share/bash-completion/completions/git \
/opt/homebrew/share/bash-completion/completions/git \
~/.git-completion.bash \
"$(dirname "${BASH_SOURCE[0]}")/.git-completion.bash"; do
if [ -f "$completion_file" ]; then
source "$completion_file"
break
fi
done
fi
# Only set up completions if __git_complete AND _git_status are available
# Both are needed: __git_complete creates wrappers, _git_* functions do the actual completion
if ! declare -f _git_status &>/dev/null; then
# _git_status not loaded yet - source git completions directly
for completion_file in \
/opt/homebrew/share/bash-completion/completions/git \
/usr/local/share/bash-completion/completions/git \
/usr/share/bash-completion/completions/git \
~/.git-completion.bash; do
if [ -f "$completion_file" ]; then
source "$completion_file"
break
fi
done
fi
if declare -f __git_complete &>/dev/null && declare -f _git_status &>/dev/null; then
# Use __git_complete for standard git alias completions
__git_complete gco _git_checkout
__git_complete gb _git_branch
__git_complete gd _git_diff
__git_complete gl _git_log
__git_complete gs _git_status
__git_complete ga _git_add
__git_complete gm _git_merge
__git_complete gp _git_push
__git_complete gf _git_fetch
__git_complete gr _git_rebase
# grh - git reset --hard (custom completion)
_grh_completion() {
local cur words cword prev
_get_comp_words_by_ref -n =: cur words cword prev
# Complete with git refs (branches, tags, commits)
__gitcomp_nl "$(__git_refs)"
}
# gbc - git branch-reset -c (custom completion)
_gbc_completion() {
local cur words cword prev
_get_comp_words_by_ref -n =: cur words cword prev
# First argument: branch name
if [ $cword -eq 1 ]; then
__gitcomp_nl "$(__git_heads)"
# Second argument: ref to reset to
elif [ $cword -eq 2 ]; then
__gitcomp_nl "$(__git_refs)"
fi
}
# gbd - git branch -D (custom completion for local branches only)
_git_bd() {
local cur words cword prev
_get_comp_words_by_ref -n =: cur words cword prev
# Complete with local branch names only
__gitcomp_nl "$(__git_heads)"
}
# Register custom completions using __git_func_wrap pattern
__git_complete grh grh_completion
__git_complete gbc gbc_completion
__git_complete gbd _git_bd
fi