Added some single command aliases (+-!#@^) and working 'add' command

This commit is contained in:
William Hilton 2015-11-03 01:46:28 -05:00
parent 5f2a90a749
commit f9ab6e296c
2 changed files with 21 additions and 16 deletions

View file

@ -24,29 +24,30 @@ _get_complete()
# $3 : the word preceding the word being completed # $3 : the word preceding the word being completed
case ${COMP_CWORD} in case ${COMP_CWORD} in
1) 1)
commands="branch commit diff fetch ignore reset rmbranch review stage status unstage" commands="branch commit diff fetch ignore reset rm rmbranch review stage unstage"
COMPREPLY=( $(compgen -W "${commands}" "$2") ) COMPREPLY=( $(compgen -W "${commands}" "$2") )
;; ;;
2) 2)
compopt -o nospace compopt -o nospace
case "$3" in #case "$3" in
case "${COMP_WORDS[1]}" in
# <branch> # <branch>
branch | rmbranch | fetch) '@' | branch | rmbranch | fetch)
COMPREPLY=( $(compgen -W "$(list_branches)" "$2") ) COMPREPLY=( $(compgen -W "$(list_branches)" "$2") )
;; ;;
# <modified path> # <modified path>
stage) '=' | stage | reset)
COMPREPLY=( $(compgen -W "$(list_modified)" "$2") ) COMPREPLY=( $(compgen -W "$(list_modified)" "$2") )
;; ;;
# <tracked path> # <tracked path>
unstage) unstage)
COMPREPLY=( $(compgen -W "$(list_staged)" "$2") ) COMPREPLY=( $(compgen -W "$(list_staged)" "$2") )
;; ;;
rm | diff) '-' | rm | diff)
COMPREPLY=( $(compgen -W "$(list_tracked)" "$2") ) COMPREPLY=( $(compgen -W "$(list_tracked)" "$2") )
;; ;;
# <untracked path> # <untracked path>
add) '+' | add)
compopt -o nospace compopt -o nospace
COMPREPLY=( $(compgen -W "$(list_untracked)" -W "STAGE" -W "HEAD" "$2") ) COMPREPLY=( $(compgen -W "$(list_untracked)" -W "STAGE" -W "HEAD" "$2") )
;; ;;

24
bin/get
View file

@ -10,7 +10,7 @@ list_remote_branches() {
} }
case "$1" in case "$1" in
"" | status) '?' | status)
# TODO: Display help if not inside a repo # TODO: Display help if not inside a repo
# TODO: figure out how to git config --global color.status always automatically. # TODO: figure out how to git config --global color.status always automatically.
git status \ git status \
@ -23,7 +23,7 @@ git status \
| grep -v 'nothing added to commit but untracked files present (use "git add" to track)' | grep -v 'nothing added to commit but untracked files present (use "git add" to track)'
;; ;;
stage) = | stage)
if [ -z "$2" ]; then if [ -z "$2" ]; then
echo Staging all modified files echo Staging all modified files
git add -u :/ git add -u :/
@ -43,7 +43,7 @@ else
fi fi
;; ;;
tag) '#' | tag)
echo Tagging echo Tagging
git tag "$2" git tag "$2"
;; ;;
@ -76,11 +76,15 @@ then
fi fi
;; ;;
add) '+' | add)
# TODO: make add only add untracked files (useful when auto-completing) # The only real difference between add and stage is
# add will tab-complete with untracked files, while
# stage tab-completes with tracked files
echo Staging "${@:2}"
git add --all "${@:2}"
;; ;;
rm) '-' | rm)
echo Removing tracked files echo Removing tracked files
git rm -r "$2" git rm -r "$2"
# Check to see if there are still remaining files # Check to see if there are still remaining files
@ -110,7 +114,7 @@ else
fi fi
;; ;;
commit) '!' | commit)
echo "Parent commit: $(git log --abbrev-commit -1 --pretty=format:'%C(bold blue)%s%Creset %Cgreen(%cr)%Creset')" echo "Parent commit: $(git log --abbrev-commit -1 --pretty=format:'%C(bold blue)%s%Creset %Cgreen(%cr)%Creset')"
if [ -z "$2" ]; then if [ -z "$2" ]; then
read -ep 'Message: ' msg read -ep 'Message: ' msg
@ -129,7 +133,7 @@ undo)
esac esac
;; ;;
branch) '@' | branch)
echo 'Switching to branch' echo 'Switching to branch'
if [ -z "$2" ]; then if [ -z "$2" ]; then
echo '! Specify branch name' echo '! Specify branch name'
@ -213,7 +217,7 @@ echo 'Compare stage with HEAD'
git diff --cached --ignore-space-change HEAD git diff --cached --ignore-space-change HEAD
;; ;;
push) ^ | push)
echo 'Pushing' echo 'Pushing'
# Check to see if upstream is set. # Check to see if upstream is set.
if git rev-parse --abbrev-ref @{upstream} >/dev/null ; then if git rev-parse --abbrev-ref @{upstream} >/dev/null ; then
@ -289,7 +293,7 @@ else
fi fi
;; ;;
lg) log)
git log --color \ git log --color \
--graph \ --graph \
--pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' \ --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' \