Last active
October 9, 2015 14:27
-
-
Save mrkschan/3522031 to your computer and use it in GitHub Desktop.
bash completion for git, with files and directory
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!bash | |
# | |
# Enable file/directory completion for git. | |
# | |
# bashref - http://is.gd/PHQRX1 | |
# bashlib - http://code.google.com/p/bash-completion-lib/ | |
have git && { | |
_git_completion() | |
{ | |
local cur words cword prev | |
_get_comp_words_by_ref -n =: cur words cword prev | |
local command subcommand | |
command=${words[1]} | |
subcommand=${words[2]} | |
# Complete with files | |
if [[ "$command" == "diff" && "$prev" == "--" ]]; then | |
_filedir | |
return 0 | |
fi | |
if [[ "$command" == "checkout" && "$prev" == "--" ]]; then | |
_filedir | |
return 0 | |
fi | |
if [[ "$command" == "log" && "$prev" == "--" ]]; then | |
_filedir | |
return 0 | |
fi | |
if [[ "$command" == "grep" && "$prev" == "--" ]]; then | |
_filedir | |
return 0 | |
fi | |
if [[ "$command" == "add" ]]; then | |
_filedir | |
return 0 | |
fi | |
if [[ "$command" == "blame" ]]; then | |
_filedir | |
return 0 | |
fi | |
if [[ "$command" == "rm" ]]; then | |
_filedir | |
return 0 | |
fi | |
if [[ "$command" == "mv" ]]; then | |
_filedir | |
return 0 | |
fi | |
# Fallback to use git default completion | |
_git | |
} | |
complete -o bashdefault -o nospace -F _git_completion git | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment