Skip to content
Browse files

Added git bash completion for custom git bash aliases

  • Loading branch information...
1 parent d8d0b36 commit e40849b27c72cf4e1ee719be3862c12184c63ccc @rmm5t committed Aug 15, 2012
Showing with 34 additions and 0 deletions.
  1. +34 −0 bash_completion
View
34 bash_completion
@@ -2,3 +2,37 @@
if [ -f ~/bin/rake_completion ]; then
. ~/bin/rake_completion
fi
+
+# Completion for custom git aliases
+# Borrowed and modified from:
+# https://github.com/bronson/dotfiles/blob/731bfd95/.bashrc#L81
+complete -o bashdefault -o default -o nospace -F _git g 2>/dev/null \
+ || complete -o default -o nospace -F _git g
+
+__define_git_completion () {
+eval "
+ _git_$2_shortcut () {
+ COMP_LINE=\"git $2\${COMP_LINE#$1}\"
+ let COMP_POINT+=$((4+${#2}-${#1}))
+ COMP_WORDS=(git $2 \"\${COMP_WORDS[@]:1}\")
+ let COMP_CWORD+=1
+
+ local cur words cword prev
+ _get_comp_words_by_ref -n =: cur words cword prev
+ _git_$2
+ }
+"
+}
+
+__git_shortcut () {
+ type _git_$2_shortcut &>/dev/null || __define_git_completion $1 $2
+ # alias $1="git $2 $3"
+ # complete -o default -o nospace -F _git_$2_shortcut $1
+ complete -o bashdefault -o default -o nospace -F _git_$2_shortcut $1 2>/dev/null \
+ || complete -o default -o nospace -F _git_$2_shortcut $1
+}
+
+__git_shortcut gco checkout
+__git_shortcut gl pull
+__git_shortcut glr pull
+__git_shortcut gp push

0 comments on commit e40849b

Please sign in to comment.
Something went wrong with that request. Please try again.