1 if test -x /usr/bin/git >/dev/null 2>&1; then
2 # chdir to a remote's directory (if the remote is on the local FS)
5 echo "Usage: cdremote [remote_name]" >&2
10 branch="`git rev-parse --abbrev-ref HEAD`"
11 remote="`git config --get branch.$branch.remote`"
16 if [ -n "$remote" ] && git config --get remote.$remote.url |
17 grep -q '^\(file:/\|/\|\.\./\)'; then # (file:/ or / or ../ at the beginning)
18 cdgitpath remote.$remote.url
23 echo "Cannot find directory for remote $1" >&2
24 echo "Usage: cdremote [remote_name]" >&2
28 _list_remotes '^\(file:/\|/\|\.\./\)' # (file:/ or / or ../ at the beginning)
29 if [ ${#GIT_REMOTES[*]} -eq 1 ]; then
30 remote=${GIT_REMOTES[0]}
32 cdgitpath remote.$remote.url
35 echo "Cannot find directory for any remote" >&2
36 echo "Usage: cdremote [remote_name]" >&2
41 # completion for `cd_worktree`
44 local cur="${COMP_WORDS[COMP_CWORD]}"
45 COMPREPLY=(`compgen -W "$(
46 git worktree list | awk '{s=$3; gsub("[\\\\[\\\\]]", "", s); print s}'
50 _cd_worktree_comp_loader() {
51 _completion_loader git
52 unset _cd_worktree_comp_loader
53 complete -F _cd_worktree_comp cd_worktree
57 complete -F _cd_worktree_comp_loader cd_worktree
59 # completion for aliases in global .gitconfig
61 # fixup rbi rbia rbiap rbip - do refs name completion
62 _git_fixup() { __gitcomp_nl "$(__git_refs)" ; }
63 _git_rbi() { __gitcomp_nl "$(__git_refs)" ; }
64 _git_rbia() { __gitcomp_nl "$(__git_refs)" ; }
65 _git_rbiap() { __gitcomp_nl "$(__git_refs)" ; }
66 _git_rbip() { __gitcomp_nl "$(__git_refs)" ; }
68 # push-to-all-remotes - do branch name completion
69 _git_push_to_all_remotes() { __gitcomp_nl "$(__git_heads)" ; }
71 _cdgitpath_complete() {
72 local cur="${COMP_WORDS[COMP_CWORD]}"
73 COMPREPLY=(`compgen -W "$(__git_config_get_set_variables)" -- "$cur"`)
80 complete -F _cdgitpath_complete cdgitpath git-open
82 # list remotes with URLs matching a regexp
85 echo "Usage: _list_remotes remote_regexp" >&2
88 declare -ag GIT_REMOTES=()
90 for remote in `git remote`; do
91 if git config --get remote.$remote.url | grep -q "$1"; then
92 GIT_REMOTES+=($remote)
97 # completion for cdremote and git-open-remote - list remotes with a pattern
98 _list_remotes_completion() {
99 local cur="${COMP_WORDS[COMP_CWORD]}"
101 COMPREPLY=(`compgen -W "${GIT_REMOTES[*]}" -- "$cur"`)
105 # completion for cdremote - list remotes with directories as URLs
106 _cdremote_complete() {
107 _list_remotes_completion '^\(file:/\|/\|\.\./\)' # (file:/ or / or ../ at the beginning)
108 if [ ${#COMPREPLY[*]} -eq 0 ]; then
109 _list_remotes_completion .
113 complete -F _cdremote_complete cdremote
115 # completion for git-open-remote - list remotes with http(s) URLs
117 _list_remotes_completion '^http\(s\)\?://'
118 if [ ${#COMPREPLY[*]} -eq 0 ]; then
119 _list_remotes_completion .
123 complete -F _git_open_remote git-open-remote