Improve tab completion

This commit is contained in:
William Hilton 2015-11-03 01:13:04 -05:00
parent 30c9f2ab4f
commit 5f2a90a749
2 changed files with 37 additions and 10 deletions

View file

@ -2,7 +2,19 @@
list_branches() { list_branches() {
git for-each-ref refs/heads --format="%(refname:short)" git for-each-ref refs/heads --format="%(refname:short)"
} }
list_tracked() {
git ls-tree HEAD | grep blob | awk '{print $4}';
git ls-tree HEAD | grep tree | awk '{print $4"/"}';
}
list_untracked() {
git ls-files --exclude-standard --other --directory --no-empty-directory
}
list_modified() {
git ls-files --modified
}
list_staged() {
git diff --name-only --relative --cached
}
_get_complete() _get_complete()
{ {
# Available variables: # Available variables:
@ -16,20 +28,35 @@ case ${COMP_CWORD} in
COMPREPLY=( $(compgen -W "${commands}" "$2") ) COMPREPLY=( $(compgen -W "${commands}" "$2") )
;; ;;
2) 2)
compopt -o nospace
case "$3" in case "$3" in
# <branch>
branch | rmbranch | fetch) branch | rmbranch | fetch)
commands=$(list_branches) COMPREPLY=( $(compgen -W "$(list_branches)" "$2") )
COMPREPLY=( $(compgen -W "${commands}" "$2") )
;; ;;
stage | unstage | ignore | rm) # <modified path>
stage)
COMPREPLY=( $(compgen -W "$(list_modified)" "$2") )
;;
# <tracked path>
unstage)
COMPREPLY=( $(compgen -W "$(list_staged)" "$2") )
;;
rm | diff)
COMPREPLY=( $(compgen -W "$(list_tracked)" "$2") )
;;
# <untracked path>
add)
compopt -o nospace compopt -o nospace
COMPREPLY=( $(compgen -o default -S "/" -d -X .git "$2") ) COMPREPLY=( $(compgen -W "$(list_untracked)" -W "STAGE" -W "HEAD" "$2") )
;; ;;
esac
;;
3)
case "${COMP_WORDS[COMP_CWORD-2]}" in
diff) diff)
compopt -o nospace compopt -o nospace
commands="STAGE" COMPREPLY=( $(compgen -W "$(list_tracked)" "$2") )
COMPREPLY=( $(compgen -W "${commands}" "$2") )
COMPREPLY+=( $(compgen -o default -S "/" -d -X .git "$2") )
;; ;;
esac esac
;; ;;

View file

@ -29,7 +29,7 @@ if [ -z "$2" ]; then
git add -u :/ git add -u :/
else else
echo Staging "${@:2}" echo Staging "${@:2}"
git add "${@:2}" git add --all "${@:2}"
fi fi
;; ;;